cooperator 0.3.1 → 0.3.2
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/benchmarks/context.rb +16 -0
- data/cooperator.gemspec +1 -0
- data/lib/cooperator/context.rb +20 -5
- data/lib/cooperator/version.rb +1 -1
- data/lib/cooperator.rb +3 -3
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db8f2410933f1cf1969814e8107a13a1ec91da44
|
4
|
+
data.tar.gz: 76df18d6692bce61623fd4ecbaf8569174e71afa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0e466bbe36fd11200b932bd45713a316d1efa3e6ded2159d17ccc5a88c597be182d1593119a4e4e7da8be993faa7ad3c008f5ca702754004623eb3c054bbf2b
|
7
|
+
data.tar.gz: b399ce428ce275014a53df3345ffc2e405d2dd410b6b270a2fb5d0599b82da6f5718a8d1a49c507be34ef0d86fdd2bd6052690141ddb06d3b4cc569c107fe5ac
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'benchmark/ips'
|
2
|
+
require 'cooperator'
|
3
|
+
|
4
|
+
context = Cooperator::Context.new value: 1
|
5
|
+
|
6
|
+
Benchmark.ips do |bm|
|
7
|
+
bm.report '#method_missing' do
|
8
|
+
context.value
|
9
|
+
end
|
10
|
+
|
11
|
+
bm.report '#[]' do
|
12
|
+
context[:value]
|
13
|
+
end
|
14
|
+
|
15
|
+
bm.compare!
|
16
|
+
end
|
data/cooperator.gemspec
CHANGED
data/lib/cooperator/context.rb
CHANGED
@@ -4,7 +4,7 @@ module Cooperator
|
|
4
4
|
@_attributes = {_failure: false}
|
5
5
|
|
6
6
|
attributes.each do |k, v|
|
7
|
-
|
7
|
+
self[k] = v
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -13,7 +13,7 @@ module Cooperator
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def success!
|
16
|
-
self
|
16
|
+
self[:_failure] = false
|
17
17
|
end
|
18
18
|
|
19
19
|
def failure!(messages = {})
|
@@ -21,7 +21,7 @@ module Cooperator
|
|
21
21
|
errors[key].push message
|
22
22
|
end
|
23
23
|
|
24
|
-
self
|
24
|
+
self[:_failure] = true
|
25
25
|
end
|
26
26
|
|
27
27
|
def success?
|
@@ -29,19 +29,34 @@ module Cooperator
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def failure?
|
32
|
-
_failure
|
32
|
+
self[:_failure]
|
33
33
|
end
|
34
34
|
|
35
35
|
def include?(key)
|
36
36
|
@_attributes.include? key
|
37
37
|
end
|
38
38
|
|
39
|
+
def []=(key, value)
|
40
|
+
@_attributes[key] = value
|
41
|
+
end
|
42
|
+
|
43
|
+
def [](key)
|
44
|
+
@_attributes[key]
|
45
|
+
end
|
46
|
+
|
39
47
|
def method_missing(method, *args, &block)
|
40
|
-
|
48
|
+
if @_attributes.include? method
|
49
|
+
puts Kernel.caller.first
|
50
|
+
warn '[DEPRECATED] Cooperator::Context: Use hash-style accessors instead of methods.'
|
51
|
+
|
52
|
+
return @_attributes.fetch method
|
53
|
+
end
|
41
54
|
|
42
55
|
name = String method
|
43
56
|
|
44
57
|
if name.include? '='
|
58
|
+
warn '[DEPRECATED] Cooperator::Context: Use hash-style accessors instead of methods.'
|
59
|
+
|
45
60
|
name.gsub!(/=/, '')
|
46
61
|
|
47
62
|
@_attributes[:"#{name}"] = args.shift
|
data/lib/cooperator/version.rb
CHANGED
data/lib/cooperator.rb
CHANGED
@@ -21,7 +21,7 @@ module Cooperator
|
|
21
21
|
|
22
22
|
def expects(property)
|
23
23
|
define_method property do
|
24
|
-
context
|
24
|
+
context[property]
|
25
25
|
end
|
26
26
|
|
27
27
|
expected << property
|
@@ -30,7 +30,7 @@ module Cooperator
|
|
30
30
|
def accepts(property, default: nil)
|
31
31
|
define_method property do
|
32
32
|
if context.include? property
|
33
|
-
value = context
|
33
|
+
value = context[property]
|
34
34
|
value.is_a?(Proc) ? value.call : value
|
35
35
|
else
|
36
36
|
nil
|
@@ -111,7 +111,7 @@ module Cooperator
|
|
111
111
|
|
112
112
|
def commit(properties = {})
|
113
113
|
properties.each do |key, value|
|
114
|
-
context
|
114
|
+
context[key] = value
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erol Fornoles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: benchmark-ips
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: Simple cooperative interactors for Ruby
|
42
56
|
email:
|
43
57
|
- erol.fornoles@gmail.com
|
@@ -50,6 +64,7 @@ files:
|
|
50
64
|
- LICENSE.txt
|
51
65
|
- README.md
|
52
66
|
- Rakefile
|
67
|
+
- benchmarks/context.rb
|
53
68
|
- cooperator.gemspec
|
54
69
|
- lib/cooperator.rb
|
55
70
|
- lib/cooperator/context.rb
|
@@ -84,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
99
|
version: '0'
|
85
100
|
requirements: []
|
86
101
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.4.
|
102
|
+
rubygems_version: 2.4.6
|
88
103
|
signing_key:
|
89
104
|
specification_version: 4
|
90
105
|
summary: Simple cooperative interactors for Ruby
|