module Representable
NOTE: this might become a separate class, that's why it's in a separate file.
Constants
- As
- AssignAs
Warning: don't rely on AssignAs/AssignName, i am not sure if i leave that as functions.
- AssignFragment
Deprecation strategy: binding.evaluate_option_with_deprecation(:reader, options, :doc)
=> binding.evaluate_option(:reader, options) # always pass in options.
- AssignName
- Decorate
- Default
- Deserialize
- Deserializer
- FindOrInstantiate
- GetValue
- Getter
- If
- OptionsForNested
Prepares options for a particular nested representer. This is used in
Serializer
andDeserializer
.- OverwriteOnNil
- ParseFilter
- Prepare
CreateObject
= Function::CreateObject.new- ReadFragment
- Reader
- RenderDefault
TODO: evaluate this, if we need this.
- RenderFilter
- Serialize
- Serializer
- SetValue
- Setter
- SkipParse
- SkipRender
- Stop
- StopOnExcluded
- StopOnNil
- StopOnNotFound
- StopOnSkipable
- VERSION
- WriteFragment
- Writer
Attributes
representable_attrs[W]
Public Class Methods
included(base)
click to toggle source
# File lib/representable.rb, line 21 def self.included(base) base.class_eval do extend Declarative # make Representable horizontally and vertically inheritable. extend ModuleExtensions, ::Declarative::Heritage::Inherited, ::Declarative::Heritage::Included extend ClassMethods extend ForCollection extend Represent end end
Private Instance Methods
create_representation_with(doc, options, format)
click to toggle source
Compiles the document going through all properties.
# File lib/representable.rb, line 42 def create_representation_with(doc, options, format) propagated_options = normalize_options(options) representable_map!(doc, propagated_options, format, :compile_fragment) doc end
normalize_options(options)
click to toggle source
# File lib/representable.rb, line 77 def normalize_options(options) return options if options.any? {user_options: {}}.merge(options) # TODO: use keyword args once we drop 2.0. end
representable_attrs()
click to toggle source
# File lib/representable.rb, line 95 def representable_attrs @representable_attrs ||= self.class.definitions end
representable_bindings_for(format, options)
click to toggle source
# File lib/representable.rb, line 73 def representable_bindings_for(format, options) representable_attrs.collect {|definition| format.build(definition) } end
representable_map(options, format)
click to toggle source
# File lib/representable.rb, line 63 def representable_map(options, format) Binding::Map.new(representable_bindings_for(format, options)) end
representable_map!(doc, options, format, method)
click to toggle source
# File lib/representable.rb, line 67 def representable_map!(doc, options, format, method) options = {doc: doc, options: options, represented: represented, decorator: self} representable_map(options, format).(method, options) # .(:uncompile_fragment, options) end
representation_wrap(*args)
click to toggle source
# File lib/representable.rb, line 99 def representation_wrap(*args) representable_attrs.wrap_for(represented, *args) end
represented()
click to toggle source
# File lib/representable.rb, line 103 def represented self end
update_properties_from(doc, options, format)
click to toggle source
Reads values from doc
and sets properties accordingly.
# File lib/representable.rb, line 34 def update_properties_from(doc, options, format) propagated_options = normalize_options(options) representable_map!(doc, propagated_options, format, :uncompile_fragment) represented end