natural_born_slugger 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Gemfile.lock +53 -0
- data/lib/natural_born_slugger/attribute_composer.rb +15 -7
- data/lib/natural_born_slugger/version.rb +1 -1
- data/spec/natural_born_slugger/attribute_builder_spec.rb +21 -1
- data/spec/support/example.rb +7 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 712e46ba34e1b21b65631322811981931c7e7256
|
4
|
+
data.tar.gz: ae7612996c63070c01f7daaa6ddd9ea4ff00c9c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3b830832ce523e5a201caa51cf3cfb23ae594ce382ce74ac7eda00b8f765f6df7432813301ed034b7fb44e69aafb1c73989c8a606a6eccf3fcac37b29193d8e
|
7
|
+
data.tar.gz: 0a0038a32ab4f63e6167d6e6d3b8de45706a8667fdbf9b2c73b5bca95fe5c51447d52d45a11d83b3ad04307071f925a9856ea9fc34d981594011cfcfff55b379
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
natural_born_slugger (0.2.6)
|
5
|
+
activesupport (>= 3.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (4.0.0)
|
11
|
+
i18n (~> 0.6, >= 0.6.4)
|
12
|
+
minitest (~> 4.2)
|
13
|
+
multi_json (~> 1.3)
|
14
|
+
thread_safe (~> 0.1)
|
15
|
+
tzinfo (~> 0.3.37)
|
16
|
+
atomic (1.1.13)
|
17
|
+
coderay (1.0.9)
|
18
|
+
diff-lcs (1.2.4)
|
19
|
+
i18n (0.6.5)
|
20
|
+
method_source (0.8.2)
|
21
|
+
minitest (4.7.5)
|
22
|
+
multi_json (1.7.9)
|
23
|
+
pry (0.9.12.2)
|
24
|
+
coderay (~> 1.0.5)
|
25
|
+
method_source (~> 0.8)
|
26
|
+
slop (~> 3.4)
|
27
|
+
rake (10.1.0)
|
28
|
+
redcarpet (2.3.0)
|
29
|
+
rspec (2.14.1)
|
30
|
+
rspec-core (~> 2.14.0)
|
31
|
+
rspec-expectations (~> 2.14.0)
|
32
|
+
rspec-mocks (~> 2.14.0)
|
33
|
+
rspec-core (2.14.5)
|
34
|
+
rspec-expectations (2.14.2)
|
35
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
36
|
+
rspec-mocks (2.14.3)
|
37
|
+
slop (3.4.6)
|
38
|
+
thread_safe (0.1.2)
|
39
|
+
atomic
|
40
|
+
tzinfo (0.3.37)
|
41
|
+
yard (0.8.7)
|
42
|
+
|
43
|
+
PLATFORMS
|
44
|
+
ruby
|
45
|
+
|
46
|
+
DEPENDENCIES
|
47
|
+
bundler (~> 1.3)
|
48
|
+
natural_born_slugger!
|
49
|
+
pry
|
50
|
+
rake (~> 10.0)
|
51
|
+
redcarpet (~> 2.2)
|
52
|
+
rspec (~> 2.13)
|
53
|
+
yard (~> 0.8)
|
@@ -90,20 +90,28 @@ module NaturalBornSlugger
|
|
90
90
|
klass.composite_attributes ||= {}
|
91
91
|
klass.composite_attributes[@name] = self
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
composer = self.class.composite_attributes[name]
|
97
|
-
old_value = self.instance_variable_get("@#{name}")
|
98
|
-
new_value = composer.evaluate(self)
|
93
|
+
klass.send :define_method, "update_#{@name}".to_sym do
|
94
|
+
name = __method__.to_s.gsub 'update_', ''
|
95
|
+
new_value = self.class.composite_attributes[name].evaluate(self)
|
99
96
|
if self.respond_to? "#{name}=".to_sym
|
100
97
|
new_value = self.send "#{name}=".to_sym, new_value
|
101
98
|
end
|
102
99
|
self.instance_variable_set("@#{name}", new_value)
|
103
|
-
|
100
|
+
#TODO: What is the fate of callbacks? Should the feature be removed? Potential race condition if the value was mutated by the callback
|
101
|
+
#composer.callback(self, old_value, new_value)
|
104
102
|
new_value
|
105
103
|
end
|
106
104
|
|
105
|
+
# Define instance attribute getter: calls setter
|
106
|
+
klass.send :define_method, @name do
|
107
|
+
name = __method__.to_s
|
108
|
+
if frozen?
|
109
|
+
self.instance_variable_get("@#{name}")
|
110
|
+
else
|
111
|
+
self.send "update_#{name}".to_sym
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
107
115
|
end
|
108
116
|
|
109
117
|
end
|
@@ -56,7 +56,24 @@ describe NaturalBornSlugger::AttributeComposer do
|
|
56
56
|
|
57
57
|
|
58
58
|
context 'instance methods' do
|
59
|
-
|
59
|
+
context '#add_to' do
|
60
|
+
subject (:target) { FreezableObject.new }
|
61
|
+
describe 'an object with a composite attribute' do
|
62
|
+
it 'should have a method named after the composite attribute' do
|
63
|
+
target.respond_to?(:natural_key).should be_true
|
64
|
+
end
|
65
|
+
it 'should have a method used to update the attribute' do
|
66
|
+
target.respond_to?(:update_natural_key).should be_true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
describe 'a frozen object' do
|
70
|
+
it 'should not auto update composite attributes' do
|
71
|
+
target.freeze
|
72
|
+
expect { target }.not_to receive(:update_natural_key)
|
73
|
+
target.natural_key
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
60
77
|
describe '#compose_attribute' do
|
61
78
|
|
62
79
|
end
|
@@ -67,4 +84,7 @@ describe NaturalBornSlugger::AttributeComposer do
|
|
67
84
|
|
68
85
|
end
|
69
86
|
|
87
|
+
|
88
|
+
|
89
|
+
|
70
90
|
end
|
data/spec/support/example.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: natural_born_slugger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Keele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- .gitignore
|
120
120
|
- .rspec
|
121
121
|
- Gemfile
|
122
|
+
- Gemfile.lock
|
122
123
|
- LICENSE.md
|
123
124
|
- README.md
|
124
125
|
- Rakefile
|
@@ -170,3 +171,4 @@ test_files:
|
|
170
171
|
- spec/natural_born_slugger_spec.rb
|
171
172
|
- spec/spec_helper.rb
|
172
173
|
- spec/support/example.rb
|
174
|
+
has_rdoc:
|