From dff12a5e905187e126e4a6285f8dc691e29d29f3 Mon Sep 17 00:00:00 2001 From: Dane Jensen Date: Thu, 6 May 2021 11:22:33 -0700 Subject: [PATCH] Accept explicit set of named arguments in Resource.property --- CHANGELOG.md | 4 ++++ lib/praxis-mapper/resource.rb | 4 ++-- spec/praxis-mapper/resource_spec.rb | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02494fd..a2d23ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # praxis-mapper changelog +## next + +* Updated `Resource.property` signature to only accept known named arguments (`dependencies` and `though` at this time) to spare anyone else from going insane wondering why their `depednencies` aren't working. + ## 4.5 (6/25/2019) * Support wrapping associations in resources for targets that do not explicitly contain the `Enumerable` module. For example, `ActiveRecord::Associations::CollectionProxy` are actually not enumerable, yet they proxy the calls directly to the underlying objects when necessary. diff --git a/lib/praxis-mapper/resource.rb b/lib/praxis-mapper/resource.rb index 6cd70a6..1ae9f28 100644 --- a/lib/praxis-mapper/resource.rb +++ b/lib/praxis-mapper/resource.rb @@ -73,8 +73,8 @@ def self.decorate(name, &block) self.decorations[name] = Class.new(ResourceDecorator, &block) end - def self.property(name, **options) - self.properties[name] = options + def self.property(name, dependencies: nil, through: nil) + self.properties[name] = {dependencies: dependencies, through: through} end def self._finalize! diff --git a/spec/praxis-mapper/resource_spec.rb b/spec/praxis-mapper/resource_spec.rb index 7c843a3..c51b945 100644 --- a/spec/praxis-mapper/resource_spec.rb +++ b/spec/praxis-mapper/resource_spec.rb @@ -21,15 +21,15 @@ subject(:properties) { resource.properties } it 'includes directly-set properties' do - properties[:other_resource].should eq(dependencies: [:other_model]) + properties[:other_resource].should eq(dependencies: [:other_model], through: nil) end it 'inherits from a superclass' do - properties[:href].should eq(dependencies: [:id]) + properties[:href].should eq(dependencies: [:id], through: nil) end it 'properly overrides a property from the parent' do - properties[:name].should eq(dependencies: [:simple_name]) + properties[:name].should eq(dependencies: [:simple_name], through: nil) end end end