pragma-operation 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
  SHA1:
3
- metadata.gz: dd7b34ba403c8aad5674258122033c1792ebf363
4
- data.tar.gz: 488a5d9a12741ba168620bd8100a27eca403f96e
3
+ metadata.gz: a0e4b70a6dbf00fc017919c4a20a4fcab1314caf
4
+ data.tar.gz: 10bd799eabb43d6f76a9d29f80a737df2c2902e0
5
5
  SHA512:
6
- metadata.gz: ade359f43ad4529a9e7715eaec67b4504fea489c78bdd22471d9f8fe311bbf1b164aa2a64d127ddfe415ca18d0db164e80a83ac1b3fc8961e4dfd76fa386accc
7
- data.tar.gz: 2eb8b22c599a80b226730d226073711a52002e0577b35dbefc9c69e8c04c425210743c581a60b43bdf3168daaa18628a7ba923284e539d3588619f5654125936
6
+ metadata.gz: ff8e629a189aa67af574569fbf2fa2db77e65e753d553f4d6ae2fc3d8b892693060a223a0f69a6112f8e9ba6ba0479fc44b77550616a9a97e7567f0565ca36a1
7
+ data.tar.gz: 5db34e59a55d5251eb05d0f33283bb83f26027afe491c8150094076eee53af092f0d20fd0f345381f1dfa7c879643f2e9868611b4f6b0b6cbe0f827a94bd1418
@@ -1,33 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
  module Pragma
3
3
  module Operation
4
+ # Provides integration with {https://github.com/pragmarb/pragma-policy Pragma::Policy}.
5
+ #
6
+ # @author Alessandro Desantis
4
7
  module Authorization
5
8
  def self.included(base)
6
9
  base.extend ClassMethods
7
10
  base.include InstanceMethods
8
11
  end
9
12
 
10
- module ClassMethods
11
- # Sets the contract to use for validating this operation.
13
+ module ClassMethods # :nodoc:
14
+ # Sets the policy to use for authorizing this operation.
12
15
  #
13
- # @param klass [Class] a subclass of +Pragma::Contract::Base+
14
- def contract(klass)
15
- @contract = klass
16
+ # @param klass [Class] a subclass of +Pragma::Policy::Base+
17
+ def policy(klass)
18
+ @policy = klass
16
19
  end
17
20
 
18
- # Builds the contract for the given resource, using the previous defined contract class.
21
+ # Builds the policy for the given user and resource, using the previous defined policy
22
+ # class.
19
23
  #
24
+ # @param user [Object]
20
25
  # @param resource [Object]
21
26
  #
22
- # @return [Pragma::Contract::Base]
27
+ # @return [Pragma::Policy::Base]
23
28
  #
24
- # @see #contract
25
- def build_contract(resource)
26
- @contract.new(resource)
29
+ # @see #policy
30
+ def build_policy(user:, resource:)
31
+ @policy.new(user: user, resource: resource)
27
32
  end
28
33
  end
29
34
 
30
- module InstanceMethods
35
+ module InstanceMethods # :nodoc:
31
36
  # Builds the policy for the current user and the given resource, using the previously
32
37
  # defined policy class.
33
38
  #
@@ -1,35 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
  module Pragma
3
3
  module Operation
4
+ # Provides integration with {https://github.com/pragmarb/pragma-contract Pragma::Contract}.
5
+ #
6
+ # @author Alessandro Desantis
4
7
  module Validation
5
8
  def self.included(base)
6
9
  base.extend ClassMethods
7
10
  base.include InstanceMethods
8
11
  end
9
12
 
10
- module ClassMethods
11
- # Sets the policy to use for authorizing this operation.
13
+ module ClassMethods # :nodoc:
14
+ # Sets the contract to use for validating this operation.
12
15
  #
13
- # @param klass [Class] a subclass of +Pragma::Policy::Base+
14
- def policy(klass)
15
- @policy = klass
16
+ # @param klass [Class] a subclass of +Pragma::Contract::Base+
17
+ def contract(klass)
18
+ @contract = klass
16
19
  end
17
20
 
18
- # Builds the policy for the given user and resource, using the previous defined policy
19
- # class.
21
+ # Builds the contract for the given resource, using the previous defined contract class.
20
22
  #
21
- # @param user [Object]
22
23
  # @param resource [Object]
23
24
  #
24
- # @return [Pragma::Policy::Base]
25
+ # @return [Pragma::Contract::Base]
25
26
  #
26
- # @see #policy
27
- def build_policy(user:, resource:)
28
- @policy.new(user: user, resource: resource)
27
+ # @see #contract
28
+ def build_contract(resource)
29
+ @contract.new(resource)
29
30
  end
30
31
  end
31
32
 
32
- module InstanceMethods
33
+ module InstanceMethods # :nodoc:
33
34
  # Builds the contract for the given resource, using the previously defined contract class.
34
35
  #
35
36
  # This is just an instance-level alias of {.build_contract}. You should use this from inside
@@ -51,11 +52,13 @@ module Pragma
51
52
  #
52
53
  # @return [Boolean] whether the operation is valid
53
54
  def validate(validatable)
55
+ # rubocop:disable Metrics/LineLength
54
56
  contract = if defined?(Pragma::Contract::Base) && validatable.is_a?(Pragma::Contract::Base)
55
57
  validatable
56
58
  else
57
59
  build_contract(validatable)
58
60
  end
61
+ # rubocop:enable Metrics/LineLength
59
62
 
60
63
  contract.validate(params)
61
64
  end
@@ -65,11 +68,13 @@ module Pragma
65
68
  #
66
69
  # @param validatable [Object|Pragma::Contract::Base] contract or resource
67
70
  def validate!(validatable)
71
+ # rubocop:disable Metrics/LineLength
68
72
  contract = if defined?(Pragma::Contract::Base) && validatable.is_a?(Pragma::Contract::Base)
69
73
  validatable
70
74
  else
71
75
  build_contract(validatable)
72
76
  end
77
+ # rubocop:enable Metrics/LineLength
73
78
 
74
79
  return if validate(contract)
75
80
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Pragma
3
3
  module Operation
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pragma-operation
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
  - Alessandro Desantis