Module: FormObject::Integrations::Base::ClassMethods
- Included in:
- FormObject::Integrations::Base
- Defined in:
- lib/form_object/integrations/base.rb
Overview
DSL methods for integrations
Instance Attribute Summary collapse
-
#defaults ⇒ Object
The default optons for integration.
Instance Method Summary collapse
- #assign_model_attributes(form_instance, model_instance) ⇒ Object
-
#avaliable? ⇒ Boolean
Integration avaliable only if the ORM that integration is for currently defined.
-
#extended(base) ⇒ Object
Extend only active versions.
-
#integration_name ⇒ Object
The name of integration.
- #matches?(klass) ⇒ Boolean
- #matches_ancestors?(ancestors) ⇒ Boolean
-
#matching_ancestors ⇒ Object
The list of ancestor names that cause this integration to matched.
-
#version(name, &blk) ⇒ Object
Define current version for integration Can override some methods for different versions.
- #versions ⇒ Object
Instance Attribute Details
#defaults ⇒ Object
The default optons for integration
8 9 10 |
# File 'lib/form_object/integrations/base.rb', line 8 def defaults @defaults end |
Instance Method Details
#assign_model_attributes(form_instance, model_instance) ⇒ Object
69 70 71 |
# File 'lib/form_object/integrations/base.rb', line 69 def assign_model_attributes( form_instance, model_instance ) form_instance.attributes = model_instance.attributes end |
#avaliable? ⇒ Boolean
Integration avaliable only if the ORM that integration is for currently defined
19 20 21 |
# File 'lib/form_object/integrations/base.rb', line 19 def avaliable? matching_ancestors.any? && Object.const_defined?(matching_ancestors[0].split('::')[0]) end |
#extended(base) ⇒ Object
Extend only active versions
74 75 76 77 78 |
# File 'lib/form_object/integrations/base.rb', line 74 def extended( base ) versions.select(&:active?).each do |version| base.extend(version) end end |
#integration_name ⇒ Object
The name of integration
11 12 13 14 15 |
# File 'lib/form_object/integrations/base.rb', line 11 def integration_name @integration_name ||= begin FormObject::Utils::StringConverter.integration_name(self.name).to_sym end end |
#matches?(klass) ⇒ Boolean
29 30 31 |
# File 'lib/form_object/integrations/base.rb', line 29 def matches?( klass ) matches_ancestors?(klass.ancestors.map(&:name)) end |
#matches_ancestors?(ancestors) ⇒ Boolean
33 34 35 |
# File 'lib/form_object/integrations/base.rb', line 33 def matches_ancestors?( ancestors ) (ancestors & matching_ancestors).any? end |
#matching_ancestors ⇒ Object
The list of ancestor names that cause this integration to matched.
25 26 27 |
# File 'lib/form_object/integrations/base.rb', line 25 def matching_ancestors [] end |
#version(name, &blk) ⇒ Object
Define current version for integration Can override some methods for different versions
Example:
module FormObject
module Integrations
module DataMapper
version '1.x' do
def persist_model
# model.save
end
end
version '2.x' do
def persist_model
# DataMapper[model.class].persist(model)
end
end
end
end
end
64 65 66 67 |
# File 'lib/form_object/integrations/base.rb', line 64 def version( name, &blk ) versions << mod = Module.new( &blk ) mod end |
#versions ⇒ Object
37 38 39 |
# File 'lib/form_object/integrations/base.rb', line 37 def versions @versions ||= [] end |