granite 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cb39340bc7582c4c2bd15f433b4b5a302fb8abd65ed67b3b9fe8694700aacbf
4
- data.tar.gz: 7e2661a4e5dc42b9297839584037517bdf6913c7166d38d33c476d34fcec31da
3
+ metadata.gz: 3b29f40ab453a5dccfe51b587a3bb8ac106441393110a34853aa7d6319a52dc8
4
+ data.tar.gz: 7670225bab82074b188a5ec72222a3986da4da217f2268473f3881f5487fb3ed
5
5
  SHA512:
6
- metadata.gz: e1444bfa33f9a15bf12d09674229237c3581e1d1de5b2b6542cdcaae8f103cf5894599869355f755bb89f382e94c5288d599c71cf0a8621d6af4395048cb1cad
7
- data.tar.gz: f5046370937087af98cb86f29fe066ec5ec7c265c9e50c0a52b506556dfb13f6921aadaffd8e7f6004fa40ab809fc63371304650e9866fe27b112d6f8c3686ae
6
+ metadata.gz: 127fb08af9bb0a97162650884ed9f7b82793db3963fa236a35b9ed1c4cd859cf3a030743eac7bf25ac7845838b61da42bc588d3baad3aa5919e5a8ef495bdb14
7
+ data.tar.gz: 5a9f6d3bd77cad622f2216706b46e413ed8263b960cd34eb5726c7cc3dc236910aa707acfa2e77df732cd15120be7774ff87261b3854bac8f65e1782096440a0
@@ -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
@@ -11,9 +11,7 @@ module Granite
11
11
  end
12
12
 
13
13
  def sync
14
- return if reference.nil?
15
-
16
- reference.public_send(writer, read)
14
+ reference.public_send(writer, read) if reference.respond_to?(writer)
17
15
  end
18
16
 
19
17
  def typecast(value)
@@ -1,3 +1,3 @@
1
1
  module Granite
2
- VERSION = '0.9.6'.freeze
2
+ VERSION = '0.9.7'.freeze
3
3
  end
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.6
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: 2020-03-05 00:00:00.000000000 Z
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.3
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