action_director 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTIyNzc4YmQ3MDczZTI2MzAwYWY4ODQ1NjJkMjgzOGJmOWExOThlZA==
4
+ NDhkZjk2NzQzYWZiNWJmNDlhYmQyMjU5MDhhNTkyNDcxMTA3OTAxNA==
5
5
  data.tar.gz: !binary |-
6
- MmI1ZTU5MTY3YWY0MWNhMzYwZTlhNzNkNDhjZDhlYjgxMDI3OWNhYQ==
6
+ NmQ0MzM4Y2FmMDNkNTAwNmZjOTUwNjMxMmExN2Y5ZTkzZmQwOTcxZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2U3NGU2YzUyNTFkN2IxOTNmM2M0NDEyY2JhZjE0M2M0MmJjNWY1YmQ1ODIz
10
- MmQ5MzFlODA5MGVkYWRjMDUxNjNhNTZmMDIzM2Y2NTEyODY1ZDAwNjdlZmFj
11
- M2QzZWJiMDk4ZjFiODRlYjczZGI2YzNiZGU2MTExMWNiNTZmY2M=
9
+ NGUwYTE0ZDc5MWRmYjhlOTAwMjYxNmUzOWE0MDhmZTllODcwMTU2NTViNmFk
10
+ YTM3ZjVhZGIyN2ZjNTU1Nzc0MmY5NDMzNWMyODA1ZTVmZDk3ZGM5MTAwNWNh
11
+ OWMwNjk5MDA1OWIzNDI4ODAzNWJhMDE0MTU4MGU0NzM5MzE3NWU=
12
12
  data.tar.gz: !binary |-
13
- MGZlODAyZjFjOTUyZGFkNTEzOTkzMTMwZTQ1ZGMxOGRkN2IyMTlkM2IyYTli
14
- NjY3NGNmM2ZjYjIyN2JmMTM1NTJkY2E2ZTNjYTkwMjBmZGQ4N2E4ZmM5NzZm
15
- M2VkNTc2NzVkYTgyMDZhMTRkNjI2NGUwYzA1NjI3NjExNmM2MWM=
13
+ MWE0N2MxZjUzOWY5NWYxMzMxMWU4OWVlNjM5MjFhNWE3ODU4ZmRmYmQwNGE4
14
+ MGJiMTFmZGI4ZTQ3ZDIyYjk4MjQ1YzVmYjkyMzk5Njg2ZTg0YTk1YzE3NDRk
15
+ NTY0NDY1M2Y2MGY3MjljNjc1ZDdhZTU4NTNlOTQ4MWYzMWE4YTg=
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
+ - jruby-18mode # JRuby in 1.8 mode
4
5
  - jruby-19mode # JRuby in 1.9 mode
5
6
  - rbx-2.1.1
6
-
7
+ - 1.8.7
data/README.md CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
18
18
 
19
19
  ## Sample Usage
20
20
 
21
- Range Conditions:
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
- Regexp Conditions:
39
+ ### for(subject, condition)
40
40
 
41
- class JsonResponseDirector < Struct.new(:view_context)
41
+ class JsonResponseDirector < Struct.new(:controller)
42
42
  include ActionDirector
43
43
 
44
- def responding
45
- @responding ||= direct view_context do
46
- with /^succeeded_creating/ do |resource| render action: 'show', status: :created, location: resource end
47
- with /^failed/ do |resource| render json: resource.errors, status: :unprocessable_entity end
48
- otherwise do |resource| head :no_content end
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
- responding.for resource, method_name
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] # use one (1) calling method for different directables instead of many on the same directable (Directive)
21
+ stored = actions[key]
22
22
  if stored
23
- stored.call *args # here only the succeeding arguments (args) are passed (excluding key)
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 # accepts only two (2) arguments
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 # accepts only one (1) argument (source), passes two (2) to the block
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), ideal for hash conditions
46
- alike condition, subject, condition # accepts only two (2) arguments and passes both
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 # accepts only one (1) argument (so)
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 # similar to as() method, passing no key they are alike :P
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
@@ -30,6 +30,9 @@ module ActionDirector
30
30
  def recognize? condition
31
31
  key_like(condition) != nil
32
32
  end
33
+
34
+ def [](condition)
35
+ @actions[key_like condition]
36
+ end
33
37
  end
34
38
  end
35
-
@@ -1,3 +1,3 @@
1
1
  module ActionDirector
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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
@@ -1,5 +1,6 @@
1
1
  require 'bundler/setup'
2
2
  require 'action_director'
3
+ require 'minitest'
3
4
  require 'minitest/unit'
4
5
  require 'minitest/autorun'
5
6
  require 'minitest/pride'
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.2
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-03 00:00:00.000000000 Z
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: