Module: Forminate
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveAttr::Model
- Defined in:
- lib/forminate.rb,
lib/forminate/version.rb,
lib/forminate/association_builder.rb,
lib/forminate/association_definition.rb,
lib/forminate/client_side_validations.rb
Defined Under Namespace
Modules: ClassMethods, ClientSideValidations
Classes: AssociationBuilder, AssociationDefinition
Constant Summary
collapse
- VERSION =
'0.2.0'
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
98
99
100
101
102
103
104
105
|
# File 'lib/forminate.rb', line 98
def method_missing(name, *args, &block)
assoc, assoc_method_name = association_for_method(name)
if assoc && assoc.respond_to?(assoc_method_name)
assoc.send(assoc_method_name, *args)
else
super
end
end
|
Instance Method Details
#association_names ⇒ Object
74
75
76
|
# File 'lib/forminate.rb', line 74
def association_names
self.class.association_names
end
|
#associations ⇒ Object
78
79
80
|
# File 'lib/forminate.rb', line 78
def associations
Hash[association_names.map { |name| [name, send(name)] }]
end
|
#before_save ⇒ Object
94
95
96
|
# File 'lib/forminate.rb', line 94
def before_save
end
|
#initialize(attributes = {}) ⇒ Object
69
70
71
72
|
# File 'lib/forminate.rb', line 69
def initialize(attributes = {})
build_associations(attributes)
super
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
107
108
109
110
111
112
113
114
|
# File 'lib/forminate.rb', line 107
def respond_to_missing?(name, include_private = false)
assoc, assoc_method_name = association_for_method(name)
if assoc && assoc.respond_to?(assoc_method_name)
true
else
super
end
end
|
#save ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/forminate.rb', line 82
def save
return false unless valid?
before_save
if defined? ActiveRecord
ActiveRecord::Base.transaction { persist_associations }
else
persist_associations
end
self
end
|