module Representable::Binding::Factories

Public Instance Methods

collect_for(item_functions) click to toggle source

i decided not to use polymorphism here for the sake of clarity.

# File lib/representable/pipeline_factories.rb, line 11
def collect_for(item_functions)
  return [Collect[*item_functions]] if array?
  return [Collect::Hash[*item_functions]] if self[:hash]
  item_functions
end
default_parse_fragment_functions() click to toggle source
# File lib/representable/pipeline_factories.rb, line 66
def default_parse_fragment_functions
  functions = [AssignFragment]
  functions << SkipParse if self[:skip_parse]

  if self[:class] or self[:extend] or self[:instance] or self[:populator]
    if self[:populator]
      functions << CreateObject::Populator
    elsif self[:parse_strategy]
      functions << CreateObject::Instance # TODO: remove in 2.5.
    else
      functions << (self[:class] ? CreateObject::Class : CreateObject::Instance)
    end

    functions << Prepare     if self[:prepare]
    functions << Decorate    if self[:extend]
    if representable?
      functions << (self[:deserialize] ? Deserializer : Deserialize)
    end
  end

  functions
end
default_parse_init_functions() click to toggle source
# File lib/representable/pipeline_factories.rb, line 55
def default_parse_init_functions
  functions = []
  functions << Stop if self[:writeable]==false
  functions << StopOnExcluded
  functions << If if self[:if]
  functions << (self[:as] ? AssignAs : AssignName)
  functions << (self[:reader] ? Reader : ReadFragment)
  functions << (has_default? ? Default : StopOnNotFound)
  functions << OverwriteOnNil # include StopOnNil if you don't want to erase things.
end
default_post_functions() click to toggle source
# File lib/representable/pipeline_factories.rb, line 89
def default_post_functions
  funcs = []
  funcs << ParseFilter if self[:parse_filter].any?
  funcs << (self[:setter] ? Setter : SetValue)
end
default_render_fragment_functions() click to toggle source
# File lib/representable/pipeline_factories.rb, line 26
def default_render_fragment_functions
  functions = []
  functions << SkipRender if self[:skip_render]
  if typed? # TODO: allow prepare regardless of :extend, which makes it independent of typed?
    if self[:prepare]
      functions << Prepare
    end
    # functions << (self[:prepare] ? Prepare : Decorate)
  end
  functions << Decorate if self[:extend] and !self[:prepare]
  if representable?
    functions << (self[:serialize] ? Serializer : Serialize)
  end
  functions
end
default_render_init_functions() click to toggle source
# File lib/representable/pipeline_factories.rb, line 42
def default_render_init_functions
  functions = []
  functions << Stop if self[:readable]==false
  functions << StopOnExcluded
  functions << If if self[:if]
  functions << (self[:getter] ? Getter : GetValue)
  functions << Writer if self[:writer]
  functions << RenderFilter if self[:render_filter].any?
  functions << RenderDefault if has_default?
  functions << StopOnSkipable
  functions << (self[:as] ? AssignAs : AssignName)
end
parse_functions() click to toggle source
# File lib/representable/pipeline_factories.rb, line 17
def parse_functions
  [*default_parse_init_functions, *collect_for(default_parse_fragment_functions), *default_post_functions]
end
pipeline_for(name, input, options) { || ... } click to toggle source
# File lib/representable/pipeline_factories.rb, line 4
def pipeline_for(name, input, options)
  return yield unless proc = @definition[name]
  # proc.(self, options)
  instance_exec(input, options, &proc)
end
render_functions() click to toggle source

DISCUSS: StopOnNil, before collect

# File lib/representable/pipeline_factories.rb, line 22
def render_functions
  [*default_render_init_functions, *collect_for(default_render_fragment_functions), WriteFragment]
end