module Jafry::Builder
Module for factoring schemes @since 0.1.0
Public Instance Methods
Return object builded from scheme
@param scheme_name [String] Scheme
name @param [Hash] options Options @option options [String] :wrap Namespace to wrap scheme in @return [Scheme] New Scheme
object build with pointed options @see Scheme
# File lib/jafry/builder.rb, line 18 def build(scheme_name, options={}) scheme = Scheme.new(parse_scheme(scheme_name)) scheme.update(options) if options scheme.self_name = scheme_name Jafry::Configurator.set_config(scheme_name) unless Jafry::Configurator.find_config(scheme_name) Jafry::Identificator.set_id_for_scheme(scheme) return wrap(options[:wrap], scheme) if options[:wrap] scheme end
Retun array of Scheme
objects
@param scheme_name [String] Scheme
name @param count [Integer] Number of objects in array @param options [Hash] Options @option options [String] :wrap Namespace to wrap list in @return [Array] Array of Schemes @see Scheme
# File lib/jafry/builder.rb, line 49 def build_list(scheme_name, count, options={}) list = [] count.times {list << build(scheme_name, options)} list end
Return json from scheme
@param scheme_name [String] Scheme
name @param options [Hash] Options @option options [String] :wrap Namespace to wrap json in @return [Scheme] New Scheme
object encoded to json @see Scheme
# File lib/jafry/builder.rb, line 36 def create(scheme_name, options={}) encode_json(build(scheme_name, options)) end
Retun array of Scheme
objects encoded to json
@param scheme_name [String] Scheme
name @param count [Integer] Number of objects in array @param options [Hash] Options @option options [String] :wrap Namespace to wrap json list in @return [Array] Json array of schemes @see Scheme
# File lib/jafry/builder.rb, line 64 def create_list(scheme_name, count, options={}) encode_json(build_list(scheme_name, count, options)) end