rao-service 0.0.48.pre → 0.0.50.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +46 -2
- data/lib/generators/rao/service/templates/initializer.rb +6 -0
- data/lib/rao/service/base/autosave_concern.rb +4 -0
- data/lib/rao/service/base/callbacks_concern.rb +7 -2
- data/lib/rao/service/base.rb +5 -0
- data/lib/rao/service/configuration.rb +1 -0
- data/{app/jobs → lib}/rao/service/job.rb +1 -1
- data/{app/mailers → lib}/rao/service/notification_mailer.rb +2 -0
- data/lib/rao/service/result/base/attribute_names_concern.rb +35 -0
- data/lib/rao/service/result/base.rb +3 -0
- metadata +7 -6
- /data/{app/mailers → lib}/rao/service/application_mailer.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 294f3a65680c8418c165d267126dbfdb339563eeac0f10aacf532f3f2eb62bcc
|
4
|
+
data.tar.gz: d78dfc7c61bdef1fcfcff9786aca13e8d667d00da890b16253f1d588bbb67bc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d614bc3dc2b93cfc2fc5b8521a78fe2b56aedfcf18d3a5326a5392a3c89f9bc218218337916fc235df1326b2d90944d7ae9c59238968bf3cec2ee462bb002fc
|
7
|
+
data.tar.gz: 3442dc89d8f1f844bd2d37ee9216c1960382e17e36da888ab7f0cdb735b48877f62416559bc032c5f710b23a2123921b83302285e3a8ec244c4dda866e5b246b
|
data/README.md
CHANGED
@@ -1,8 +1,52 @@
|
|
1
1
|
# Rails Add-Ons Service
|
2
|
-
|
2
|
+
|
3
|
+
Rails is missing a service layer. For simple applications the default MVC impementation may be enought, but once you begin adding serious business lovgic you either end up with fat controllers, models, callback hell or all of them.
|
4
|
+
|
5
|
+
Rao::Service solves this problem by providing you a service object that is easy to use. It can be simultaneously used for UIs and APIs by using Rao::ServiceController and Rao::Api::Service Controller as its frontend.
|
6
|
+
|
3
7
|
|
4
8
|
## Usage
|
5
|
-
|
9
|
+
|
10
|
+
Here is a basic example that queries the nasa api:
|
11
|
+
```
|
12
|
+
# nethttp.rb
|
13
|
+
require 'uri'
|
14
|
+
require 'net/http'
|
15
|
+
|
16
|
+
class NasaService < Rao::Service::Base
|
17
|
+
class Result < Rao::Service::Result::Base
|
18
|
+
attr_accessor :response
|
19
|
+
|
20
|
+
def parsed_response
|
21
|
+
@parsed_response ||= JSON.parse(response)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def _perform
|
28
|
+
response = Net::HTTP.get_response(uri)
|
29
|
+
|
30
|
+
if response.is_a?(Net::HTTPSuccess)
|
31
|
+
@result.response = response.body
|
32
|
+
else
|
33
|
+
add_error_and_say(:base, "API request failed.")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def uri
|
38
|
+
@uri ||= URI('https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
result = PlanetService.call
|
43
|
+
|
44
|
+
if result.ok?
|
45
|
+
result.parsed_response
|
46
|
+
else
|
47
|
+
result.errors.full_messages.to_sentence
|
48
|
+
end
|
49
|
+
```
|
6
50
|
|
7
51
|
## Installation
|
8
52
|
Add this line to your application's Gemfile:
|
@@ -16,4 +16,10 @@ Rao::Service.configure do |config|
|
|
16
16
|
# Default: config.default_notification_recipient = ->(result) { ::Rails.env }
|
17
17
|
#
|
18
18
|
config.notification_environment = ->(result) { ::Rails.env }
|
19
|
+
|
20
|
+
# Sets the base class for service jobs.
|
21
|
+
#
|
22
|
+
# default: config.job_base_class_name = 'ActiveJob::Base'
|
23
|
+
#
|
24
|
+
config.job_base_class_name = 'ActiveJob::Base'
|
19
25
|
end
|
@@ -9,6 +9,9 @@ module Rao
|
|
9
9
|
def before_validation; end
|
10
10
|
def after_validation; end
|
11
11
|
def after_perform; end
|
12
|
+
def around_perform
|
13
|
+
yield
|
14
|
+
end
|
12
15
|
|
13
16
|
def perform(options = {})
|
14
17
|
options.reverse_merge!(validate: true)
|
@@ -19,8 +22,10 @@ module Rao
|
|
19
22
|
after_validation
|
20
23
|
end
|
21
24
|
before_perform
|
22
|
-
|
23
|
-
|
25
|
+
around_perform do
|
26
|
+
say "Performing" do
|
27
|
+
_perform
|
28
|
+
end
|
24
29
|
end
|
25
30
|
after_perform
|
26
31
|
save if autosave? && respond_to?(:save, true)
|
data/lib/rao/service/base.rb
CHANGED
@@ -11,6 +11,7 @@ module Rao
|
|
11
11
|
mattr_accessor(:default_notification_sender) { 'john.doe@domain.local' }
|
12
12
|
mattr_accessor(:default_notification_recipient) { 'john.doe@domain.local' }
|
13
13
|
mattr_accessor(:notification_environment) { Object.const_defined?('::Rails') ? ::Rails.env : nil }
|
14
|
+
mattr_accessor(:job_base_class_name) { 'ActiveJob::Base' }
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Rao
|
2
|
+
module Service
|
3
|
+
module Result
|
4
|
+
module Base::AttributeNamesConcern
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
end
|
9
|
+
|
10
|
+
class_methods do
|
11
|
+
def attr_accessor(*args)
|
12
|
+
super
|
13
|
+
add_attribute_names(*args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def attr_reader(*args)
|
17
|
+
super
|
18
|
+
add_attribute_names(*args)
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_attribute_names(*args)
|
22
|
+
args.each do |attr_name|
|
23
|
+
attribute_names << attr_name
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def attribute_names
|
28
|
+
(@attr_names ||= [])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rao-service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.50.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Vasquez Angel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -188,14 +188,12 @@ files:
|
|
188
188
|
- MIT-LICENSE
|
189
189
|
- README.md
|
190
190
|
- Rakefile
|
191
|
-
- app/jobs/rao/service/job.rb
|
192
|
-
- app/mailers/rao/service/application_mailer.rb
|
193
|
-
- app/mailers/rao/service/notification_mailer.rb
|
194
191
|
- app/views/rao/service/notification_mailer/result_email.text.erb
|
195
192
|
- lib/generators/rao/service/install_generator.rb
|
196
193
|
- lib/generators/rao/service/templates/initializer.rb
|
197
194
|
- lib/rao-service.rb
|
198
195
|
- lib/rao/service.rb
|
196
|
+
- lib/rao/service/application_mailer.rb
|
199
197
|
- lib/rao/service/base.rb
|
200
198
|
- lib/rao/service/base/active_job_concern.rb
|
201
199
|
- lib/rao/service/base/autosave_concern.rb
|
@@ -206,8 +204,11 @@ files:
|
|
206
204
|
- lib/rao/service/base/result_concern.rb
|
207
205
|
- lib/rao/service/configuration.rb
|
208
206
|
- lib/rao/service/engine.rb
|
207
|
+
- lib/rao/service/job.rb
|
209
208
|
- lib/rao/service/message/base.rb
|
209
|
+
- lib/rao/service/notification_mailer.rb
|
210
210
|
- lib/rao/service/result/base.rb
|
211
|
+
- lib/rao/service/result/base/attribute_names_concern.rb
|
211
212
|
- lib/rao/service/result/base/mailable_concern.rb
|
212
213
|
- lib/rao/service/result/base/succeedable_concern.rb
|
213
214
|
- lib/rao/service/version.rb
|
@@ -231,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
231
232
|
- !ruby/object:Gem::Version
|
232
233
|
version: 1.3.1
|
233
234
|
requirements: []
|
234
|
-
rubygems_version: 3.
|
235
|
+
rubygems_version: 3.4.20
|
235
236
|
signing_key:
|
236
237
|
specification_version: 4
|
237
238
|
summary: Services for Ruby on Rails.
|
File without changes
|