Class: Representable::Config
- Inherits:
-
Declarative::Definitions
- Object
- Declarative::Definitions
- Representable::Config
- 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
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#options ⇒ Object
FIXME: this is not inherited.
- #remove(name) ⇒ Object
- #wrap=(value) ⇒ Object
-
#wrap_for(represented, options = {}, &block) ⇒ Object
Computes the wrap string or returns false.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
12 13 14 15 |
# File 'lib/representable/config.rb', line 12 def initialize(*) super @wrap = nil end |
Instance Method Details
#options ⇒ Object
FIXME: this is not inherited.
21 22 23 |
# File 'lib/representable/config.rb', line 21 def # FIXME: this is not inherited. @options ||= {} end |
#remove(name) ⇒ Object
17 18 19 |
# File 'lib/representable/config.rb', line 17 def remove(name) delete(name.to_s) end |
#wrap=(value) ⇒ Object
25 26 27 28 |
# File 'lib/representable/config.rb', line 25 def wrap=(value) value = value.to_s if value.is_a?(Symbol) @wrap = ::Representable::Option(value) end |
#wrap_for(represented, options = {}, &block) ⇒ Object
Computes the wrap string or returns false.
31 32 33 34 35 36 37 38 39 |
# File 'lib/representable/config.rb', line 31 def wrap_for(represented, = {}, &block) return unless @wrap value = @wrap.(exec_context: represented, keyword_arguments: .to_hash) return value if value != true infer_name_for(represented.class.name) end |