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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b5bf788dee82cc5ebe55c1a2df92a3949f69ffd
4
- data.tar.gz: 79c5a14b468c3bbece8938c7e46c12d78389f47a
3
+ metadata.gz: 1f1582c815201583dba180555b5bd51655d3e360
4
+ data.tar.gz: f832ad44a7aa5184d8751ec936e6e2e97d92d7b2
5
5
  SHA512:
6
- metadata.gz: 81affd9ba997e80550f4309ee3480e5c68937048aee7202b70764dc889c814c8b5927ff0d5ad014c8007b0fb6d1286ea241958d9fb6e51728b57d59725e7d23e
7
- data.tar.gz: 0a4b14aaa4c1b380041376a0254b1232fa251b02640728f24b5cb764daf427b14359ad2161f739cb2e49ca7c223cba49163634f87e7403c34ec3528153f78e9a
6
+ metadata.gz: 52406e282e75275c70f976f0ef1b62c448d2e1e0d0932bddd3b502cd207ca781f56d33718a28a10080e17ff291fa0093c55ec666d96da00249ca09529ec38c6d
7
+ data.tar.gz: b02e6b83b5011184cd364294b9e9118a959465b296eca7844c08688ce490fa27989738a758696007ae254f9fb86e753ae09e73542746e30d1c161b43d178bc28
@@ -47,23 +47,23 @@ module Rasti
47
47
 
48
48
  end
49
49
 
50
- def initialize(container, context={})
51
- @container = container
52
- @context = context
50
+ def initialize(environment, session)
51
+ @environment = environment
52
+ @session = session
53
53
  end
54
54
 
55
55
  private
56
56
 
57
- attr_reader :container, :context
57
+ attr_reader :environment, :session
58
58
 
59
59
  def policy
60
- @policy ||= (container[:policy_class] || Policy).new container, context
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, container, context, form
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, context, form, options
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
@@ -45,15 +45,15 @@ module Rasti
45
45
 
46
46
  include Delegable
47
47
 
48
- def initialize(facade, container, context)
48
+ def initialize(facade, environment, session)
49
49
  @facade = facade
50
- @container = container
51
- @context = context
50
+ @environment = environment
51
+ @session = session
52
52
  end
53
53
 
54
54
  private
55
55
 
56
- attr_reader :facade, :container, :context
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, container, context, form
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, container, context, form)
84
- interaction_class(name).new(container, context).call(form)
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, context, form, options={})
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
- context: context,
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(container, context)
115
- SynchronicInteractionsFactory.new self, container, context
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(container, context)
16
- @container = container
17
- @context = context
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 :container, :context
30
+ attr_reader :environment, :session
31
31
 
32
32
  def form
33
33
  thread_cache[:form]
@@ -4,13 +4,13 @@ module Rasti
4
4
 
5
5
  extend ClassConfig
6
6
 
7
- attr_config :container
7
+ attr_config :environment
8
8
 
9
9
  def call
10
- raise "Undefined #{self.class.name}.container" unless self.class.container
10
+ raise "Undefined #{self.class.name}.environment" unless self.class.environment
11
11
 
12
- context = params[:context].merge(job_id: @process.id)
13
- interaction = params[:interaction].new self.class.container, context
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
 
@@ -35,30 +35,26 @@ module Rasti
35
35
 
36
36
  end
37
37
 
38
- def initialize(container, context)
39
- @container = container
40
- @context = context
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 :container, :context
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
@@ -16,6 +16,11 @@ module Rasti
16
16
  end
17
17
  end
18
18
 
19
+ def namespace_of(klass)
20
+ namespace = klass.name.split('::')[0..-2].join('::')
21
+ namespace.empty? ? nil : Object.const_get(namespace)
22
+ end
23
+
19
24
  end
20
25
  end
21
26
  end
@@ -1,5 +1,5 @@
1
1
  module Rasti
2
2
  class App
3
- VERSION = '0.1.2'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
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.1.2
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-03-20 00:00:00.000000000 Z
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
@@ -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