Class: Repost::Senpai

Inherits:
Action
  • Object
show all
Defined in:
lib/repost/senpai.rb

Constant Summary collapse

DEFAULT_SUBMIT_BUTTON_TEXT =
'Continue'
DEFAULT_CHARSET =
'UTF-8'
OVERRIDE_METHODS =

Browsers only submit forms via GET or POST; other verbs are sent as POST with a Rails-style "_method" override field.

%w[put patch delete].freeze

Instance Method Summary collapse

Methods inherited from Action

perform

Constructor Details

#initialize(url, params: {}, options: {}) ⇒ Senpai

Returns a new instance of Senpai.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/repost/senpai.rb', line 12

def initialize(url, params: {}, options: {})
  @url                = url
  @params             = params
  @options            = options
  @method             = options.fetch(:method, :post).to_s.downcase
  @authenticity_token = options.fetch(:authenticity_token, nil)
  @charset            = options.fetch(:charset, DEFAULT_CHARSET)
  @form_id            = options.fetch(:form_id, generated_form_id)
  @autosubmit         = options.fetch(:autosubmit, true)
  @autosubmit_nonce   = options.fetch(:autosubmit_nonce, nil)
  @section_classes    = options.dig(:decor, :section, :classes)
  @section_html       = options.dig(:decor, :section, :html)
  @submit_classes     = options.dig(:decor, :submit, :classes)
  @submit_text        = options.dig(:decor, :submit, :text) || DEFAULT_SUBMIT_BUTTON_TEXT
end

Instance Method Details

#performObject



28
29
30
31
32
33
34
35
# File 'lib/repost/senpai.rb', line 28

def perform
  compiled_body = if autosubmit
                    form_body << auto_submit_script << no_script
                  else
                    form_body << submit_section
                  end
  form_head << compiled_body << form_footer
end