Class: DactylForm

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/dactyl_form.rb

Overview

TODO Thread safety TODO Raise exceptions on invalid input TODO Possible normalizations infinite loop TODO Comments TODO (attribute)_change inspection and handling TODO Readme file TODO License file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, params = nil) ⇒ DactylForm

Returns a new instance of DactylForm.



15
16
17
18
19
20
21
# File 'lib/dactyl_form.rb', line 15

def initialize(object, params = nil)
  @object = object
  @params = params
  @attribute_cache = {}
  @persisted = object.persisted?
  self.class.define_getters unless self.class.getters_defined?
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



13
14
15
# File 'lib/dactyl_form.rb', line 13

def object
  @object
end

Instance Method Details

#creating?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/dactyl_form.rb', line 31

def creating?
  !updating?
end

#http_methodObject



23
24
25
# File 'lib/dactyl_form.rb', line 23

def http_method
  updating? ? :put : :post
end

#processObject



35
36
37
38
39
40
41
42
43
# File 'lib/dactyl_form.rb', line 35

def process
  if valid?
    save_object
    true
  else
    restore_params
    false
  end
end

#updating?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/dactyl_form.rb', line 27

def updating?
  persisted?
end