rasti-app 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rasti/app.rb +20 -42
- data/lib/rasti/app/asynchronic_interaction.rb +4 -0
- data/lib/rasti/app/delegable.rb +33 -0
- data/lib/rasti/app/facade.rb +118 -0
- data/lib/rasti/app/interaction.rb +4 -0
- data/lib/rasti/app/utils.rb +22 -0
- data/lib/rasti/app/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3793dceedf42613f23ddee1725e14f152c97d6ce
|
4
|
+
data.tar.gz: 933deb25ee6be913c2013a277922262cef53d325
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c467add607bc1afadb2ff9ab5c3eb46293fa33752b5b29a35c8d90c65bb3749e80e5187535d7daaeb50fdcb2e89a4fd8f17f7d83a5654c9697943cac8cfa561
|
7
|
+
data.tar.gz: e1ff86425b84a98621ce3563c81e34ffdd885c9edbf3d074d10bdaadc40e569d6ba935ecd8f8f21fa45098e25137b0044b77558a23c61f570e17be8816f3a2e6
|
data/lib/rasti/app.rb
CHANGED
@@ -17,51 +17,34 @@ module Rasti
|
|
17
17
|
|
18
18
|
class << self
|
19
19
|
|
20
|
-
|
21
|
-
@permissions ||= []
|
22
|
-
end
|
20
|
+
extend Forwardable
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
def_delegators :facade, :interactions,
|
23
|
+
:synchronic_interactions,
|
24
|
+
:asynchronic_interactions,
|
25
|
+
:permissions,
|
26
|
+
:valid_permission?
|
28
27
|
|
29
|
-
|
30
|
-
[].tap do |classes|
|
31
|
-
namespace.constants.each do |name|
|
32
|
-
constant = namespace.const_get name
|
33
|
-
if constant.class == Module
|
34
|
-
classes_in(constant, superclass).each { |c| classes << c }
|
35
|
-
elsif constant.class == Class && (superclass.nil? || constant.ancestors.include?(superclass))
|
36
|
-
classes << constant
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
28
|
+
attr_reader :facade
|
41
29
|
|
42
30
|
private
|
43
31
|
|
44
|
-
def
|
45
|
-
|
46
|
-
permission = interaction_permission interaction, namespace
|
47
|
-
permissions << permission
|
32
|
+
def expose(namespace)
|
33
|
+
@facade = Facade.new namespace
|
48
34
|
|
49
|
-
|
50
|
-
|
51
|
-
|
35
|
+
facade.interactions.each do |name, specification|
|
36
|
+
if specification.synchronic?
|
37
|
+
define_method name do |params={}|
|
38
|
+
call name, specification.permission, params
|
52
39
|
end
|
53
40
|
end
|
54
|
-
|
55
|
-
define_method "enqueue_#{
|
56
|
-
enqueue
|
41
|
+
|
42
|
+
define_method "enqueue_#{name}" do |params={}|
|
43
|
+
enqueue name, specification.permission, params
|
57
44
|
end
|
58
45
|
end
|
59
46
|
end
|
60
47
|
|
61
|
-
def interaction_permission(interaction, namespace)
|
62
|
-
Permission.new interaction.name.sub("#{namespace.name}::", '').split('::').map { |s| Inflecto.underscore s }
|
63
|
-
end
|
64
|
-
|
65
48
|
end
|
66
49
|
|
67
50
|
def initialize(container, context={})
|
@@ -77,19 +60,14 @@ module Rasti
|
|
77
60
|
@policy ||= (container[:policy_class] || Policy).new container, context
|
78
61
|
end
|
79
62
|
|
80
|
-
def call(
|
63
|
+
def call(name, permission, params={})
|
81
64
|
authorize! permission, params
|
82
|
-
|
65
|
+
self.class.facade.call name, container, context, params
|
83
66
|
end
|
84
67
|
|
85
|
-
def enqueue(
|
68
|
+
def enqueue(name, permission, params={})
|
86
69
|
authorize! permission, params
|
87
|
-
|
88
|
-
Job.enqueue queue: params.delete(:queue) || Asynchronic.default_queue,
|
89
|
-
alias: interaction,
|
90
|
-
interaction: interaction,
|
91
|
-
context: context,
|
92
|
-
params: interaction.build_form(params).attributes
|
70
|
+
self.class.facade.enqueue name, context, params
|
93
71
|
end
|
94
72
|
|
95
73
|
def authorize!(permission, params)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Rasti
|
2
|
+
class App
|
3
|
+
module Delegable
|
4
|
+
|
5
|
+
def methods(*args)
|
6
|
+
delegated_methods | super
|
7
|
+
end
|
8
|
+
|
9
|
+
def public_methods(*args)
|
10
|
+
delegated_methods | super
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def delegated_method?(method_name)
|
16
|
+
delegated_methods.include? method_name.to_sym
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(method_name, *args, &block)
|
20
|
+
if delegated_method? method_name
|
21
|
+
call_delegated_method method_name, *args, &block
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def respond_to_missing?(method_name, *args)
|
28
|
+
delegated_method?(method_name) || super
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module Rasti
|
2
|
+
class App
|
3
|
+
class Facade
|
4
|
+
|
5
|
+
class UndefinedInteraction < StandardError
|
6
|
+
def initialize(name)
|
7
|
+
super "Undefined interaction #{name}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
class InteractionSpecification
|
13
|
+
|
14
|
+
attr_reader :interaction, :namespace
|
15
|
+
|
16
|
+
def initialize(interaction, namespace)
|
17
|
+
@interaction = interaction
|
18
|
+
@namespace = namespace
|
19
|
+
end
|
20
|
+
|
21
|
+
def name
|
22
|
+
permission.last_section.to_sym
|
23
|
+
end
|
24
|
+
|
25
|
+
def permission
|
26
|
+
@permission ||= Permission.new interaction.name.sub("#{namespace.name}::", '').split('::').map { |s| Inflecto.underscore s }
|
27
|
+
end
|
28
|
+
|
29
|
+
def asynchronic?
|
30
|
+
interaction.asynchronic?
|
31
|
+
end
|
32
|
+
|
33
|
+
def synchronic?
|
34
|
+
!asynchronic?
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
class SynchronicInteractionsFactory
|
41
|
+
|
42
|
+
include Delegable
|
43
|
+
|
44
|
+
def initialize(facade, container, context)
|
45
|
+
@facade = facade
|
46
|
+
@container = container
|
47
|
+
@context = context
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
attr_reader :facade, :container, :context
|
53
|
+
|
54
|
+
def delegated_methods
|
55
|
+
facade.synchronic_interactions.keys
|
56
|
+
end
|
57
|
+
|
58
|
+
def call_delegated_method(method_name, *args, &block)
|
59
|
+
facade.call method_name, container, context, *args
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
attr_reader :interactions
|
66
|
+
|
67
|
+
def initialize(namespace)
|
68
|
+
@interactions = Utils.classes_in(namespace, Interaction).each_with_object({}) do |interaction, hash|
|
69
|
+
specificaiton = InteractionSpecification.new interaction, namespace
|
70
|
+
hash[specificaiton.name] = specificaiton
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def call(name, container, context, params={})
|
75
|
+
interaction_class(name).new(container, context).call(params)
|
76
|
+
end
|
77
|
+
|
78
|
+
def enqueue(name, context, params={})
|
79
|
+
interaction = interaction_class name
|
80
|
+
|
81
|
+
Job.enqueue queue: params.delete(:queue) || Asynchronic.default_queue,
|
82
|
+
alias: interaction,
|
83
|
+
interaction: interaction,
|
84
|
+
context: context,
|
85
|
+
params: interaction.build_form(params).attributes
|
86
|
+
end
|
87
|
+
|
88
|
+
def synchronic_interactions
|
89
|
+
interactions.select { |k,v| v.synchronic? }
|
90
|
+
end
|
91
|
+
|
92
|
+
def asynchronic_interactions
|
93
|
+
interactions.select { |k,v| v.asynchronic? }
|
94
|
+
end
|
95
|
+
|
96
|
+
def permissions
|
97
|
+
interactions.values.map(&:permission).sort
|
98
|
+
end
|
99
|
+
|
100
|
+
def valid_permission?(permission)
|
101
|
+
permission = Permission.new permission
|
102
|
+
permissions.any? { |p| permission.include? p }
|
103
|
+
end
|
104
|
+
|
105
|
+
def synchronic_interactions_factory(container, context)
|
106
|
+
SynchronicInteractionsFactory.new self, container, context
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def interaction_class(name)
|
112
|
+
raise UndefinedInteraction, name unless interactions.key?(name.to_sym)
|
113
|
+
interactions[name.to_sym].interaction
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Rasti
|
2
|
+
class App
|
3
|
+
class Utils
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def classes_in(namespace, superclass=nil)
|
7
|
+
[].tap do |classes|
|
8
|
+
namespace.constants.each do |name|
|
9
|
+
constant = namespace.const_get name
|
10
|
+
if constant.class == Module
|
11
|
+
classes_in(constant, superclass).each { |c| classes << c }
|
12
|
+
elsif constant.class == Class && (superclass.nil? || constant.ancestors.include?(superclass))
|
13
|
+
classes << constant
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/rasti/app/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rasti-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inflecto
|
@@ -238,6 +238,8 @@ files:
|
|
238
238
|
- lib/rasti/app.rb
|
239
239
|
- lib/rasti/app/asynchronic_interaction.rb
|
240
240
|
- lib/rasti/app/container.rb
|
241
|
+
- lib/rasti/app/delegable.rb
|
242
|
+
- lib/rasti/app/facade.rb
|
241
243
|
- lib/rasti/app/interaction.rb
|
242
244
|
- lib/rasti/app/job.rb
|
243
245
|
- lib/rasti/app/permission.rb
|
@@ -245,6 +247,7 @@ files:
|
|
245
247
|
- lib/rasti/app/service.rb
|
246
248
|
- lib/rasti/app/service_factory.rb
|
247
249
|
- lib/rasti/app/settings.rb
|
250
|
+
- lib/rasti/app/utils.rb
|
248
251
|
- lib/rasti/app/version.rb
|
249
252
|
- rasti-app.gemspec
|
250
253
|
- spec/coverage_helper.rb
|