policy 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.metrics +5 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +2 -0
  6. data/.travis.yml +18 -0
  7. data/.yardopts +3 -0
  8. data/Gemfile +7 -0
  9. data/Guardfile +15 -0
  10. data/LICENSE +21 -0
  11. data/README.md +223 -0
  12. data/Rakefile +17 -0
  13. data/config/metrics/STYLEGUIDE +231 -0
  14. data/config/metrics/cane.yml +5 -0
  15. data/config/metrics/churn.yml +6 -0
  16. data/config/metrics/flay.yml +2 -0
  17. data/config/metrics/metric_fu.yml +14 -0
  18. data/config/metrics/pippi.yml +3 -0
  19. data/config/metrics/reek.yml +1 -0
  20. data/config/metrics/roodi.yml +24 -0
  21. data/config/metrics/rubocop.yml +87 -0
  22. data/config/metrics/saikuro.yml +3 -0
  23. data/config/metrics/simplecov.yml +5 -0
  24. data/config/metrics/yardstick.yml +37 -0
  25. data/lib/policy/follower/followed_policies.rb +45 -0
  26. data/lib/policy/follower/followed_policy.rb +104 -0
  27. data/lib/policy/follower/names.rb +29 -0
  28. data/lib/policy/follower.rb +143 -0
  29. data/lib/policy/interface.rb +48 -0
  30. data/lib/policy/validations.rb +28 -0
  31. data/lib/policy/version.rb +9 -0
  32. data/lib/policy/violation_error.rb +52 -0
  33. data/lib/policy.rb +40 -0
  34. data/policy.gemspec +23 -0
  35. data/spec/features/follower_spec.rb +95 -0
  36. data/spec/spec_helper.rb +10 -0
  37. data/spec/tests/policy/follower/followed_policies_spec.rb +87 -0
  38. data/spec/tests/policy/follower/followed_policy_spec.rb +117 -0
  39. data/spec/tests/policy/follower/names_spec.rb +19 -0
  40. data/spec/tests/policy/follower_spec.rb +220 -0
  41. data/spec/tests/policy/interface_spec.rb +83 -0
  42. data/spec/tests/policy/validations_spec.rb +13 -0
  43. data/spec/tests/policy/violation_error_spec.rb +75 -0
  44. data/spec/tests/policy_spec.rb +35 -0
  45. metadata +142 -0
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+ require "ostruct"
3
+
4
+ describe Policy::ViolationError do
5
+
6
+ # OpenStruct is used instead of double because it should be frozen
7
+ let(:policy) { OpenStruct.new(messages: ["foo"]) }
8
+
9
+ subject { described_class.new policy }
10
+
11
+ describe ".new" do
12
+
13
+ it "takes a policy" do
14
+ expect { described_class.new }.to raise_error ArgumentError
15
+ expect { subject }.not_to raise_error
16
+ end
17
+
18
+ it "is a RuntimeError" do
19
+ expect(subject).to be_kind_of RuntimeError
20
+ end
21
+
22
+ it "is immutable" do
23
+ expect(subject).to be_frozen
24
+ end
25
+
26
+ end # describe .new
27
+
28
+ describe "#policy" do
29
+
30
+ it "returns the policy" do
31
+ expect(subject.policy).to eq policy
32
+ end
33
+
34
+ it "is immutable" do
35
+ expect(subject.policy).to be_frozen
36
+ end
37
+
38
+ it "doesn't freeze the source policy object" do
39
+ subject
40
+ expect(policy).not_to be_frozen
41
+ end
42
+
43
+ end # describe #policy
44
+
45
+ describe "#messages" do
46
+
47
+ it "delegated to the policy" do
48
+ expect(subject.messages).to eq subject.policy.messages
49
+ end
50
+
51
+ it "is immutable" do
52
+ expect(subject.messages).to be_frozen
53
+ end
54
+
55
+ end # describe #messages
56
+
57
+ describe "#inspect" do
58
+
59
+ it "returns a proper text" do
60
+ expect(subject.inspect)
61
+ .to eq "#<Policy::ViolationError: #{ subject.message }>"
62
+ end
63
+
64
+ end # describe #inspect
65
+
66
+ describe "#message" do
67
+
68
+ it "returns a proper text" do
69
+ expect(subject.message)
70
+ .to eq "#{ policy.inspect } violated: #{ subject.messages }"
71
+ end
72
+
73
+ end # describe #message
74
+
75
+ end # describe Policy::ViolationError
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ describe Policy do
4
+
5
+ describe ".new" do
6
+
7
+ subject { described_class.new :debet, :credit }
8
+
9
+ it "builds the Struct" do
10
+ expect(subject.ancestors).to include Struct
11
+ end
12
+
13
+ it "adds required attributes" do
14
+ methods = subject.instance_methods
15
+
16
+ %i(debet debet= credit credit=).each do |method|
17
+ expect(methods).to include method
18
+ end
19
+ end
20
+
21
+ it "includes Policy::Interface" do
22
+ expect(subject).to include(Policy::Interface)
23
+ end
24
+
25
+ end # describe .new
26
+
27
+ describe ".name" do
28
+
29
+ subject { described_class.name }
30
+
31
+ it { is_expected.to eq "Policy" }
32
+
33
+ end
34
+
35
+ end # describe Policy
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: policy
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kozin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: adamantium
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hexx-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ description: A tiny library implementing the Policy Object pattern.
56
+ email: andrew.kozin@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files:
60
+ - README.md
61
+ - LICENSE
62
+ - config/metrics/STYLEGUIDE
63
+ files:
64
+ - ".coveralls.yml"
65
+ - ".metrics"
66
+ - ".rspec"
67
+ - ".rubocop.yml"
68
+ - ".travis.yml"
69
+ - ".yardopts"
70
+ - Gemfile
71
+ - Guardfile
72
+ - LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - config/metrics/STYLEGUIDE
76
+ - config/metrics/cane.yml
77
+ - config/metrics/churn.yml
78
+ - config/metrics/flay.yml
79
+ - config/metrics/metric_fu.yml
80
+ - config/metrics/pippi.yml
81
+ - config/metrics/reek.yml
82
+ - config/metrics/roodi.yml
83
+ - config/metrics/rubocop.yml
84
+ - config/metrics/saikuro.yml
85
+ - config/metrics/simplecov.yml
86
+ - config/metrics/yardstick.yml
87
+ - lib/policy.rb
88
+ - lib/policy/follower.rb
89
+ - lib/policy/follower/followed_policies.rb
90
+ - lib/policy/follower/followed_policy.rb
91
+ - lib/policy/follower/names.rb
92
+ - lib/policy/interface.rb
93
+ - lib/policy/validations.rb
94
+ - lib/policy/version.rb
95
+ - lib/policy/violation_error.rb
96
+ - policy.gemspec
97
+ - spec/features/follower_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/tests/policy/follower/followed_policies_spec.rb
100
+ - spec/tests/policy/follower/followed_policy_spec.rb
101
+ - spec/tests/policy/follower/names_spec.rb
102
+ - spec/tests/policy/follower_spec.rb
103
+ - spec/tests/policy/interface_spec.rb
104
+ - spec/tests/policy/validations_spec.rb
105
+ - spec/tests/policy/violation_error_spec.rb
106
+ - spec/tests/policy_spec.rb
107
+ homepage: https://github.com/nepalez/policy
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.6
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Policy Objects for Ruby.
131
+ test_files:
132
+ - spec/spec_helper.rb
133
+ - spec/tests/policy_spec.rb
134
+ - spec/tests/policy/follower_spec.rb
135
+ - spec/tests/policy/interface_spec.rb
136
+ - spec/tests/policy/validations_spec.rb
137
+ - spec/tests/policy/follower/followed_policies_spec.rb
138
+ - spec/tests/policy/follower/followed_policy_spec.rb
139
+ - spec/tests/policy/follower/names_spec.rb
140
+ - spec/tests/policy/violation_error_spec.rb
141
+ - spec/features/follower_spec.rb
142
+ has_rdoc: