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

Instance Method Summary collapse

Instance Attribute Details

#defaultsObject

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

Returns:

  • (Boolean)


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_nameObject

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

Returns:

  • (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

Returns:

  • (Boolean)


33
34
35
# File 'lib/form_object/integrations/base.rb', line 33

def matches_ancestors?( ancestors )
  (ancestors & matching_ancestors).any?
end

#matching_ancestorsObject

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

#versionsObject



37
38
39
# File 'lib/form_object/integrations/base.rb', line 37

def versions
  @versions ||= []
end