lib/representable/definition.rb in representable-2.0.4 vs lib/representable/definition.rb in representable-2.1.0

- old
+ new

@@ -31,12 +31,13 @@ setup!(options, &block) # FIXME: this doesn't yield :as etc. self end - extend Forwardable - def_delegators :@runtime_options, :[], :each + def [](name) + @runtime_options[name] + end def clone self.class.new(name, @options.clone) end @@ -47,11 +48,11 @@ def typed? self[:class] or self[:extend] or self[:instance] end def representable? - return if self[:representable] === false + return if self[:representable] == false self[:representable] or typed? end def array? self[:collection] @@ -59,32 +60,27 @@ def hash? self[:hash] end - def default_for(value) - return self[:default] if skipable_empty_value?(value) - value - end - def has_default? @options.has_key?(:default) end def representer_module @options[:extend] end - def skipable_empty_value?(value) - return true if array? and self[:render_empty] == false and value and value.size == 0 # TODO: change in 2.0, don't render emtpy. - value.nil? and not self[:render_nil] - end - def create_binding(*args) self[:binding].call(self, *args) end + def inspect + state = (instance_variables-[:@runtime_options, :@name]).collect { |ivar| "#{ivar}=#{instance_variable_get(ivar)}" } + "#<Representable::Definition ==>#{name} #{state.join(" ")}>" + end + private def setup!(options, &block) handle_extend!(options) handle_as!(options) @@ -107,10 +103,10 @@ @runtime_options[name] = value end end def dynamic_options - [:as, :getter, :setter, :class, :instance, :reader, :writer, :extend, :prepare, :if, :deserialize, :serialize, :render_filter, :parse_filter] + [:as, :getter, :setter, :class, :instance, :reader, :writer, :extend, :prepare, :if, :deserialize, :serialize, :render_filter, :parse_filter, :skip_parse] end def handle_extend!(options) mod = options.delete(:extend) || options.delete(:decorator) and options[:extend] = mod end