resourcerer 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55448f1a54313470f4c84d50243ad79ce0f13750
4
- data.tar.gz: 30de7964ebdff67394987395145c00e156cdafe9
3
+ metadata.gz: efd793cb62e4dc4237140caaafc4788f90d7512b
4
+ data.tar.gz: 8c2cb136555283429df108083d70301283c8aca9
5
5
  SHA512:
6
- metadata.gz: 0201a4f045934bd7b2bfc9fd7ca32b324386d618c84ee9da16963d73002472d801c7487972151a29d856c3f926725748f05a08e05844819cd29fec7c736ee4d5
7
- data.tar.gz: b06fb4cbbc6216be391e6bf9af24019596a4af8bd0459fd30f2e3178c6d99be48743ee17474b0497f4c5f2e773686a918fe9f504f43fb1d5fa1f1186a0b3f593
6
+ metadata.gz: 5f7710479b0c98397f045ca492d2f30a6465630fbabc8a22b6cdbb0cf64a515aad3845ab66246d9989f528b8000ef98f185d828c0c6eb22e42089755ca9c9919
7
+ data.tar.gz: 291983c1a28aafabe478019f8e24c5bd5b9ce774085c3482579db82252a2fa36495abfbf54646bde5803e165e68ed8e91ab34f5eb4f2baee304fccec5c3c2d22
data/README.md CHANGED
@@ -152,7 +152,7 @@ resource(:employee, model: :person, finder_attribute: :name, finder: ->(name){ c
152
152
  The DSL is more convenient when you have an object oriented design and want to allow an object to handle its collections, or as a quick way to set the StrongParameters method.
153
153
 
154
154
  Configuration options play well together, and the defaults try to make intelligent use of them. For example,
155
- setting the `finder_attribute` in the example abovie changes the `finder_param` to `person_name` instead of `person_id`, and the value of that parameter is provided to the finder block.
155
+ setting the `finder_attribute` in the example above changes the `finder_param` to `person_name` instead of `person_id`, and the value of that parameter is provided to the finder block.
156
156
 
157
157
  ### Setting a distinct object for a single action
158
158
 
@@ -8,10 +8,6 @@ module Resourcerer
8
8
  @options = options || {}
9
9
  end
10
10
 
11
- def attributes
12
- @attributes ||= options[:attributes].try(:call)
13
- end
14
-
15
11
  def method_missing(name, *args)
16
12
  super if args.size > 1
17
13
  define_option_method(name)
@@ -9,7 +9,7 @@ module Resourcerer
9
9
  end
10
10
 
11
11
  def attributes
12
- config.attributes
12
+ @attributes ||= controller_eval(config.attributes)
13
13
  end
14
14
 
15
15
  def assign_attributes?
@@ -23,11 +23,17 @@ module Resourcerer
23
23
  end
24
24
 
25
25
  def find_resource(id)
26
- config.finder.try(:call, id) || model.find_by(finder_attribute => id)
26
+ controller_eval(config.finder, id) || model.find_by(finder_attribute => id)
27
27
  end
28
28
 
29
29
  def build_resource
30
- config.builder.try(:call) || model.new
30
+ controller_eval(config.builder) || model.new
31
+ end
32
+
33
+ protected
34
+
35
+ def controller_eval(proc, *args)
36
+ controller.instance_exec(*args, &proc) if proc
31
37
  end
32
38
  end
33
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resourcerer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Máximo Mussini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-25 00:00:00.000000000 Z
11
+ date: 2014-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport