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
Option(value)
click to toggle source
# File lib/representable/option.rb, line 16 def self.Option(value) ::Representable::Option.build(value) end
included(base)
click to toggle source
# File lib/representable.rb, line 32 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 53 def create_representation_with(doc, options, format) propagated_options = normalize_options(**options) representable_map!(doc, propagated_options, format, :compile_fragment) doc end
normalize_options(user_options: {}, **options)
click to toggle source
# File lib/representable.rb, line 75 def normalize_options(user_options: {}, **options) { user_options: user_options }.merge(options) end
representable_attrs()
click to toggle source
# File lib/representable.rb, line 92 def representable_attrs @representable_attrs ||= self.class.definitions end
representable_bindings_for(format, options)
click to toggle source
# File lib/representable.rb, line 71 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 61 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 65 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(options = {})
click to toggle source
# File lib/representable.rb, line 96 def representation_wrap(options = {}) representable_attrs.wrap_for(represented, options) end
represented()
click to toggle source
# File lib/representable.rb, line 100 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 45 def update_properties_from(doc, options, format) propagated_options = normalize_options(**options) representable_map!(doc, propagated_options, format, :uncompile_fragment) represented end