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.3.0'
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
101
102
103
104
105
106
107
108
|
# File 'lib/forminate.rb', line 101
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
97
98
99
|
# File 'lib/forminate.rb', line 97
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
110
111
112
113
114
115
116
117
|
# File 'lib/forminate.rb', line 110
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
89
90
91
92
93
94
95
|
# File 'lib/forminate.rb', line 89
def save
if use_transaction?
ActiveRecord::Base.transaction { save! }
else
save!
end
end
|
#save! ⇒ Object
82
83
84
85
86
87
|
# File 'lib/forminate.rb', line 82
def save!
return false unless valid?
before_save
persist_associations
self
end
|