Module: Representable

Included in:
Decorator
Defined in:
lib/representable/pipeline_factories.rb,
lib/representable.rb,
lib/representable/xml.rb,
lib/representable/hash.rb,
lib/representable/json.rb,
lib/representable/yaml.rb,
lib/representable/debug.rb,
lib/representable/cached.rb,
lib/representable/config.rb,
lib/representable/insert.rb,
lib/representable/object.rb,
lib/representable/option.rb,
lib/representable/binding.rb,
lib/representable/version.rb,
lib/representable/coercion.rb,
lib/representable/pipeline.rb,
lib/representable/decorator.rb,
lib/representable/populator.rb,
lib/representable/definition.rb,
lib/representable/serializer.rb,
lib/representable/declarative.rb,
lib/representable/xml/binding.rb,
lib/representable/deserializer.rb,
lib/representable/hash/binding.rb,
lib/representable/hash_methods.rb,
lib/representable/yaml/binding.rb,
lib/representable/for_collection.rb,
lib/representable/object/binding.rb,
lib/representable/hash/allow_symbols.rb

Overview

NOTE: this might become a separate class, that’s why it’s in a separate file.

Defined Under Namespace

Modules: Cached, ClassMethods, Coercion, CreateObject, Debug, Declarative, ForCollection, Function, Hash, HashMethods, JSON, ModuleExtensions, Object, Represent, XML, YAML Classes: Binding, Collect, Config, Decorator, Definition, DeserializeError, Option, Pipeline, Populator

Constant Summary collapse

VERSION =
"3.2.0"
FindOrInstantiate =
Populator::FindOrInstantiate
Getter =
->(input, options) do
  options[:binding].evaluate_option(:getter, input, options)
end
GetValue =
->(_input, options) { options[:binding].send(:exec_context, options).public_send(options[:binding].getter) }
Writer =
->(input, options) do
  options[:binding].evaluate_option(:writer, input, options)
  Pipeline::Stop
end
RenderDefault =

TODO: evaluate this, if we need this.

->(input, options) do
  binding = options[:binding]

  binding.skipable_empty_value?(input) ? binding[:default] : input
end
StopOnSkipable =
->(input, options) do
  options[:binding].send(:skipable_empty_value?, input) ? Pipeline::Stop : input
end
RenderFilter =
->(input, options) do
  options[:binding][:render_filter].(input, options)
end
SkipRender =
->(input, options) do
  options[:binding].evaluate_option(:skip_render, input, options) ? Pipeline::Stop : input
end
Serializer =
->(input, options) do
  return if input.nil? # DISCUSS: how can we prevent that?

  options[:binding].evaluate_option(:serialize, input, options)
end
Serialize =
->(input, options) do
  return if input.nil? # DISCUSS: how can we prevent that?

  binding, options = options[:binding], options[:options] # FIXME: rename to :local_options.

  options_for_nested = OptionsForNested.(options, binding)

  input.send(binding.serialize_method, options_for_nested)
end
WriteFragment =
->(input, options) { options[:binding].write(options[:doc], input, options[:as]) }
As =
->(input, options) { options[:binding].evaluate_option(:as, input, options) }
AssignAs =

Warning: don’t rely on AssignAs/AssignName, i am not sure if i leave that as functions.

->(input, options) { options[:as] = As.(input, options); input }
AssignName =
->(input, options) { options[:as] = options[:binding].name; input }
AssignFragment =

Deprecation strategy: binding.evaluate_option_with_deprecation(:reader, options, :doc)

=> binding.evaluate_option(:reader, options) # always pass in options.
->(input, options) { options[:fragment] = input }
ReadFragment =
->(input, options) { options[:binding].read(input, options[:as]) }
Reader =
->(input, options) { options[:binding].evaluate_option(:reader, input, options) }
StopOnNotFound =
->(input, _options) do
  Binding::FragmentNotFound == input ? Pipeline::Stop : input
end
StopOnNil =

DISCUSS: Not tested/used, yet.

->(input, _options) do # DISCUSS: Not tested/used, yet.
  input.nil? ? Pipeline::Stop : input
end
OverwriteOnNil =
->(input, options) do
  input.nil? ? (SetValue.(input, options); Pipeline::Stop) : input
end
Default =
->(input, options) do
  Binding::FragmentNotFound == input ? options[:binding][:default] : input
end
SkipParse =
->(input, options) do
  options[:binding].evaluate_option(:skip_parse, input, options) ? Pipeline::Stop : input
end
Prepare =

CreateObject = Function::CreateObject.new

Function::Prepare.new
Decorate =
Function::Decorate.new
Deserializer =
->(input, options) { options[:binding].evaluate_option(:deserialize, input, options) }
Deserialize =
->(input, args) do
  binding, fragment, options = args[:binding], args[:fragment], args[:options]

  # user_options:
  child_options = OptionsForNested.(options, args[:binding])

  input.send(binding.deserialize_method, fragment, child_options)
end
ParseFilter =
->(input, options) do
  options[:binding][:parse_filter].(input, options)
end
Setter =
->(input, options) { options[:binding].evaluate_option(:setter, input, options) }
SetValue =
->(input, options) { options[:binding].send(:exec_context, options).send(options[:binding].setter, input) }
Stop =
->(*) { Pipeline::Stop }
If =
->(input, options) { options[:binding].evaluate_option(:if, nil, options) ? input : Pipeline::Stop }
StopOnExcluded =
->(input, options) do
  return input unless options[:options]
  return input unless props = (options[:options][:exclude] || options[:options][:include])

  res = props.include?(options[:binding].name.to_sym) # false with include: Stop. false with exclude: go!

  return input if options[:options][:include]&&res
  return input if options[:options][:exclude]&&!res

  Pipeline::Stop
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#representable_attrs=(value) ⇒ Object

Sets the attribute representable_attrs

Parameters:

  • value

    the value to set the attribute representable_attrs to.



30
31
32
# File 'lib/representable.rb', line 30

def representable_attrs=(value)
  @representable_attrs = value
end

Class Method Details

.included(base) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# 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

.Option(value) ⇒ Object



16
17
18
# File 'lib/representable/option.rb', line 16

def self.Option(value)
  ::Representable::Option.build(value)
end