Module: Intelligence::Adapter::ModuleMethods
- Included in:
- Intelligence::Adapter
- Defined in:
- lib/intelligence/adapter/module_methods.rb
Instance Method Summary collapse
- #[](adapter_type) ⇒ Object
- #build(adapter_type, attributes = nil, &block) ⇒ Object
- #build!(adapter_type, attributes = nil, &block) ⇒ Object
Instance Method Details
#[](adapter_type) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/intelligence/adapter/module_methods.rb', line 5 def []( adapter_type ) raise ArgumentError.new( "An adapter type is required but nil was given." ) \ if adapter_type.nil? class_name = adapter_type.to_s.split( '_' ).map( &:capitalize ).join class_name += "::Adapter" adapter_class = Intelligence.const_get( class_name ) rescue nil if adapter_class.nil? adapter_file = File.( "../../adapters/#{adapter_type}", __FILE__ ) unless require adapter_file raise ArgumentError.new( "The Intelligence adapter file #{adapter_file} is missing or does not define #{class_name}." ) end adapter_class = Intelligence.const_get( class_name ) rescue nil end raise ArgumentError.new( "An unknown Intelligence adapter #{adapter_type} was requested." ) \ if adapter_class.nil? adapter_class end |
#build(adapter_type, attributes = nil, &block) ⇒ Object
31 32 33 |
# File 'lib/intelligence/adapter/module_methods.rb', line 31 def build( adapter_type, attributes = nil, &block ) self.[]( adapter_type ).build( attributes, &block ) end |
#build!(adapter_type, attributes = nil, &block) ⇒ Object
35 36 37 |
# File 'lib/intelligence/adapter/module_methods.rb', line 35 def build!( adapter_type, attributes = nil, &block ) self.[]( adapter_type ).build!( attributes, &block ) end |