policy_check 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a1e72d0560846575b9f7058c0143f736ba327fff679202f6b50630c6cf87907
4
- data.tar.gz: c5dcf2ee63df0890a9ef835109b271b88ff0e8adf4648a98755ff4918e8add81
3
+ metadata.gz: a4b25415b61494e375278f7c2279d387004e91120f2331bb4553614a26857bd3
4
+ data.tar.gz: 4ba22e0be2d3f2e43a356259ad2398df00622e8ab233e1eb6df6820e9f75b316
5
5
  SHA512:
6
- metadata.gz: 3621a014b73eda77689c064437c8fbbd267b05b541c6d2b5516f74f3c0841b86282e0194fb60e74f43ad1509fcb83f419919eef600c0f57641111baaae71e266
7
- data.tar.gz: 3333297547cb1e00b83fb8e4b2d9fba03ca4a00657ea8cc00864a30480374f045ff5d07cffb1db4f26a2e3fd6c4a50c1e39281aadbe4cd1725e2b31cd6957fe5
6
+ metadata.gz: 571ee7602757f70b7e635497a50dd44211ac5342a115120f39ecfa1e6ec3861efba4797b36f1d5ebdac15a2d982f41fde9c741b5369936ff801d56794ea9f069
7
+ data.tar.gz: cff979634a25bed373743eadc0ee8519dfd43410ae6f96b0cffaecb2412e222030d81ac105aacc2b0ff2782d650ccc03afc11d8de0e327a6010c7bd568b4c3df
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- policy_check (0.1.1)
4
+ policy_check (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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", "write is not admin"]
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).
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PolicyCheck
4
- # Determines the error
4
+ # Model representing one error defined in the {PolicyCheck#policy} block
5
5
  class Error
6
6
  def initialize(model, message, &block)
7
7
  @model = model
@@ -3,12 +3,13 @@
3
3
  require "policy_check/error"
4
4
 
5
5
  module PolicyCheck
6
- # Create a summary error model and summarize the decision
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 = instance_eval(&block)
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PolicyCheck
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
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.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-04 00:00:00.000000000 Z
11
+ date: 2023-02-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: