cooperator 0.2.5 → 0.3.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 +4 -4
- data/.gitignore +15 -18
- data/README.md +2 -0
- data/lib/cooperator/context.rb +4 -1
- data/lib/cooperator/version.rb +1 -1
- data/lib/cooperator.rb +25 -20
- data/spec/defaults.rb +36 -0
- data/spec/properties.rb +4 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f8e7f8260c6e42ee40c8bd2344548c0c4a09b5c
|
4
|
+
data.tar.gz: 57be298794871256340978b381ef822042b7ec4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef124110fa289b1f2708167d61fe638865bf8aa4797382e1eb6cfbde38f9944a6f4987a6fda1dbadb9e80063400505b58775461f8255c2db8759e2568688d0b7
|
7
|
+
data.tar.gz: 94bad4d5547b40b99819be8dc38cd2ab4c6337cccd0ad8e606f5ebc1bb0efef11edfb30b55be90703065162c53b4f78623230cc2d720453843edb265989f723c
|
data/.gitignore
CHANGED
@@ -1,18 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
+
[](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)
|
data/lib/cooperator/context.rb
CHANGED
@@ -51,7 +51,10 @@ module Cooperator
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def respond_to_missing?(method, private = false)
|
54
|
-
|
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
|
data/lib/cooperator/version.rb
CHANGED
data/lib/cooperator.rb
CHANGED
@@ -15,34 +15,35 @@ module Cooperator
|
|
15
15
|
@_committed ||= []
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
context.send property
|
22
|
-
end
|
18
|
+
def defaults
|
19
|
+
@_defaults ||= {}
|
20
|
+
end
|
23
21
|
|
24
|
-
|
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(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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(
|
43
|
-
|
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
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.
|
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:
|
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.
|
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
|