Class: Granite::Form::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



13
14
15
16
17
18
19
20
# File 'lib/granite/form/config.rb', line 13

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

Instance Attribute Details

#_normalizersObject

Returns the value of attribute _normalizers.



6
7
8
# File 'lib/granite/form/config.rb', line 6

def _normalizers
  @_normalizers
end

#base_classObject

Returns the value of attribute base_class.



6
7
8
# File 'lib/granite/form/config.rb', line 6

def base_class
  @base_class
end

#base_concernObject

Returns the value of attribute base_concern.



6
7
8
# File 'lib/granite/form/config.rb', line 6

def base_concern
  @base_concern
end

#i18n_scopeObject

Returns the value of attribute i18n_scope.



6
7
8
# File 'lib/granite/form/config.rb', line 6

def i18n_scope
  @i18n_scope
end

#include_root_in_jsonObject

Returns the value of attribute include_root_in_json.



6
7
8
# File 'lib/granite/form/config.rb', line 6

def include_root_in_json
  @include_root_in_json
end

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/granite/form/config.rb', line 6

def logger
  @logger
end

#primary_attributeObject

Returns the value of attribute primary_attribute.



6
7
8
# File 'lib/granite/form/config.rb', line 6

def primary_attribute
  @primary_attribute
end

#typesObject

Returns the value of attribute types.



6
7
8
# File 'lib/granite/form/config.rb', line 6

def types
  @types
end

Class Method Details

.delegatedObject



9
10
11
# File 'lib/granite/form/config.rb', line 9

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

Instance Method Details

#normalizer(name, &block) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/granite/form/config.rb', line 22

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

#type_for(klass) ⇒ Object



36
37
38
39
# File 'lib/granite/form/config.rb', line 36

def type_for(klass)
  key = klass.ancestors.grep(Class).map(&:to_s).find(&types) or raise TypecasterMissing, klass
  types.fetch(key)
end

#typecaster(class_name, &block) ⇒ Object



30
31
32
33
34
# File 'lib/granite/form/config.rb', line 30

def typecaster(class_name, &block)
  types[class_name.to_s.camelize] = Class.new(Types::Object) do
    define_method(:typecast, &block)
  end
end