lib/rabl/builder.rb in rabl-0.12.0 vs lib/rabl/builder.rb in rabl-0.13.0

- old
+ new

@@ -13,11 +13,11 @@ # Constructs a new rabl hash based on given object and options # options = { :format => "json", :root => true, :child_root => true, # :attributes, :node, :child, :glue, :extends } # - def initialize(object, settings = {}, options = {}, &block) + def initialize(object, settings = {}, options = {}) @_object = object @settings = settings @options = options @_context_scope = options[:scope] @@ -39,11 +39,11 @@ def replace_engine(engine, value) engines[engines.index(engine)] = value end - def to_hash(object = nil, settings = {}, options = {}) + def to_hash(object = nil, settings = nil, options = nil) @_object = object if object @options.merge!(options) if options @settings.merge!(settings) if settings cache_results do @@ -166,13 +166,13 @@ return unless data.present? && resolve_condition(options) name = is_name_value?(options[:root]) ? options[:root] : data_name(data) object = data_object(data) - include_root = is_collection?(object) && options.fetch(:object_root, @options[:child_root]) # child @users - engine_options = @options.slice(:child_root).merge(:root => include_root) - engine_options.merge!(:object_root_name => options[:object_root]) if is_name_value?(options[:object_root]) + engine_options = @options.slice(:child_root) + engine_options[:root] = is_collection?(object) && options.fetch(:object_root, @options[:child_root]) # child @users + engine_options[:object_root_name] = options[:object_root] if is_name_value?(options[:object_root]) object = { object => name } if data.is_a?(Hash) && object # child :users => :people engines << { name.to_sym => object_to_engine(object, engine_options, &block) } end @@ -190,10 +190,10 @@ # Extends an existing rabl template with additional attributes in the block # extends("users/show") { attribute :full_name } def extends(file, options = {}, &block) return unless resolve_condition(options) - options = @options.slice(:child_root).merge(:object => @_object).merge(options) + options = @options.slice(:child_root).merge!(:object => @_object).merge!(options) engines << partial_as_engine(file, options, &block) end # Evaluate conditions given a symbol/proc/lambda/variable to evaluate def call_condition_proc(condition, object)