cooperator 0.3.1 → 0.3.2

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: 7f8e7f8260c6e42ee40c8bd2344548c0c4a09b5c
4
- data.tar.gz: 57be298794871256340978b381ef822042b7ec4a
3
+ metadata.gz: db8f2410933f1cf1969814e8107a13a1ec91da44
4
+ data.tar.gz: 76df18d6692bce61623fd4ecbaf8569174e71afa
5
5
  SHA512:
6
- metadata.gz: ef124110fa289b1f2708167d61fe638865bf8aa4797382e1eb6cfbde38f9944a6f4987a6fda1dbadb9e80063400505b58775461f8255c2db8759e2568688d0b7
7
- data.tar.gz: 94bad4d5547b40b99819be8dc38cd2ab4c6337cccd0ad8e606f5ebc1bb0efef11edfb30b55be90703065162c53b4f78623230cc2d720453843edb265989f723c
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
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency 'bundler', "~> 1.5"
22
22
  spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'benchmark-ips'
23
24
  end
@@ -4,7 +4,7 @@ module Cooperator
4
4
  @_attributes = {_failure: false}
5
5
 
6
6
  attributes.each do |k, v|
7
- send :"#{k}=", v
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._failure = false
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._failure = true
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
- return @_attributes.fetch method if @_attributes.include? method
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
@@ -1,3 +1,3 @@
1
1
  module Cooperator
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
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.send property
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.send property
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.send :"#{key}=", value
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.1
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-17 00:00:00.000000000 Z
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.5
102
+ rubygems_version: 2.4.6
88
103
  signing_key:
89
104
  specification_version: 4
90
105
  summary: Simple cooperative interactors for Ruby