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
Public Class Methods
Source
# File lib/representable/option.rb, line 16 def self.Option(value) ::Representable::Option.build(value) end
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
Source
# 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
Compiles the document going through all properties.
Source
# File lib/representable.rb, line 75 def normalize_options(user_options: {}, **options) { user_options: user_options }.merge(options) end
Source
# File lib/representable.rb, line 92 def representable_attrs @representable_attrs ||= self.class.definitions end
Source
# File lib/representable.rb, line 71 def representable_bindings_for(format, options) representable_attrs.collect {|definition| format.build(definition) } end
Source
# File lib/representable.rb, line 61 def representable_map(options, format) Binding::Map.new(representable_bindings_for(format, options)) end
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
Source
# File lib/representable.rb, line 96 def representation_wrap(options = {}) representable_attrs.wrap_for(represented, options) end
Source
# 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
Reads values from doc
and sets properties accordingly.