action_director 0.0.2 → 0.0.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 +8 -8
- data/.travis.yml +2 -1
- data/README.md +9 -9
- data/lib/action_director/directable.rb +10 -10
- data/lib/action_director/directive.rb +4 -1
- data/lib/action_director/version.rb +1 -1
- data/test/lookup_test.rb +17 -0
- data/test/test_helper.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDhkZjk2NzQzYWZiNWJmNDlhYmQyMjU5MDhhNTkyNDcxMTA3OTAxNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmQ0MzM4Y2FmMDNkNTAwNmZjOTUwNjMxMmExN2Y5ZTkzZmQwOTcxZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NGUwYTE0ZDc5MWRmYjhlOTAwMjYxNmUzOWE0MDhmZTllODcwMTU2NTViNmFk
|
10
|
+
YTM3ZjVhZGIyN2ZjNTU1Nzc0MmY5NDMzNWMyODA1ZTVmZDk3ZGM5MTAwNWNh
|
11
|
+
OWMwNjk5MDA1OWIzNDI4ODAzNWJhMDE0MTU4MGU0NzM5MzE3NWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWE0N2MxZjUzOWY5NWYxMzMxMWU4OWVlNjM5MjFhNWE3ODU4ZmRmYmQwNGE4
|
14
|
+
MGJiMTFmZGI4ZTQ3ZDIyYjk4MjQ1YzVmYjkyMzk5Njg2ZTg0YTk1YzE3NDRk
|
15
|
+
NTY0NDY1M2Y2MGY3MjljNjc1ZDdhZTU4NTNlOTQ4MWYzMWE4YTg=
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Sample Usage
|
20
20
|
|
21
|
-
|
21
|
+
### from(subject)
|
22
22
|
|
23
23
|
class AgeLabeler
|
24
24
|
include ActionDirector
|
@@ -36,22 +36,22 @@ Range Conditions:
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
### for(subject, condition)
|
40
40
|
|
41
|
-
class JsonResponseDirector < Struct.new(:
|
41
|
+
class JsonResponseDirector < Struct.new(:controller)
|
42
42
|
include ActionDirector
|
43
43
|
|
44
|
-
def
|
45
|
-
|
46
|
-
with
|
47
|
-
with
|
48
|
-
otherwise
|
44
|
+
def response
|
45
|
+
direct controller do
|
46
|
+
with /fail/ do |resource| render json: resource.errors, status: :unprocessable_entity end
|
47
|
+
with /created/ do |resource| render action: 'show', status: :created, location: resource end
|
48
|
+
otherwise do |resource| head :no_content end
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
def method_missing(method_name, *args, &block)
|
53
53
|
resource = args.first
|
54
|
-
|
54
|
+
response.for resource, method_name
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -18,9 +18,9 @@ module ActionDirector
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def as key, *args # of the eight(8) calling methods, is the most straight forward (direct) way of calling a stored action block
|
21
|
-
stored = actions[key]
|
21
|
+
stored = actions[key]
|
22
22
|
if stored
|
23
|
-
stored.call *args
|
23
|
+
stored.call *args
|
24
24
|
else
|
25
25
|
raise ArgumentError, "#{key.inspect}:#{key.class} did not match any condition"
|
26
26
|
end
|
@@ -31,27 +31,27 @@ module ActionDirector
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def of key, subject # passes the subject with the key
|
34
|
-
as key, subject, key
|
34
|
+
as key, subject, key
|
35
35
|
end
|
36
36
|
|
37
37
|
def from source # matches (keys) and passes the subject (with matching key)
|
38
|
-
of key_like(source), source
|
38
|
+
of key_like(source), source
|
39
39
|
end
|
40
40
|
|
41
41
|
def to destination, *args # matches (keys) and passes the subject (without a key) plus (optional) arguments
|
42
42
|
alike destination, destination, *args
|
43
43
|
end
|
44
44
|
|
45
|
-
def for subject, condition # evaluates second argument (condition) instead of the first (subject)
|
46
|
-
alike condition, subject, condition
|
45
|
+
def for subject, condition # evaluates second argument (condition) instead of the first (subject)
|
46
|
+
alike condition, subject, condition
|
47
47
|
end
|
48
48
|
|
49
|
-
def like so, &block # matches and passes the subject (so)
|
50
|
-
alike so, so, block
|
49
|
+
def like so, &block # matches and passes the subject (so), accepts only one (1) argument (so)
|
50
|
+
alike so, so, block
|
51
51
|
end
|
52
52
|
|
53
|
-
def alike so, *args # derives a key from the subject (so), only passes succeeding arguments (args)
|
54
|
-
as key_like(so), *args
|
53
|
+
def alike so, *args # derives a key from the subject (so), only passes succeeding arguments (args), similar to as() method, passing no key they are alike :P
|
54
|
+
as key_like(so), *args
|
55
55
|
end
|
56
56
|
|
57
57
|
def conditions # list block keys
|
data/test/lookup_test.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LookupTest < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@directive = ActionDirector::Directive.new().setup do
|
6
|
+
with :ok do 'OK' end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_lookup_is_a_proc
|
11
|
+
assert_equal @directive[:ok].class, Proc
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_lookup_and_call_ok
|
15
|
+
assert_equal @directive[:ok].call, 'OK'
|
16
|
+
end
|
17
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_director
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ritchie Paul Buitre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/action_director/directive.rb
|
101
101
|
- lib/action_director/version.rb
|
102
102
|
- test/directive_test.rb
|
103
|
+
- test/lookup_test.rb
|
103
104
|
- test/test_directive_from.rb
|
104
105
|
- test/test_helper.rb
|
105
106
|
homepage: https://github.com/RichOrElse/action-director
|
@@ -129,6 +130,7 @@ summary: You can think of it as either a router for your objects, or as a rapid
|
|
129
130
|
toolset.
|
130
131
|
test_files:
|
131
132
|
- test/directive_test.rb
|
133
|
+
- test/lookup_test.rb
|
132
134
|
- test/test_directive_from.rb
|
133
135
|
- test/test_helper.rb
|
134
136
|
has_rdoc:
|