rasti-app 0.1.2 → 1.0.0
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/rasti/app.rb +7 -7
- data/lib/rasti/app/environment.rb +28 -0
- data/lib/rasti/app/facade.rb +11 -11
- data/lib/rasti/app/interaction.rb +4 -4
- data/lib/rasti/app/job.rb +4 -4
- data/lib/rasti/app/policy.rb +6 -10
- data/lib/rasti/app/session.rb +22 -0
- data/lib/rasti/app/utils.rb +5 -0
- data/lib/rasti/app/version.rb +1 -1
- metadata +4 -3
- data/lib/rasti/app/container.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f1582c815201583dba180555b5bd51655d3e360
|
4
|
+
data.tar.gz: f832ad44a7aa5184d8751ec936e6e2e97d92d7b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52406e282e75275c70f976f0ef1b62c448d2e1e0d0932bddd3b502cd207ca781f56d33718a28a10080e17ff291fa0093c55ec666d96da00249ca09529ec38c6d
|
7
|
+
data.tar.gz: b02e6b83b5011184cd364294b9e9118a959465b296eca7844c08688ce490fa27989738a758696007ae254f9fb86e753ae09e73542746e30d1c161b43d178bc28
|
data/lib/rasti/app.rb
CHANGED
@@ -47,23 +47,23 @@ module Rasti
|
|
47
47
|
|
48
48
|
end
|
49
49
|
|
50
|
-
def initialize(
|
51
|
-
@
|
52
|
-
@
|
50
|
+
def initialize(environment, session)
|
51
|
+
@environment = environment
|
52
|
+
@session = session
|
53
53
|
end
|
54
54
|
|
55
55
|
private
|
56
56
|
|
57
|
-
attr_reader :
|
57
|
+
attr_reader :environment, :session
|
58
58
|
|
59
59
|
def policy
|
60
|
-
@policy ||=
|
60
|
+
@policy ||= environment.policy_for session
|
61
61
|
end
|
62
62
|
|
63
63
|
def call(name, permission, params={})
|
64
64
|
form = self.class.facade.build_form name, params
|
65
65
|
authorize! permission, form
|
66
|
-
result = self.class.facade.call name,
|
66
|
+
result = self.class.facade.call name, environment, session, form
|
67
67
|
after_call name, form.attributes
|
68
68
|
|
69
69
|
result
|
@@ -77,7 +77,7 @@ module Rasti
|
|
77
77
|
|
78
78
|
form = self.class.facade.build_form name, params
|
79
79
|
authorize! permission, form
|
80
|
-
result = self.class.facade.enqueue name,
|
80
|
+
result = self.class.facade.enqueue name, session, form, options
|
81
81
|
after_call name, form.attributes
|
82
82
|
|
83
83
|
result
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Rasti
|
2
|
+
class App
|
3
|
+
class Environment
|
4
|
+
|
5
|
+
attr_reader :settings
|
6
|
+
|
7
|
+
def initialize(name)
|
8
|
+
@settings = File.exist?(name) ? Settings.load_file(name) : Settings.load(name)
|
9
|
+
end
|
10
|
+
|
11
|
+
def policy_for(session)
|
12
|
+
policy_class.new self, session
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def policy_class
|
18
|
+
@policy_class ||= begin
|
19
|
+
namespace = Utils.namespace_of self.class
|
20
|
+
namespace.nil? ? Consty.get('Policy') : Consty.get('Policy', namespace)
|
21
|
+
rescue
|
22
|
+
Policy
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/rasti/app/facade.rb
CHANGED
@@ -45,15 +45,15 @@ module Rasti
|
|
45
45
|
|
46
46
|
include Delegable
|
47
47
|
|
48
|
-
def initialize(facade,
|
48
|
+
def initialize(facade, environment, session)
|
49
49
|
@facade = facade
|
50
|
-
@
|
51
|
-
@
|
50
|
+
@environment = environment
|
51
|
+
@session = session
|
52
52
|
end
|
53
53
|
|
54
54
|
private
|
55
55
|
|
56
|
-
attr_reader :facade, :
|
56
|
+
attr_reader :facade, :environment, :session
|
57
57
|
|
58
58
|
def delegated_methods
|
59
59
|
facade.synchronic_interactions.keys
|
@@ -61,7 +61,7 @@ module Rasti
|
|
61
61
|
|
62
62
|
def call_delegated_method(interaction_name, params={})
|
63
63
|
form = facade.build_form interaction_name, params
|
64
|
-
facade.call interaction_name,
|
64
|
+
facade.call interaction_name, environment, session, form
|
65
65
|
end
|
66
66
|
|
67
67
|
end
|
@@ -80,17 +80,17 @@ module Rasti
|
|
80
80
|
interaction_class(name).build_form params
|
81
81
|
end
|
82
82
|
|
83
|
-
def call(name,
|
84
|
-
interaction_class(name).new(
|
83
|
+
def call(name, environment, session, form)
|
84
|
+
interaction_class(name).new(environment, session).call(form)
|
85
85
|
end
|
86
86
|
|
87
|
-
def enqueue(name,
|
87
|
+
def enqueue(name, session, form, options={})
|
88
88
|
interaction = interaction_class name
|
89
89
|
Job.enqueue queue: options[:queue] || Asynchronic.default_queue,
|
90
90
|
id: options[:job_id],
|
91
91
|
alias: interaction,
|
92
92
|
interaction: interaction,
|
93
|
-
|
93
|
+
session: session,
|
94
94
|
params: form.attributes
|
95
95
|
end
|
96
96
|
|
@@ -111,8 +111,8 @@ module Rasti
|
|
111
111
|
permissions.any? { |p| permission.include? p }
|
112
112
|
end
|
113
113
|
|
114
|
-
def synchronic_interactions_factory(
|
115
|
-
SynchronicInteractionsFactory.new self,
|
114
|
+
def synchronic_interactions_factory(environment, session)
|
115
|
+
SynchronicInteractionsFactory.new self, environment, session
|
116
116
|
end
|
117
117
|
|
118
118
|
private
|
@@ -12,9 +12,9 @@ module Rasti
|
|
12
12
|
false
|
13
13
|
end
|
14
14
|
|
15
|
-
def initialize(
|
16
|
-
@
|
17
|
-
@
|
15
|
+
def initialize(environment, session)
|
16
|
+
@environment = environment
|
17
|
+
@session = session
|
18
18
|
end
|
19
19
|
|
20
20
|
def call(form)
|
@@ -27,7 +27,7 @@ module Rasti
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
attr_reader :
|
30
|
+
attr_reader :environment, :session
|
31
31
|
|
32
32
|
def form
|
33
33
|
thread_cache[:form]
|
data/lib/rasti/app/job.rb
CHANGED
@@ -4,13 +4,13 @@ module Rasti
|
|
4
4
|
|
5
5
|
extend ClassConfig
|
6
6
|
|
7
|
-
attr_config :
|
7
|
+
attr_config :environment
|
8
8
|
|
9
9
|
def call
|
10
|
-
raise "Undefined #{self.class.name}.
|
10
|
+
raise "Undefined #{self.class.name}.environment" unless self.class.environment
|
11
11
|
|
12
|
-
|
13
|
-
interaction = params[:interaction].new self.class.
|
12
|
+
session.job_id = @process.id
|
13
|
+
interaction = params[:interaction].new self.class.environment, session
|
14
14
|
interaction.call params[:interaction].build_form params[:params]
|
15
15
|
end
|
16
16
|
|
data/lib/rasti/app/policy.rb
CHANGED
@@ -35,30 +35,26 @@ module Rasti
|
|
35
35
|
|
36
36
|
end
|
37
37
|
|
38
|
-
def initialize(
|
39
|
-
@
|
40
|
-
@
|
38
|
+
def initialize(environment, session)
|
39
|
+
@environment = environment
|
40
|
+
@session = session
|
41
41
|
end
|
42
42
|
|
43
43
|
def authorized?(permission, form)
|
44
44
|
if self.class.authorizations.key? permission
|
45
45
|
instance_exec form, &self.class.authorizations[permission]
|
46
46
|
else
|
47
|
-
user.authorized? permission
|
47
|
+
session.user.authorized? permission
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
def authorize!(permission, form)
|
52
|
-
raise UnauthorizedError.new(user.name, permission) unless authorized? permission, form
|
52
|
+
raise UnauthorizedError.new(session.user.name, permission) unless authorized? permission, form
|
53
53
|
end
|
54
54
|
|
55
55
|
private
|
56
56
|
|
57
|
-
attr_reader :
|
58
|
-
|
59
|
-
def user
|
60
|
-
context.fetch(:user)
|
61
|
-
end
|
57
|
+
attr_reader :environment, :session
|
62
58
|
|
63
59
|
end
|
64
60
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Rasti
|
2
|
+
class App
|
3
|
+
class Session
|
4
|
+
|
5
|
+
attr_reader :user
|
6
|
+
attr_accessor :job_id
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def user
|
13
|
+
options.fetch(:user)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :options
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/rasti/app/utils.rb
CHANGED
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.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inflecto
|
@@ -243,8 +243,8 @@ files:
|
|
243
243
|
- lib/rasti-app.rb
|
244
244
|
- lib/rasti/app.rb
|
245
245
|
- lib/rasti/app/asynchronic_interaction.rb
|
246
|
-
- lib/rasti/app/container.rb
|
247
246
|
- lib/rasti/app/delegable.rb
|
247
|
+
- lib/rasti/app/environment.rb
|
248
248
|
- lib/rasti/app/facade.rb
|
249
249
|
- lib/rasti/app/interaction.rb
|
250
250
|
- lib/rasti/app/job.rb
|
@@ -252,6 +252,7 @@ files:
|
|
252
252
|
- lib/rasti/app/policy.rb
|
253
253
|
- lib/rasti/app/service.rb
|
254
254
|
- lib/rasti/app/service_factory.rb
|
255
|
+
- lib/rasti/app/session.rb
|
255
256
|
- lib/rasti/app/settings.rb
|
256
257
|
- lib/rasti/app/utils.rb
|
257
258
|
- lib/rasti/app/version.rb
|
data/lib/rasti/app/container.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module Rasti
|
2
|
-
class App
|
3
|
-
class Container
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@registry = {}
|
7
|
-
@cache = {}
|
8
|
-
yield self if block_given?
|
9
|
-
end
|
10
|
-
|
11
|
-
def register(key, &block)
|
12
|
-
registry[key] = block
|
13
|
-
end
|
14
|
-
|
15
|
-
def resolve(key)
|
16
|
-
cache[key] ||= registry.fetch(key).call
|
17
|
-
end
|
18
|
-
|
19
|
-
alias_method :[], :resolve
|
20
|
-
|
21
|
-
def resolve_all
|
22
|
-
registry.each_key { |k| resolve k }
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
attr_reader :registry, :cache
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|