agrippa 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/Guardfile +7 -0
- data/LICENSE.txt +202 -0
- data/README.md +186 -0
- data/Rakefile +13 -0
- data/agrippa.gemspec +28 -0
- data/lib/agrippa.rb +10 -0
- data/lib/agrippa/accessor_methods.rb +28 -0
- data/lib/agrippa/delegation.rb +67 -0
- data/lib/agrippa/immutable.rb +80 -0
- data/lib/agrippa/maybe.rb +18 -0
- data/lib/agrippa/methods.rb +52 -0
- data/lib/agrippa/mutable.rb +62 -0
- data/lib/agrippa/mutable_hash.rb +72 -0
- data/lib/agrippa/proxy.rb +77 -0
- data/lib/agrippa/state.rb +12 -0
- data/lib/agrippa/utilities.rb +12 -0
- data/lib/agrippa/version.rb +3 -0
- data/spec/delegation_spec.rb +146 -0
- data/spec/immutable_spec.rb +23 -0
- data/spec/maybe_spec.rb +32 -0
- data/spec/methods_spec.rb +38 -0
- data/spec/mutable_hash_spec.rb +14 -0
- data/spec/mutable_spec.rb +14 -0
- data/spec/object_state_spec.rb +38 -0
- data/spec/proxy_spec.rb +107 -0
- data/spec/shared/state_container_examples.rb +150 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/state_spec.rb +17 -0
- data/spec/utilities_spec.rb +21 -0
- metadata +225 -0
@@ -0,0 +1,150 @@
|
|
1
|
+
RSpec.shared_examples_for "a state container" do
|
2
|
+
let(:random_value) { Object.new }
|
3
|
+
|
4
|
+
let(:instance) { klass.new }
|
5
|
+
|
6
|
+
describe "#new" do
|
7
|
+
it "empty" do
|
8
|
+
expect { klass.new }.to_not raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it "hash" do
|
12
|
+
expect { klass.new(a: random_value, "b" => 2) }.to_not raise_error
|
13
|
+
end
|
14
|
+
|
15
|
+
it "otherwise explodes" do
|
16
|
+
expect { klass.new(42) }.to raise_error(ArgumentError)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".state_reader" do
|
21
|
+
it "returns a value" do
|
22
|
+
klass.state_reader :a
|
23
|
+
expect(instance).to respond_to(:a)
|
24
|
+
expect(instance.a).to be(nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "not command method" do
|
28
|
+
klass.state_reader :a
|
29
|
+
expect(klass.command_method?(:a)).to_not be(true)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "prefix" do
|
33
|
+
klass.state_reader :a, prefix: "foo"
|
34
|
+
expect(instance).to respond_to(:foo_a)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "suffix" do
|
38
|
+
klass.state_reader :a, suffix: "foo"
|
39
|
+
expect(instance).to respond_to(:a_foo)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe ".state_writer" do
|
44
|
+
it "chainable" do
|
45
|
+
klass.state_writer :a
|
46
|
+
expect(instance).to respond_to(:set_a)
|
47
|
+
expect(instance.set_a(:value)).to be_a(klass)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "command method" do
|
51
|
+
klass.state_writer :a
|
52
|
+
expect(klass.command_method?(:set_a)).to be(true)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "prefix" do
|
56
|
+
klass.state_writer :a, prefix: "foo"
|
57
|
+
expect(instance).to respond_to(:set_foo_a)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "no prefix" do
|
61
|
+
klass.state_writer :a, prefix: false
|
62
|
+
expect(instance).to respond_to(:a)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "suffix" do
|
66
|
+
klass.state_writer :a, suffix: "foo"
|
67
|
+
expect(instance).to respond_to(:set_a_foo)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it ".state_accessor builds both" do
|
72
|
+
klass.state_accessor :a
|
73
|
+
expect(instance).to respond_to(:a)
|
74
|
+
expect(instance).to respond_to(:set_a)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "reader returns a value" do
|
78
|
+
klass.state_accessor :a
|
79
|
+
instance = klass.new(a: random_value)
|
80
|
+
expect(instance.a).to be(random_value)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "writer sets a value" do
|
84
|
+
klass.state_accessor :a
|
85
|
+
expect(instance.set_a(2).a).to eq(2)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "#chain command method" do
|
89
|
+
expect(klass.command_method?(:chain)).to be(true)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "#chain sets multiple values" do
|
93
|
+
klass.state_accessor :a, :b
|
94
|
+
updated = instance.chain(a: random_value, b: 2)
|
95
|
+
expect(updated).to be_a(klass)
|
96
|
+
expect(updated.a).to be(random_value)
|
97
|
+
expect(updated.b).to eq(2)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "#store" do
|
101
|
+
klass.state_accessor :a
|
102
|
+
updated = instance.store(:a, random_value)
|
103
|
+
expect(updated).to be_a(klass)
|
104
|
+
expect(updated.a).to be(random_value)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "#store indifferent on symbols and strings" do
|
108
|
+
klass.state_accessor :a, :b
|
109
|
+
expect(instance.store(:a, 1).a).to eq(1)
|
110
|
+
expect(instance.store("b", 2).b).to eq(2)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "#store command method" do
|
114
|
+
expect(klass.command_method?(:store)).to be(true)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "#fetch" do
|
118
|
+
klass.state_accessor :a
|
119
|
+
expect(instance.store(:a, random_value).fetch(:a)).to be(random_value)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "#fetch default" do
|
123
|
+
klass.state_accessor :a
|
124
|
+
expect(instance.fetch(:a, random_value)).to be(random_value)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "#fetch not command method" do
|
128
|
+
expect(klass.command_method?(:fetch)).to be(false)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "#fetch indifferent on symbols and strings" do
|
132
|
+
updated = instance.store(:a, 1)
|
133
|
+
expect(updated.fetch(:a)).to eq(1)
|
134
|
+
expect(updated.fetch("a")).to eq(1)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "#default_state" do
|
138
|
+
klass.state_accessor :a
|
139
|
+
klass.send(:define_method, :default_state) { { a: "default" } }
|
140
|
+
expect(instance.a).to eq("default")
|
141
|
+
end
|
142
|
+
|
143
|
+
it "#default_state and new(state)" do
|
144
|
+
klass.state_accessor :a, :b
|
145
|
+
klass.send(:define_method, :default_state) { { a: 1 } }
|
146
|
+
instance = klass.new(b: 2)
|
147
|
+
expect(instance.a).to eq(1)
|
148
|
+
expect(instance.b).to eq(2)
|
149
|
+
end
|
150
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
root = File.join(File.dirname(File.expand_path(__FILE__)), "..")
|
2
|
+
$LOAD_PATH.unshift(root) unless $LOAD_PATH.include?(root)
|
3
|
+
|
4
|
+
require "simplecov"
|
5
|
+
|
6
|
+
SimpleCov.start do
|
7
|
+
add_filter "/spec/"
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.filter_run(:focus)
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.order = :random
|
14
|
+
config.default_formatter = "doc" if config.files_to_run.one?
|
15
|
+
Kernel.srand(config.seed)
|
16
|
+
|
17
|
+
config.expect_with :rspec do |expectations|
|
18
|
+
expectations.syntax = :expect
|
19
|
+
end
|
20
|
+
|
21
|
+
config.mock_with :rspec do |mocks|
|
22
|
+
mocks.syntax = :expect
|
23
|
+
mocks.verify_partial_doubles = true
|
24
|
+
end
|
25
|
+
end
|
data/spec/state_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "agrippa/state"
|
3
|
+
|
4
|
+
RSpec.describe Agrippa::State do
|
5
|
+
it "command methods update" do
|
6
|
+
value = double(ping: "pong", :command_method? => true)
|
7
|
+
proxy = Agrippa::State.new(value)
|
8
|
+
expect(proxy.ping.__id__).to eq(proxy.__id__)
|
9
|
+
expect(proxy._value).to eq("pong")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "query methods return" do
|
13
|
+
value = double(ping: "pong", :command_method? => false)
|
14
|
+
proxy = Agrippa::State.new(value, :ping)
|
15
|
+
expect(proxy.ping).to eq("pong")
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "agrippa"
|
3
|
+
|
4
|
+
RSpec.describe Agrippa::Utilities do
|
5
|
+
def try_require(*args)
|
6
|
+
Agrippa::Utilities.try_require(*args)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "#try_require success" do
|
10
|
+
expect { try_require("securerandom") }.to_not raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it "#try_require fail" do
|
14
|
+
expect { try_require("totallynotagem") }.to_not raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it "#try_require fail message" do
|
18
|
+
expect { try_require("totallynotagem", "XXX") }
|
19
|
+
.to raise_error(LoadError, /XXX/)
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: agrippa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Don Werve
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 3.0.0
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '3.0'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.0.0
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: guard
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.8'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2.8'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: guard-rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '4.3'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '4.3'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: ruby_gntp
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: simplecov
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: pry
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: hamster
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '1.0'
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 1.0.0
|
141
|
+
type: :development
|
142
|
+
prerelease: false
|
143
|
+
version_requirements: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - "~>"
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '1.0'
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 1.0.0
|
151
|
+
description: A small collection of design patterns, codified in a gem for easy reuse.
|
152
|
+
email:
|
153
|
+
- don@werve.net
|
154
|
+
executables: []
|
155
|
+
extensions: []
|
156
|
+
extra_rdoc_files: []
|
157
|
+
files:
|
158
|
+
- ".gitignore"
|
159
|
+
- Gemfile
|
160
|
+
- Guardfile
|
161
|
+
- LICENSE.txt
|
162
|
+
- README.md
|
163
|
+
- Rakefile
|
164
|
+
- agrippa.gemspec
|
165
|
+
- lib/agrippa.rb
|
166
|
+
- lib/agrippa/accessor_methods.rb
|
167
|
+
- lib/agrippa/delegation.rb
|
168
|
+
- lib/agrippa/immutable.rb
|
169
|
+
- lib/agrippa/maybe.rb
|
170
|
+
- lib/agrippa/methods.rb
|
171
|
+
- lib/agrippa/mutable.rb
|
172
|
+
- lib/agrippa/mutable_hash.rb
|
173
|
+
- lib/agrippa/proxy.rb
|
174
|
+
- lib/agrippa/state.rb
|
175
|
+
- lib/agrippa/utilities.rb
|
176
|
+
- lib/agrippa/version.rb
|
177
|
+
- spec/delegation_spec.rb
|
178
|
+
- spec/immutable_spec.rb
|
179
|
+
- spec/maybe_spec.rb
|
180
|
+
- spec/methods_spec.rb
|
181
|
+
- spec/mutable_hash_spec.rb
|
182
|
+
- spec/mutable_spec.rb
|
183
|
+
- spec/object_state_spec.rb
|
184
|
+
- spec/proxy_spec.rb
|
185
|
+
- spec/shared/state_container_examples.rb
|
186
|
+
- spec/spec_helper.rb
|
187
|
+
- spec/state_spec.rb
|
188
|
+
- spec/utilities_spec.rb
|
189
|
+
homepage: https://github.com/mataton/agrippa/
|
190
|
+
licenses:
|
191
|
+
- Apache-2.0
|
192
|
+
metadata: {}
|
193
|
+
post_install_message:
|
194
|
+
rdoc_options: []
|
195
|
+
require_paths:
|
196
|
+
- lib
|
197
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - ">="
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
requirements: []
|
208
|
+
rubyforge_project:
|
209
|
+
rubygems_version: 2.2.2
|
210
|
+
signing_key:
|
211
|
+
specification_version: 4
|
212
|
+
summary: Tools for building better code.
|
213
|
+
test_files:
|
214
|
+
- spec/delegation_spec.rb
|
215
|
+
- spec/immutable_spec.rb
|
216
|
+
- spec/maybe_spec.rb
|
217
|
+
- spec/methods_spec.rb
|
218
|
+
- spec/mutable_hash_spec.rb
|
219
|
+
- spec/mutable_spec.rb
|
220
|
+
- spec/object_state_spec.rb
|
221
|
+
- spec/proxy_spec.rb
|
222
|
+
- spec/shared/state_container_examples.rb
|
223
|
+
- spec/spec_helper.rb
|
224
|
+
- spec/state_spec.rb
|
225
|
+
- spec/utilities_spec.rb
|