granite 0.9.6 → 0.9.7
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 +4 -4
- data/lib/granite/action.rb +1 -0
- data/lib/granite/action/precondition.rb +38 -0
- data/lib/granite/action/preconditions.rb +8 -1
- data/lib/granite/action/preconditions/object_precondition.rb +15 -0
- data/lib/granite/represents/attribute.rb +1 -3
- data/lib/granite/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b29f40ab453a5dccfe51b587a3bb8ac106441393110a34853aa7d6319a52dc8
|
4
|
+
data.tar.gz: 7670225bab82074b188a5ec72222a3986da4da217f2268473f3881f5487fb3ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 127fb08af9bb0a97162650884ed9f7b82793db3963fa236a35b9ed1c4cd859cf3a030743eac7bf25ac7845838b61da42bc588d3baad3aa5919e5a8ef495bdb14
|
7
|
+
data.tar.gz: 5a9f6d3bd77cad622f2216706b46e413ed8263b960cd34eb5726c7cc3dc236910aa707acfa2e77df732cd15120be7774ff87261b3854bac8f65e1782096440a0
|
data/lib/granite/action.rb
CHANGED
@@ -7,6 +7,7 @@ require 'granite/action/types'
|
|
7
7
|
require 'granite/action/error'
|
8
8
|
require 'granite/action/performing'
|
9
9
|
require 'granite/action/performer'
|
10
|
+
require 'granite/action/precondition'
|
10
11
|
require 'granite/action/preconditions'
|
11
12
|
require 'granite/action/policies'
|
12
13
|
require 'granite/action/projectors'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Granite
|
2
|
+
class Action
|
3
|
+
class Precondition < BasicObject
|
4
|
+
UNDEFINED = ::Object.new.freeze
|
5
|
+
|
6
|
+
def self.description(text = UNDEFINED)
|
7
|
+
case text
|
8
|
+
when UNDEFINED
|
9
|
+
@description
|
10
|
+
else
|
11
|
+
@description = text
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(context)
|
16
|
+
@context = context
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(*)
|
20
|
+
fail NotImplementedError, "#call method must be implemented for #{self.class}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_missing(method_name, *args, &blk)
|
24
|
+
super unless @context.respond_to?(method_name)
|
25
|
+
|
26
|
+
@context.__send__(method_name, *args, &blk)
|
27
|
+
end
|
28
|
+
|
29
|
+
def respond_to_missing?(method_name, _include_private = false)
|
30
|
+
@context.respond_to?(method_name)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
attr_reader :context
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'granite/action/preconditions/base_precondition'
|
2
2
|
require 'granite/action/preconditions/embedded_precondition'
|
3
|
+
require 'granite/action/preconditions/object_precondition'
|
3
4
|
|
4
5
|
module Granite
|
5
6
|
class Action
|
@@ -13,6 +14,10 @@ module Granite
|
|
13
14
|
extend ActiveSupport::Concern
|
14
15
|
|
15
16
|
class PreconditionsCollection
|
17
|
+
include Enumerable
|
18
|
+
|
19
|
+
delegate :each, to: :@preconditions
|
20
|
+
|
16
21
|
def initialize(*preconditions)
|
17
22
|
@preconditions = preconditions.flatten
|
18
23
|
end
|
@@ -43,8 +48,10 @@ module Granite
|
|
43
48
|
options = args.extract_options!
|
44
49
|
if block
|
45
50
|
add_precondition(BasePrecondition, options, &block)
|
51
|
+
elsif args.first.is_a?(Class)
|
52
|
+
add_precondition(ObjectPrecondition, *args, options)
|
46
53
|
else
|
47
|
-
common_options = options.extract!(:if, :unless)
|
54
|
+
common_options = options.extract!(:if, :unless, :desc, :description)
|
48
55
|
args.each do |type|
|
49
56
|
precondition common_options.merge(type => {})
|
50
57
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'granite/action/preconditions/base_precondition'
|
2
|
+
|
3
|
+
module Granite
|
4
|
+
class Action
|
5
|
+
module Preconditions
|
6
|
+
class ObjectPrecondition < BasePrecondition
|
7
|
+
private
|
8
|
+
|
9
|
+
def _execute(context)
|
10
|
+
@args.first.new(context).call(**@options.except(:if, :unless))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/granite/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: granite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkadiy Zabazhanov & friends
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -320,9 +320,11 @@ files:
|
|
320
320
|
- lib/granite/action/policies/always_allow_strategy.rb
|
321
321
|
- lib/granite/action/policies/any_strategy.rb
|
322
322
|
- lib/granite/action/policies/required_performer_strategy.rb
|
323
|
+
- lib/granite/action/precondition.rb
|
323
324
|
- lib/granite/action/preconditions.rb
|
324
325
|
- lib/granite/action/preconditions/base_precondition.rb
|
325
326
|
- lib/granite/action/preconditions/embedded_precondition.rb
|
327
|
+
- lib/granite/action/preconditions/object_precondition.rb
|
326
328
|
- lib/granite/action/projectors.rb
|
327
329
|
- lib/granite/action/subject.rb
|
328
330
|
- lib/granite/action/transaction.rb
|
@@ -386,7 +388,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
386
388
|
- !ruby/object:Gem::Version
|
387
389
|
version: '0'
|
388
390
|
requirements: []
|
389
|
-
rubygems_version: 3.0.
|
391
|
+
rubygems_version: 3.0.9
|
390
392
|
signing_key:
|
391
393
|
specification_version: 4
|
392
394
|
summary: Another business actions architecture for Rails apps
|