Skip to content

Commit

Permalink
Lazy Set Up Helper Method for Controller (#8)
Browse files Browse the repository at this point in the history
* Lazy set up helper method

* Update gemfile.lock
  • Loading branch information
vergilet authored Oct 15, 2019
1 parent 2c7e2c6 commit 74c482f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
repost (0.3.0)
repost (0.3.1)

GEM
remote: https://rubygems.org/
Expand Down
25 changes: 13 additions & 12 deletions lib/repost/extend_controller.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
if defined?(Rails)
class ::ActionController::Base
AUTO_TOKEN_OPTIONS = ['auto', :auto].freeze
if defined?(Rails) && defined?(ActiveSupport)
ActiveSupport.on_load(:action_controller) do
class ::ActionController::Base

def repost(url, params: {}, options: {})
authenticity_token = form_authenticity_token if AUTO_TOKEN_OPTIONS.include?(options[:authenticity_token])
render html: Repost::Senpai.perform(
url,
params: params,
options: options.merge({authenticity_token: authenticity_token}.compact)
).html_safe
end
def repost(url, params: {}, options: {})
authenticity_token = form_authenticity_token if ['auto', :auto].include?(options[:authenticity_token])
render html: Repost::Senpai.perform(
url,
params: params,
options: options.merge({authenticity_token: authenticity_token}.compact)
).html_safe
end

alias :redirect_post :repost
alias :redirect_post :repost

end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/repost/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Repost
VERSION = "0.3.0"
VERSION = "0.3.1"
end

0 comments on commit 74c482f

Please sign in to comment.