Class: Udongo::Form

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/udongo/form.rb

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Form

Returns a new instance of Form.



6
7
8
9
# File 'lib/udongo/form.rb', line 6

def initialize(object)
  instance_var_name object
  init_attribute_values(object)
end

Instance Method Details

#init_attribute_values(object) ⇒ Object



11
12
13
# File 'lib/udongo/form.rb', line 11

def init_attribute_values(object)
  attributes.keys.each { |k| send("#{k}=", object.send(k)) }
end

#init_object_values(object) ⇒ Object



15
16
17
# File 'lib/udongo/form.rb', line 15

def init_object_values(object)
  attributes.each { |k, v| object.send("#{k}=", v) }
end

#persisted?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/udongo/form.rb', line 19

def persisted?
  false
end

#save(params) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/udongo/form.rb', line 23

def save(params)
  attributes.keys.each { |k| send("#{k}=", params[k]) }

  if valid?
    save_object
    true
  else
    false
  end
end

#save!Object

This method only exists so the related factory tests pass



35
36
37
# File 'lib/udongo/form.rb', line 35

def save!
  valid?
end