class-action 1.2.0 → 1.2.1

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: efcb015c47c36ad6a97afb3d09c8a24f92e2d78b
4
- data.tar.gz: 7563322db21411006066a429815da428275e15bc
3
+ metadata.gz: 97c5219d01a0bda05a42c7bb2f0c7c98fc6dd7ed
4
+ data.tar.gz: 8e0b56fdf6dd1d594b514c56ab08eb2b8651f406
5
5
  SHA512:
6
- metadata.gz: f47f51e9bf362cea79e40eb5b06dec063b9c250fc82cb06b11d89141d921e35d0ad8ab3556331749b78a8dc9aa5e4f46c37afaf99c7518c0d6cf9aa3f1da71d0
7
- data.tar.gz: 911bc61ae935e384088ad33b8f47e6fac421e634f8e8b5ff68b7562ac964318701f17e4ab4e866bfb0dad5b229fc37e120458b139940fa814ccf3a6ea2898c53
6
+ metadata.gz: 035bd987eb5b496d5b2128053e1dfb9a3b7519f20215378d5ce772a6d0cb84e39fe61b9e39208c6ea1bb520fa659c75191d4ba0cac85d54ef50b5e13a555dc63
7
+ data.tar.gz: ee7bbe117d9d52850bf0ca387c95e6c639e563d4faa998472ac518a98d8ff80c5889d4785c189752b41d2611bdb0cda1fa712df0c79256e82544d00bc01e82c4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- class-action (1.2.0)
4
+ class-action (1.2.1)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -1,3 +1,3 @@
1
1
  module ClassAction
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
data/lib/class_action.rb CHANGED
@@ -42,6 +42,22 @@ module ClassAction
42
42
  end
43
43
  end
44
44
 
45
+ # Delegates the given method to the current class action.
46
+ def class_action_delegate(*methods)
47
+ file, line = caller.first.split(':', 2)
48
+ line = line.to_i
49
+
50
+ methods.each do |method|
51
+ definition = (method =~ /[^\]]=$/) ? 'arg' : '*args, &block'
52
+
53
+ module_eval(<<-RUBY, file, line)
54
+ def #{method}(#{definition})
55
+ class_action.send :#{method}, #{definition}
56
+ end
57
+ RUBY
58
+ end
59
+ end
60
+
45
61
  private
46
62
 
47
63
  # Injects the mimes (formats) that the action responds to into the controller
@@ -189,4 +189,26 @@ describe ClassAction do
189
189
 
190
190
  end
191
191
 
192
+ describe 'method delegation' do
193
+
194
+ it "should allow delegating a method to the current class action" do
195
+ ClassActionTestController.class_eval do
196
+ class_action :show
197
+ class_action_delegate :one, :two
198
+ end
199
+
200
+ action_class = Class.new do
201
+ def one; :one end
202
+ def two; :two end
203
+ protected :two
204
+ end
205
+
206
+ allow(controller).to receive(:class_action).and_return(action_class.new)
207
+ expect(controller.one).to be(:one)
208
+ expect(controller.two).to be(:two)
209
+ expect{controller.three}.to raise_error(NoMethodError)
210
+ end
211
+
212
+ end
213
+
192
214
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: class-action
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joost Lubach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-10 00:00:00.000000000 Z
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -158,3 +158,4 @@ test_files:
158
158
  - spec/class_action/rspec/respond_with_matcher_spec.rb
159
159
  - spec/class_action_spec.rb
160
160
  - spec/spec_helper.rb
161
+ has_rdoc: