Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix populator bug causing new data to never be set. #198

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/representable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ def normalize_options(options)
child_options[:wrap] = binding[:wrap] unless binding[:wrap].nil?

# nested params:
child_options.merge!(options[binding.name.to_sym]) if options[binding.name.to_sym]
if nested_options = options[binding.name.to_sym] || options[binding.name.to_s]
child_options.merge!(nested_options)
if nested_options.key?("user_options")
child_options[:user_options].merge!(nested_options["user_options"])
end
end
child_options
end

Expand Down
9 changes: 0 additions & 9 deletions lib/representable/populator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ class Populator

object_class = binding[:class].(input, options)
object = object_class.find_by(id: input["id"]) || object_class.new
if options[:binding].array?
# represented.songs[i] = model
options[:represented].send(binding.getter)[options[:index]] = object
else
# represented.song = model
options[:represented].send(binding.setter, object)
end

object
}

Expand All @@ -23,7 +15,6 @@ def self.apply!(options)

options[:parse_pipeline] = ->(input, options) do
pipeline = Pipeline[*parse_functions] # TODO: AssignFragment
pipeline = Pipeline::Insert.(pipeline, SetValue, delete: true) # remove the setter function.
pipeline = Pipeline::Insert.(pipeline, populator, replace: CreateObject::Populator) # let the actual populator do the job.
# puts pipeline.extend(Representable::Pipeline::Debug).inspect
pipeline
Expand Down
2 changes: 1 addition & 1 deletion representable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake"
spec.add_development_dependency "test_xml", "0.1.6"
spec.add_development_dependency "minitest"
spec.add_development_dependency "mongoid"
spec.add_development_dependency "mongoid", "~> 5.1.4"
spec.add_development_dependency "virtus"
spec.add_development_dependency "json", '>= 1.7.7'

Expand Down