class Representable::Config
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).
Public Class Methods
new(*)
click to toggle source
Calls superclass method
# File lib/representable/config.rb, line 8 def initialize(*) super @wrap = nil end
Public Instance Methods
options()
click to toggle source
# File lib/representable/config.rb, line 17 def options # FIXME: this is not inherited. @options ||= {} end
remove(name)
click to toggle source
# File lib/representable/config.rb, line 13 def remove(name) delete(name.to_s) end
wrap=(value)
click to toggle source
# 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)
click to toggle source
Computes the wrap string or returns false.
# 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
Private Instance Methods
infer_name_for(name)
click to toggle source
# File lib/representable/config.rb, line 37 def infer_name_for(name) name.to_s.split('::').last. gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). downcase end