policy_check 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +22 -1
- data/lib/policy_check/error.rb +1 -1
- data/lib/policy_check/error_list.rb +3 -3
- data/lib/policy_check/module_builder.rb +1 -0
- data/lib/policy_check/version.rb +1 -1
- data/lib/policy_check.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4b25415b61494e375278f7c2279d387004e91120f2331bb4553614a26857bd3
|
4
|
+
data.tar.gz: 4ba22e0be2d3f2e43a356259ad2398df00622e8ab233e1eb6df6820e9f75b316
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 571ee7602757f70b7e635497a50dd44211ac5342a115120f39ecfa1e6ec3861efba4797b36f1d5ebdac15a2d982f41fde9c741b5369936ff801d56794ea9f069
|
7
|
+
data.tar.gz: cff979634a25bed373743eadc0ee8519dfd43410ae6f96b0cffaecb2412e222030d81ac105aacc2b0ff2782d650ccc03afc11d8de0e327a6010c7bd568b4c3df
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -83,11 +83,32 @@ end
|
|
83
83
|
|
84
84
|
post = Post.find(1)
|
85
85
|
user = current_user
|
86
|
-
PostPublishablePolicy.new(post, user).error_messages #=> ["body is empty", "
|
86
|
+
PostPublishablePolicy.new(post, user).error_messages #=> ["body is empty", "user is not admin"]
|
87
87
|
PostPublishablePolicy.new(post, user).valid? #=> false
|
88
88
|
PostPublishablePolicy.new(post, user).invalid? #=> true
|
89
89
|
```
|
90
90
|
|
91
|
+
## Compatibility
|
92
|
+
|
93
|
+
PolicyCheck officially supports the following runtime Ruby implementations:
|
94
|
+
|
95
|
+
- MRI 2.7, 3.0, 3.1, 3.2
|
96
|
+
|
97
|
+
## Development
|
98
|
+
|
99
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
100
|
+
Then, run `bundle exec rspec` to run the tests.
|
101
|
+
Before committing, run `bundle exec rubocop` to perform a style check.
|
102
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
103
|
+
|
104
|
+
## Contribution
|
105
|
+
|
106
|
+
1. Fork it ( https://github.com/hazi/policy_check/fork )
|
107
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
108
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
109
|
+
4. Push to the branch (git push origin my-new-feature)
|
110
|
+
5. Create new Pull Request
|
111
|
+
|
91
112
|
## License
|
92
113
|
|
93
114
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/policy_check/error.rb
CHANGED
@@ -3,12 +3,13 @@
|
|
3
3
|
require "policy_check/error"
|
4
4
|
|
5
5
|
module PolicyCheck
|
6
|
-
#
|
6
|
+
# A model that summarizes the errors defined in the {PolicyCheck#policy} block
|
7
7
|
class ErrorList
|
8
8
|
def initialize(model, &block)
|
9
9
|
@model = model
|
10
10
|
@block = block
|
11
|
-
@errors =
|
11
|
+
@errors = []
|
12
|
+
instance_eval(&block)
|
12
13
|
end
|
13
14
|
|
14
15
|
# @return [Boolean] true if all errors are false
|
@@ -27,7 +28,6 @@ module PolicyCheck
|
|
27
28
|
|
28
29
|
# called when a policy is defined
|
29
30
|
def error(message, &block)
|
30
|
-
@errors ||= []
|
31
31
|
@errors << Error.new(model, message, &block)
|
32
32
|
end
|
33
33
|
end
|
@@ -5,6 +5,7 @@ require "policy_check/error_list"
|
|
5
5
|
module PolicyCheck
|
6
6
|
# Module Builder to define methods to make decisions
|
7
7
|
class ModuleBuilder < Module
|
8
|
+
# {PolicyCheck#policy} method will call this method to create a ModuleBuilder instance
|
8
9
|
def initialize(name, &block) # rubocop:disable Lint/MissingSuper, Metrics/MethodLength
|
9
10
|
define_method name ? "#{name}?" : "valid?" do
|
10
11
|
errors = ErrorList.new(self, &block)
|
data/lib/policy_check/version.rb
CHANGED
data/lib/policy_check.rb
CHANGED
@@ -25,9 +25,9 @@ require "policy_check/module_builder"
|
|
25
25
|
# end
|
26
26
|
# end
|
27
27
|
module PolicyCheck
|
28
|
+
# If a name is specified "#\\{name}?" and "#\\{name}_errors" method are added.
|
29
|
+
# if name is `nil`, add `#error_messages`, `#valid?` and `#invalid?` method
|
28
30
|
# @param [#to_sym] name policy name, default is `nil`.
|
29
|
-
# If a name is specified "#{name}?" and "#{name}_errors" method are added.
|
30
|
-
# if `nil`, add `#error_messages`, `#valid?` and `#invalid?` method
|
31
31
|
def policy(name = nil, &block)
|
32
32
|
name = name&.to_sym
|
33
33
|
class_exec { include PolicyCheck::ModuleBuilder.new(name, &block) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: policy_check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HAZI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|