granite 0.9.2 → 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/config/rubocop-default.yml +3 -0
- data/lib/granite/action.rb +1 -0
- data/lib/granite/action/performing.rb +4 -2
- 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/projector/controller_actions.rb +2 -2
- data/lib/granite/represents/attribute.rb +1 -3
- data/lib/granite/version.rb +1 -1
- data/lib/rubocop-granite.rb +8 -0
- data/lib/rubocop/granite.rb +9 -0
- data/lib/rubocop/granite/inject.rb +20 -0
- metadata +55 -18
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'
|
@@ -92,8 +92,10 @@ module Granite
|
|
92
92
|
private
|
93
93
|
|
94
94
|
def perform_action(raise_errors: false, **options)
|
95
|
-
|
96
|
-
|
95
|
+
result = run_callbacks(:execute_perform) do
|
96
|
+
apply_association_changes!
|
97
|
+
execute_perform!(options)
|
98
|
+
end
|
97
99
|
@_action_performed = true
|
98
100
|
result || true
|
99
101
|
rescue *handled_exceptions => e
|
@@ -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
|
@@ -23,11 +23,11 @@ module Granite
|
|
23
23
|
controller_class.__send__(:define_method, name, &block)
|
24
24
|
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
25
25
|
def #{name}_url(options = {})
|
26
|
-
action_url(:#{name}, options)
|
26
|
+
action_url(:#{name}, options.symbolize_keys)
|
27
27
|
end
|
28
28
|
|
29
29
|
def #{name}_path(options = {})
|
30
|
-
action_path(:#{name}, options)
|
30
|
+
action_path(:#{name}, options.symbolize_keys)
|
31
31
|
end
|
32
32
|
METHOD
|
33
33
|
else
|
data/lib/granite/version.rb
CHANGED
@@ -0,0 +1,9 @@
|
|
1
|
+
module RuboCop
|
2
|
+
module Granite
|
3
|
+
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
4
|
+
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'rubocop-default.yml').freeze
|
5
|
+
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
6
|
+
|
7
|
+
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# The original code is from https://github.com/rubocop-hq/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
|
4
|
+
# See https://github.com/rubocop-hq/rubocop-rspec/blob/master/MIT-LICENSE.md
|
5
|
+
module RuboCop
|
6
|
+
module Granite
|
7
|
+
# Because RuboCop doesn't yet support plugins, we have to monkey patch in a
|
8
|
+
# bit of our configuration.
|
9
|
+
module Inject
|
10
|
+
def self.defaults!
|
11
|
+
path = CONFIG_DEFAULT.to_s
|
12
|
+
hash = ConfigLoader.load_file(path)
|
13
|
+
config = Config.new(hash, path).tap(&:make_excludes_absolute)
|
14
|
+
puts "configuration from #{path}" if ConfigLoader.debug?
|
15
|
+
config = ConfigLoader.merge_with_default(config, path)
|
16
|
+
ConfigLoader.instance_variable_set(:@default_configuration, config)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,57 +1,69 @@
|
|
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
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5.1'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6.1'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '5.1'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6.1'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: active_data
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.1.
|
39
|
+
version: 1.1.5
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.1.
|
46
|
+
version: 1.1.5
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: activesupport
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- - "
|
51
|
+
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '5.1'
|
54
|
+
- - "<"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '6.1'
|
48
57
|
type: :runtime
|
49
58
|
prerelease: false
|
50
59
|
version_requirements: !ruby/object:Gem::Requirement
|
51
60
|
requirements:
|
52
|
-
- - "
|
61
|
+
- - ">="
|
53
62
|
- !ruby/object:Gem::Version
|
54
63
|
version: '5.1'
|
64
|
+
- - "<"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '6.1'
|
55
67
|
- !ruby/object:Gem::Dependency
|
56
68
|
name: memoist
|
57
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,16 +82,22 @@ dependencies:
|
|
70
82
|
name: activerecord
|
71
83
|
requirement: !ruby/object:Gem::Requirement
|
72
84
|
requirements:
|
73
|
-
- - "
|
85
|
+
- - ">="
|
74
86
|
- !ruby/object:Gem::Version
|
75
87
|
version: '5.0'
|
88
|
+
- - "<"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '6.1'
|
76
91
|
type: :development
|
77
92
|
prerelease: false
|
78
93
|
version_requirements: !ruby/object:Gem::Requirement
|
79
94
|
requirements:
|
80
|
-
- - "
|
95
|
+
- - ">="
|
81
96
|
- !ruby/object:Gem::Version
|
82
97
|
version: '5.0'
|
98
|
+
- - "<"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '6.1'
|
83
101
|
- !ruby/object:Gem::Dependency
|
84
102
|
name: capybara
|
85
103
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +132,14 @@ dependencies:
|
|
114
132
|
requirements:
|
115
133
|
- - "<"
|
116
134
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
135
|
+
version: '2'
|
118
136
|
type: :development
|
119
137
|
prerelease: false
|
120
138
|
version_requirements: !ruby/object:Gem::Requirement
|
121
139
|
requirements:
|
122
140
|
- - "<"
|
123
141
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
142
|
+
version: '2'
|
125
143
|
- !ruby/object:Gem::Dependency
|
126
144
|
name: pry-byebug
|
127
145
|
requirement: !ruby/object:Gem::Requirement
|
@@ -226,28 +244,42 @@ dependencies:
|
|
226
244
|
requirements:
|
227
245
|
- - "~>"
|
228
246
|
- !ruby/object:Gem::Version
|
229
|
-
version:
|
247
|
+
version: 0.78.0
|
248
|
+
type: :development
|
249
|
+
prerelease: false
|
250
|
+
version_requirements: !ruby/object:Gem::Requirement
|
251
|
+
requirements:
|
252
|
+
- - "~>"
|
253
|
+
- !ruby/object:Gem::Version
|
254
|
+
version: 0.78.0
|
255
|
+
- !ruby/object:Gem::Dependency
|
256
|
+
name: rubocop-rails
|
257
|
+
requirement: !ruby/object:Gem::Requirement
|
258
|
+
requirements:
|
259
|
+
- - "~>"
|
260
|
+
- !ruby/object:Gem::Version
|
261
|
+
version: 2.4.1
|
230
262
|
type: :development
|
231
263
|
prerelease: false
|
232
264
|
version_requirements: !ruby/object:Gem::Requirement
|
233
265
|
requirements:
|
234
266
|
- - "~>"
|
235
267
|
- !ruby/object:Gem::Version
|
236
|
-
version:
|
268
|
+
version: 2.4.1
|
237
269
|
- !ruby/object:Gem::Dependency
|
238
270
|
name: rubocop-rspec
|
239
271
|
requirement: !ruby/object:Gem::Requirement
|
240
272
|
requirements:
|
241
273
|
- - "~>"
|
242
274
|
- !ruby/object:Gem::Version
|
243
|
-
version:
|
275
|
+
version: 1.37.0
|
244
276
|
type: :development
|
245
277
|
prerelease: false
|
246
278
|
version_requirements: !ruby/object:Gem::Requirement
|
247
279
|
requirements:
|
248
280
|
- - "~>"
|
249
281
|
- !ruby/object:Gem::Version
|
250
|
-
version:
|
282
|
+
version: 1.37.0
|
251
283
|
- !ruby/object:Gem::Dependency
|
252
284
|
name: simplecov
|
253
285
|
requirement: !ruby/object:Gem::Requirement
|
@@ -270,6 +302,7 @@ extra_rdoc_files: []
|
|
270
302
|
files:
|
271
303
|
- LICENSE
|
272
304
|
- app/controllers/granite/controller.rb
|
305
|
+
- config/rubocop-default.yml
|
273
306
|
- lib/generators/USAGE
|
274
307
|
- lib/generators/granite/install_controller_generator.rb
|
275
308
|
- lib/generators/granite_generator.rb
|
@@ -287,9 +320,11 @@ files:
|
|
287
320
|
- lib/granite/action/policies/always_allow_strategy.rb
|
288
321
|
- lib/granite/action/policies/any_strategy.rb
|
289
322
|
- lib/granite/action/policies/required_performer_strategy.rb
|
323
|
+
- lib/granite/action/precondition.rb
|
290
324
|
- lib/granite/action/preconditions.rb
|
291
325
|
- lib/granite/action/preconditions/base_precondition.rb
|
292
326
|
- lib/granite/action/preconditions/embedded_precondition.rb
|
327
|
+
- lib/granite/action/preconditions/object_precondition.rb
|
293
328
|
- lib/granite/action/projectors.rb
|
294
329
|
- lib/granite/action/subject.rb
|
295
330
|
- lib/granite/action/transaction.rb
|
@@ -331,6 +366,9 @@ files:
|
|
331
366
|
- lib/granite/translations.rb
|
332
367
|
- lib/granite/typecasters.rb
|
333
368
|
- lib/granite/version.rb
|
369
|
+
- lib/rubocop-granite.rb
|
370
|
+
- lib/rubocop/granite.rb
|
371
|
+
- lib/rubocop/granite/inject.rb
|
334
372
|
homepage: https://github.com/toptal/granite
|
335
373
|
licenses:
|
336
374
|
- MIT
|
@@ -350,8 +388,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
350
388
|
- !ruby/object:Gem::Version
|
351
389
|
version: '0'
|
352
390
|
requirements: []
|
353
|
-
|
354
|
-
rubygems_version: 2.7.6
|
391
|
+
rubygems_version: 3.0.9
|
355
392
|
signing_key:
|
356
393
|
specification_version: 4
|
357
394
|
summary: Another business actions architecture for Rails apps
|