Class: Golden::SingleFormPresenter

Inherits:
ApplicationPresenter show all
Defined in:
lib/golden/objects/form/single_form_presenter.rb

Direct Known Subclasses

QueryFormPresenter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(form, accessors = {}) ⇒ SingleFormPresenter

Returns a new instance of SingleFormPresenter.



20
21
22
23
# File 'lib/golden/objects/form/single_form_presenter.rb', line 20

def initialize(form, accessors = {})
  assign_form_attributes(form, excludes: excluded_form_accessors)
  assign_attributes(accessors || {})
end

Instance Attribute Details

#formObject (readonly)

include Rails.application.routes.url_helpers



16
17
18
# File 'lib/golden/objects/form/single_form_presenter.rb', line 16

def form
  @form
end

Class Method Details

.form_accessors(permits) ⇒ Object



6
7
8
9
10
11
# File 'lib/golden/objects/form/single_form_presenter.rb', line 6

def form_accessors(permits)
  accessors = permits.reject do |permit|
    %w[Symbol String].exclude? permit.class.name
  end
  attr_accessor(*accessors)
end

Instance Method Details

#assign_form_attributes(form, excludes: []) ⇒ Object



25
26
27
28
29
30
# File 'lib/golden/objects/form/single_form_presenter.rb', line 25

def assign_form_attributes(form, excludes: [])
  @form = form
  accessors = form.class.permits.reject { |permit| excludes.include?(permit) }
  self.class.form_accessors accessors
  assign_attributes form.attributes.slice(*accessors)
end

#excluded_form_accessorsObject



32
33
34
# File 'lib/golden/objects/form/single_form_presenter.rb', line 32

def excluded_form_accessors
  []
end

#persisted?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/golden/objects/form/single_form_presenter.rb', line 36

def persisted?
  false
end