Class: ActiveData::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/active_data/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



12
13
14
15
16
17
18
19
# File 'lib/active_data/config.rb', line 12

def initialize
  @include_root_in_json = false
  @i18n_scope = :active_data
  @logger = Logger.new(STDERR)
  @primary_attribute = :id
  @_normalizers = {}
  @_typecasters = {}
end

Instance Attribute Details

#_normalizersObject

Returns the value of attribute _normalizers.



5
6
7
# File 'lib/active_data/config.rb', line 5

def _normalizers
  @_normalizers
end

#_typecastersObject

Returns the value of attribute _typecasters.



5
6
7
# File 'lib/active_data/config.rb', line 5

def _typecasters
  @_typecasters
end

#base_classObject

Returns the value of attribute base_class.



5
6
7
# File 'lib/active_data/config.rb', line 5

def base_class
  @base_class
end

#base_concernObject

Returns the value of attribute base_concern.



5
6
7
# File 'lib/active_data/config.rb', line 5

def base_concern
  @base_concern
end

#i18n_scopeObject

Returns the value of attribute i18n_scope.



5
6
7
# File 'lib/active_data/config.rb', line 5

def i18n_scope
  @i18n_scope
end

#include_root_in_jsonObject

Returns the value of attribute include_root_in_json.



5
6
7
# File 'lib/active_data/config.rb', line 5

def include_root_in_json
  @include_root_in_json
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/active_data/config.rb', line 5

def logger
  @logger
end

#primary_attributeObject

Returns the value of attribute primary_attribute.



5
6
7
# File 'lib/active_data/config.rb', line 5

def primary_attribute
  @primary_attribute
end

Class Method Details

.delegatedObject



8
9
10
# File 'lib/active_data/config.rb', line 8

def self.delegated
  public_instance_methods - superclass.public_instance_methods - Singleton.public_instance_methods
end

Instance Method Details

#normalizer(name, &block) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/active_data/config.rb', line 21

def normalizer(name, &block)
  if block
    _normalizers[name.to_sym] = block
  else
    _normalizers[name.to_sym] or raise NormalizerMissing, name
  end
end

#typecaster(*classes, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/active_data/config.rb', line 29

def typecaster(*classes, &block)
  classes = classes.flatten
  if block
    _typecasters[classes.first.to_s.camelize] = block
  else
    _typecasters[classes.detect do |klass|
      _typecasters[klass.to_s.camelize]
    end.to_s.camelize] or raise TypecasterMissing, classes
  end
end