cooperator 0.2.5 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb6c7e817991eb67a8d46d5b66b56658444b9ad7
4
- data.tar.gz: dc828b0e627ff3203c4b66943f30619ae3a47f22
3
+ metadata.gz: 7f8e7f8260c6e42ee40c8bd2344548c0c4a09b5c
4
+ data.tar.gz: 57be298794871256340978b381ef822042b7ec4a
5
5
  SHA512:
6
- metadata.gz: 8e3a94a307194b45601fd01794a6ab1db0932ae3ae84eed924ed2b0246b07f8c32efd8b568eee03421961e2fa908533f9088e09a59e224148ca35e292e8dbb18
7
- data.tar.gz: 592557aaa4bfa7778c51a75917614eb96009498b93ef25987d81854bd78a0f9b5fe72f182f4807c237dee02e55df85f08a0361fc19128c29c1f6fde35b0f1eb6
6
+ metadata.gz: ef124110fa289b1f2708167d61fe638865bf8aa4797382e1eb6cfbde38f9944a6f4987a6fda1dbadb9e80063400505b58775461f8255c2db8759e2568688d0b7
7
+ data.tar.gz: 94bad4d5547b40b99819be8dc38cd2ab4c6337cccd0ad8e606f5ebc1bb0efef11edfb30b55be90703065162c53b4f78623230cc2d720453843edb265989f723c
data/.gitignore CHANGED
@@ -1,18 +1,15 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .gs
6
- .yardoc
7
- Gemfile.lock
8
- InstalledFiles
9
- _yardoc
10
- coverage
11
- doc/
12
- lib/bundler/man
13
- pkg
14
- rdoc
15
- spec/reports
16
- test/tmp
17
- test/version_tmp
18
- tmp
1
+ /.bundle/
2
+ /.gem/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  Simple cooperative interactors for Ruby
6
6
 
7
+ [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Erol/cooperator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
8
+
7
9
  Inspired by the following:
8
10
 
9
11
  * [LightService](https://github.com/adomokos/light-service) by [Atilla Domokos](https://github.com/adomokos)
@@ -51,7 +51,10 @@ module Cooperator
51
51
  end
52
52
 
53
53
  def respond_to_missing?(method, private = false)
54
- @_attributes.include?(method) || super
54
+ name = String method
55
+ name.gsub!(/=/, '') if name.include? '='
56
+
57
+ @_attributes.include?(:"#{name}") || super
55
58
  end
56
59
  end
57
60
  end
@@ -1,3 +1,3 @@
1
1
  module Cooperator
2
- VERSION = '0.2.5'
2
+ VERSION = '0.3.1'
3
3
  end
data/lib/cooperator.rb CHANGED
@@ -15,34 +15,35 @@ module Cooperator
15
15
  @_committed ||= []
16
16
  end
17
17
 
18
- def expects(*properties)
19
- properties.each do |property|
20
- define_method property do
21
- context.send property
22
- end
18
+ def defaults
19
+ @_defaults ||= {}
20
+ end
23
21
 
24
- expected << property
22
+ def expects(property)
23
+ define_method property do
24
+ context.send property
25
25
  end
26
+
27
+ expected << property
26
28
  end
27
29
 
28
- def accepts(*properties)
29
- properties.each do |property|
30
- define_method property do
31
- if context.include? property
32
- context.send property
33
- else
34
- nil
35
- end
30
+ def accepts(property, default: nil)
31
+ define_method property do
32
+ if context.include? property
33
+ value = context.send property
34
+ value.is_a?(Proc) ? value.call : value
35
+ else
36
+ nil
36
37
  end
37
-
38
- accepted << property
39
38
  end
39
+
40
+ accepted << property
41
+
42
+ defaults[property] = default if default
40
43
  end
41
44
 
42
- def commits(*properties)
43
- properties.each do |property|
44
- committed << property
45
- end
45
+ def commits(property)
46
+ committed << property
46
47
  end
47
48
 
48
49
  def perform(context = {})
@@ -50,6 +51,10 @@ module Cooperator
50
51
  raise Exception, "missing expected property: #{property}" unless context.include? property
51
52
  end
52
53
 
54
+ defaults.each do |property, value|
55
+ context[property] = value unless context.include? property
56
+ end
57
+
53
58
  action = new context
54
59
 
55
60
  catch :_finish do
data/spec/defaults.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'cooperator'
2
+
3
+ class Action
4
+ prepend Cooperator
5
+
6
+ accepts :value, default: 1
7
+ accepts :reference, default: -> { 1 }
8
+
9
+ def perform
10
+ $value = value
11
+ $reference = reference
12
+ end
13
+ end
14
+
15
+ prepare do
16
+ $value = nil
17
+ $reference = nil
18
+ end
19
+
20
+ spec '.accepts allows a default value' do
21
+ Action.perform
22
+
23
+ assert $value, :==, 1
24
+ end
25
+
26
+ spec '.accepts allows a default lambda' do
27
+ Action.perform
28
+
29
+ assert $reference, :==, 1
30
+ end
31
+
32
+ spec 'defaults do not override given properties' do
33
+ Action.perform value: 2
34
+
35
+ assert $value, :==, 2
36
+ end
data/spec/properties.rb CHANGED
@@ -3,8 +3,10 @@ require 'cooperator'
3
3
  class Interactor
4
4
  prepend Cooperator
5
5
 
6
- expects :apple, :banana
7
- accepts :coconut, :durian
6
+ expects :apple
7
+ expects :banana
8
+ accepts :coconut
9
+ accepts :durian
8
10
 
9
11
  commits :fig
10
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cooperator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erol Fornoles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-15 00:00:00.000000000 Z
11
+ date: 2015-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -57,6 +57,7 @@ files:
57
57
  - spec/commit.rb
58
58
  - spec/context.rb
59
59
  - spec/cooperate.rb
60
+ - spec/defaults.rb
60
61
  - spec/failure.rb
61
62
  - spec/perform.rb
62
63
  - spec/predicates.rb
@@ -83,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
84
  version: '0'
84
85
  requirements: []
85
86
  rubyforge_project:
86
- rubygems_version: 2.2.2
87
+ rubygems_version: 2.4.5
87
88
  signing_key:
88
89
  specification_version: 4
89
90
  summary: Simple cooperative interactors for Ruby
@@ -91,6 +92,7 @@ test_files:
91
92
  - spec/commit.rb
92
93
  - spec/context.rb
93
94
  - spec/cooperate.rb
95
+ - spec/defaults.rb
94
96
  - spec/failure.rb
95
97
  - spec/perform.rb
96
98
  - spec/predicates.rb