Module: FormObject::Integrations

Defined in:
lib/form_object/integrations.rb,
lib/form_object/integrations/base.rb,
lib/form_object/integrations/active_model.rb,
lib/form_object/integrations/active_record.rb,
lib/form_object/integrations/active_model/versions.rb,
lib/form_object/integrations/active_record/versions.rb

Defined Under Namespace

Modules: ActiveModel, ActiveRecord, Base

Class Method Summary collapse

Class Method Details

.allObject



39
40
41
42
43
44
45
# File 'lib/form_object/integrations.rb', line 39

def self.all
  # ActiveModel should be last item
  constants = self.constants.map {|c| c.to_s}
                            .select {|c| c != 'ActiveModel'}
                            .sort <<          'ActiveModel'
  constants.map {|c| const_get(c)}
end

.find_by_name(name) ⇒ Object

Find integration by name

Examples:

FormObject::Integrations.find_by_name(:active_record) # => FormObject::Integrations::ActiveRecord


35
36
37
# File 'lib/form_object/integrations.rb', line 35

def self.find_by_name( name )
  all.detect {|integration| integration.integration_name == name} || raise( InvalidIntegration.new(name) )
end

.match(klass) ⇒ Object

Find integrations for for selected class

Examples:

class User
end

class ActiveRecordUser < ActiveRecord::Base
end

FormObject::Integrations.match(User) # => nil
FormObject::Integrations.match(ActiveRecordUser) # => FormObject::Integrations::ActiveRecord


26
27
28
# File 'lib/form_object/integrations.rb', line 26

def self.match( klass )
  all.detect {|integration| integration.matches?(klass)}
end