Class: Tramway::BaseForm

Inherits:
Object
  • Object
show all
Includes:
DuckTyping::ActiveRecordCompatibility, Forms::Normalizations, Forms::Properties
Defined in:
lib/tramway/base_form.rb

Overview

Provides form object for Tramway

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DuckTyping::ActiveRecordCompatibility

included

Methods included from Forms::Normalizations

#__apply_normalizations, included

Methods included from Forms::Properties

#__apply_properties, included

Constructor Details

#initialize(object) ⇒ BaseForm

Returns a new instance of BaseForm.



17
18
19
20
21
# File 'lib/tramway/base_form.rb', line 17

def initialize(object)
  @object = object

  self.class.delegate object.class.primary_key, to: :object
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/tramway/base_form.rb', line 52

def method_missing(method_name, *args)
  if method_name.to_s.end_with?('=') && args.count == 1
    object.public_send(method_name, args.first)
  else
    super
  end
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



15
16
17
# File 'lib/tramway/base_form.rb', line 15

def object
  @object
end

Class Method Details

.inherited(subclass) ⇒ Object



24
25
26
27
28
29
# File 'lib/tramway/base_form.rb', line 24

def inherited(subclass)
  __initialize_properties subclass
  __initialize_normalizations subclass

  super
end

Instance Method Details

#assign(params) ⇒ Object



48
49
50
# File 'lib/tramway/base_form.rb', line 48

def assign(params)
  __submit params
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/tramway/base_form.rb', line 60

def respond_to_missing?(method_name, include_private = false)
  method_name.to_s.end_with?('=') || super
end

#submit(params) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/tramway/base_form.rb', line 32

def submit(params)
  __submit params

  object.save.tap do
    __object
  end
end

#submit!(params) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/tramway/base_form.rb', line 40

def submit!(params)
  __submit params

  object.save!.tap do
    __object
  end
end