Class: Representable::Config

Inherits:
Declarative::Definitions
  • Object
show all
Defined in:
lib/representable/config.rb

Overview

Stores Definitions from ::property. It preserves the adding order (1.9+). Same-named properties get overridden, just like in a Hash.

Overwrite definition_class if you need a custom Definition object (helpful when using representable in other gems).

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



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

def initialize(*)
  super
  @wrap = nil
end

Instance Method Details

#optionsObject

FIXME: this is not inherited.



17
18
19
# File 'lib/representable/config.rb', line 17

def options # FIXME: this is not inherited.
  @options ||= {}
end

#remove(name) ⇒ Object



13
14
15
# File 'lib/representable/config.rb', line 13

def remove(name)
  delete(name.to_s)
end

#wrap=(value) ⇒ Object



21
22
23
24
# File 'lib/representable/config.rb', line 21

def wrap=(value)
  value = value.to_s if value.is_a?(Symbol)
  @wrap = ::Declarative::Option(value, instance_exec: true, callable: Uber::Callable)
end

#wrap_for(represented, *args, &block) ⇒ Object

Computes the wrap string or returns false.



27
28
29
30
31
32
33
34
# File 'lib/representable/config.rb', line 27

def wrap_for(represented, *args, &block)
  return unless @wrap

  value = @wrap.(represented, *args)

  return value if value != true
  infer_name_for(represented.class.name)
end