attestor 0.1.0 → 0.2.0

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: e5d5fbaf26c97f5c5dd838289b64904714d118b7
4
- data.tar.gz: 777f4abaa5ef17cfe19627cbb69b9e960394a4c7
3
+ metadata.gz: dbf1e027054a7c3baeeaa39f6e66f515e1b3fa2e
4
+ data.tar.gz: 546765bd0a8dfee528fa5ed45f3fe7a3b07047cf
5
5
  SHA512:
6
- metadata.gz: 91138866beb8ef0615181d4ab9c3a9cbad86f3bb2b238b648f155b0b7fea5d6a1b2b48185762e7b5289b66965faa5f7bc9c62c49e85db2705744ae28f4bdfd42
7
- data.tar.gz: 3ff1370688ca7712e5e7fdfad088e8298f73e10a85f17e247923cec2e05ed36f0791604342c1a3ae77c481c9d702710a90861b5d80640b5464910280582072e4
6
+ metadata.gz: bfa470608fa7882248c256abd5e594a7ed4d50cef97fbc230425a89703b1cd6c652586b57a760a76b78b9611a76ad41f0f58eb2573e2e3f50c88f2aabfd903df
7
+ data.tar.gz: 5694b759f83f0b281fc102753dce9537512510157e79a22941fd312d5ed141b7e62e7b1b6072d54035b43995e735b74ce746109acc43c9c5a6197b4553d2ea3c
data/README.md CHANGED
@@ -157,15 +157,11 @@ Policy Objects
157
157
 
158
158
  Extract a validator to the separate object (policy). Basically the policy includes `Attestor::Validations` with additional methods.
159
159
 
160
- ```ruby
161
- class ConsistencyPolicy < Struct.new(:debet, :credit)
162
- include Attestor::Policy # includes Attestor::Validator as well
163
-
164
- validate :consistent
160
+ To create a policy as a `Struct` use the builder method:
165
161
 
166
- private
167
-
168
- def consistent
162
+ ```ruby
163
+ ConsistencyPolicy = Attestor::Policy.new(:debet, :credit) do
164
+ def validate
169
165
  fraud = credit - debet
170
166
  invalid :inconsistent, fraud: fraud if fraud != 0
171
167
  end
@@ -16,6 +16,27 @@ module Attestor
16
16
  end
17
17
  end
18
18
 
19
+ # Builds the policy class
20
+ #
21
+ # @example
22
+ # MyPolicy = Attestor::Policy.new(:foo, :bar) do
23
+ # attr_reader :baz
24
+ # end
25
+ #
26
+ # @attribute [Array<#to_sym>] attributes
27
+ # the list of attributes
28
+ # @attribute [Proc] block
29
+ #
30
+ # @yield the block in the scope of created class
31
+ #
32
+ # @return [Class]
33
+ def self.new(*attributes, &block)
34
+ Struct.new(*attributes) do
35
+ include Attestor::Policy
36
+ instance_eval(&block) if block_given?
37
+ end
38
+ end
39
+
19
40
  # Checks whether the policy is valid
20
41
  #
21
42
  # @return [Boolean]
@@ -4,6 +4,6 @@ module Attestor
4
4
 
5
5
  # The semantic version of the module.
6
6
  # @see http://semver.org/ Semantic versioning 2.0
7
- VERSION = "0.1.0".freeze
7
+ VERSION = "0.2.0".freeze
8
8
 
9
9
  end # module Attestor
@@ -18,6 +18,29 @@ describe Attestor::Policy do
18
18
 
19
19
  describe ".new" do
20
20
 
21
+ let(:build) { described_class.new(:foo) { attr_reader :bar } }
22
+ subject { build.new(:baz) }
23
+
24
+ it "builds the struct" do
25
+ expect(subject).to be_kind_of Struct
26
+ end
27
+
28
+ it "adds given attributes" do
29
+ expect(subject.foo).to eq :baz
30
+ end
31
+
32
+ it "builds the policy" do
33
+ expect(subject).to be_kind_of described_class
34
+ end
35
+
36
+ it "yields the block in class scope" do
37
+ expect(subject).to respond_to :bar
38
+ end
39
+
40
+ end
41
+
42
+ describe ".included" do
43
+
21
44
  it "creates a validator" do
22
45
  expect(subject).to be_kind_of validator
23
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attestor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kozin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-26 00:00:00.000000000 Z
11
+ date: 2015-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: extlib