application_service 0.2.6 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8cf0e27732278a5b59314f2026b94c38fc60efc7
4
- data.tar.gz: 69b3edb80cf28b33c0baf7f72316d43c340fd572
2
+ SHA256:
3
+ metadata.gz: 87237dd34364ef71483ec478dde114e69e45c35210d2cd82e3369b9907db4940
4
+ data.tar.gz: 40f18312cd9606cee57a8cab09b0b72c8ceac1b056083c227e0697a630aad5ba
5
5
  SHA512:
6
- metadata.gz: 81e3cdb81ea574a6b053162cb87e7051d349a4bed13f1f2b983df65b35be7e28562f9df1e9fad99b09c7b540f16c5c4d44be6cbbf3d943f19a03fd04543b5299
7
- data.tar.gz: 25d83f5721dfdb39e91f5689aee236a53103cf91715e472a54081739369d1c10eb60c99b26af399ec34457c76a7525ee61e0f4ac53fb2a86234d94e8576b606f
6
+ metadata.gz: '029975f7377f57cd983358f5b82afe1ce291c879914044d312467b94b047f5586b68f27f090e76a3f28b783947a5460da2f721dfedb123f7f68d5b4f77991844'
7
+ data.tar.gz: 3d44b1b5efca69c3c15a1e65c33c5b786c9e101fccce1e206f99234e3b91424f41a2fc581dbc437aeffda8a8f52886af709d2616a07aae7bf8d488cf8dbb92ed
@@ -0,0 +1,24 @@
1
+ name: CI
2
+ on: [push]
3
+
4
+ jobs:
5
+ test:
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - uses: actions/checkout@v2
9
+ - uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
10
+ with:
11
+ ruby-version: 2.7
12
+ bundler-cache: true
13
+ - run: bundle install
14
+ - run: bundle exec rspec
15
+ rubocop:
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
20
+ with:
21
+ ruby-version: 2.7
22
+ bundler-cache: true
23
+ - run: bundle install
24
+ - run: bundle exec rubocop
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ AllCops:
2
+ DisabledByDefault: true
3
+
4
+ Security:
5
+ Enabled: true
6
+
7
+ Bundler/DuplicatedGem:
8
+ Enabled: true
9
+ Bundler/InsecureProtocolSource:
10
+ Enabled: true
11
+ Layout/IndentationStyle:
12
+ Enabled: true
13
+ Layout/SpaceInsideRangeLiteral:
14
+ Enabled: true
15
+ Lint:
16
+ Enabled: true
17
+ Lint/RaiseException:
18
+ Enabled: true
19
+ Naming/AsciiIdentifiers:
20
+ Enabled: true
21
+ Naming/ClassAndModuleCamelCase:
22
+ Enabled: true
23
+ Naming/ConstantName:
24
+ Enabled: true
25
+ Naming/FileName:
26
+ Enabled: true
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.5
1
+ 3.0.3
data/Gemfile CHANGED
@@ -1,8 +1,9 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'activesupport', '~> 5.0', '>= 5.0.0.1'
3
+ gem 'activesupport', '>= 5.0.0.1'
4
4
 
5
5
  group :development do
6
6
  gem 'rspec', '~> 3.5'
7
+ gem 'rubocop'
7
8
  gem 'jeweler', '~> 2.2', '>= 2.2.1'
8
9
  end
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # application\_service
2
+
3
+ A service layer for rails apps.
4
+
5
+ [![CI Status](https://github.com/controlshift/application_service/actions/workflows/ci.yml/badge.svg)](https://github.com/controlshift/application_service/actions/workflows/ci.yml)
6
+
7
+ ## Contributing to application\_service
8
+
9
+ - Check out the latest code from `main` to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
10
+ - Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
11
+ - Fork the project.
12
+ - Start a feature/bugfix branch.
13
+ - Commit and push until you are happy with your contribution.
14
+ - Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
15
+ - Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
16
+
17
+ ## Copyright
18
+
19
+ Copyright (c) 2013 Nathan Woodhull. See LICENSE.txt for
20
+ further details.
21
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.4.1
@@ -2,30 +2,32 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: application_service 0.2.6 ruby lib
5
+ # stub: application_service 0.4.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "application_service".freeze
9
- s.version = "0.2.6"
9
+ s.version = "0.4.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Nathan Woodhull".freeze]
14
- s.date = "2018-12-03"
14
+ s.date = "2022-03-02"
15
15
  s.description = "A service layer scaffold for rails apps extracted from Agra".freeze
16
16
  s.email = "woodhull@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE.txt",
19
- "README.rdoc"
19
+ "README.md"
20
20
  ]
21
21
  s.files = [
22
22
  ".document",
23
+ ".github/workflows/ci.yml",
23
24
  ".rspec",
25
+ ".rubocop.yml",
24
26
  ".ruby-gemset",
25
27
  ".ruby-version",
26
28
  "Gemfile",
27
29
  "LICENSE.txt",
28
- "README.rdoc",
30
+ "README.md",
29
31
  "Rakefile",
30
32
  "VERSION",
31
33
  "application_service.gemspec",
@@ -35,25 +37,23 @@ Gem::Specification.new do |s|
35
37
  ]
36
38
  s.homepage = "http://github.com/woodhull/application_service".freeze
37
39
  s.licenses = ["MIT".freeze]
38
- s.rubygems_version = "2.6.12".freeze
40
+ s.rubygems_version = "3.2.32".freeze
39
41
  s.summary = "Service Layer Scaffold".freeze
40
42
 
41
43
  if s.respond_to? :specification_version then
42
44
  s.specification_version = 4
45
+ end
43
46
 
44
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
- s.add_runtime_dependency(%q<activesupport>.freeze, [">= 5.0.0.1", "~> 5.0"])
46
- s.add_development_dependency(%q<rspec>.freeze, ["~> 3.5"])
47
- s.add_development_dependency(%q<jeweler>.freeze, [">= 2.2.1", "~> 2.2"])
48
- else
49
- s.add_dependency(%q<activesupport>.freeze, [">= 5.0.0.1", "~> 5.0"])
50
- s.add_dependency(%q<rspec>.freeze, ["~> 3.5"])
51
- s.add_dependency(%q<jeweler>.freeze, [">= 2.2.1", "~> 2.2"])
52
- end
47
+ if s.respond_to? :add_runtime_dependency then
48
+ s.add_runtime_dependency(%q<activesupport>.freeze, [">= 5.0.0.1"])
49
+ s.add_development_dependency(%q<rspec>.freeze, ["~> 3.5"])
50
+ s.add_development_dependency(%q<rubocop>.freeze, [">= 0"])
51
+ s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.2", ">= 2.2.1"])
53
52
  else
54
- s.add_dependency(%q<activesupport>.freeze, [">= 5.0.0.1", "~> 5.0"])
53
+ s.add_dependency(%q<activesupport>.freeze, [">= 5.0.0.1"])
55
54
  s.add_dependency(%q<rspec>.freeze, ["~> 3.5"])
56
- s.add_dependency(%q<jeweler>.freeze, [">= 2.2.1", "~> 2.2"])
55
+ s.add_dependency(%q<rubocop>.freeze, [">= 0"])
56
+ s.add_dependency(%q<jeweler>.freeze, ["~> 2.2", ">= 2.2.1"])
57
57
  end
58
58
  end
59
59
 
@@ -3,7 +3,7 @@ require 'active_support/all'
3
3
  class ApplicationService
4
4
 
5
5
  include ActiveSupport::Callbacks
6
- define_callbacks :save, :create, :update, :destroy, {terminator: ->(target, result) { result.call == false }, skip_after_callbacks_if_terminated: true}
6
+ define_callbacks :save, :create, :update, :destroy, {terminator: ->(_target, result) { result.call == false }, skip_after_callbacks_if_terminated: true}
7
7
 
8
8
  def initialize
9
9
  end
@@ -67,16 +67,16 @@ class ApplicationService
67
67
  end
68
68
  end
69
69
 
70
- def update_attributes(obj, params)
70
+ def update_attributes(obj, params, with_admin_save: false)
71
71
  @obj = obj
72
72
  @obj.assign_attributes(params)
73
73
 
74
74
  yield if block_given?
75
75
 
76
- run_callbacks :save do
77
- run_callbacks :update do
78
- @obj.save
79
- end
76
+ if with_admin_save
77
+ self.admin_save(obj)
78
+ else
79
+ self.save(obj)
80
80
  end
81
81
  end
82
82
 
@@ -104,6 +104,12 @@ class ApplicationService
104
104
  @on_admin_save = false
105
105
  end
106
106
 
107
+ def self.extract_callback_options(args)
108
+ options = args.last.is_a?(Hash) ? args.pop : {}
109
+
110
+ options
111
+ end
112
+
107
113
  private
108
114
 
109
115
  def create!(save_method=:save!)
@@ -129,13 +135,4 @@ class ApplicationService
129
135
  @obj.send(save_method)
130
136
  end
131
137
  end
132
-
133
- private
134
-
135
- def self.extract_callback_options(args)
136
- options = args.last.is_a?(Hash) ? args.pop : {}
137
-
138
- options
139
- end
140
-
141
138
  end
@@ -71,13 +71,21 @@ describe ApplicationService do
71
71
  end
72
72
 
73
73
  describe "#update_attributes" do
74
+ let(:obj) { double(new_record?: false) }
75
+
74
76
  it "should trigger update" do
75
- obj = double()
76
- expect(obj).to receive(:assign_attributes).with( {:foo => 'bar'}).and_return(:true)
77
+ expect(obj).to receive(:assign_attributes).with( {:foo => 'bar'}).and_return(true)
77
78
  expect(obj).to receive(:save)
78
79
 
79
80
  subject.update_attributes(obj, {:foo => 'bar'})
80
81
  end
82
+
83
+ it 'should trigger admin_save if argument is true' do
84
+ expect(obj).to receive(:assign_attributes).with( {:foo => 'bar'}).and_return(true)
85
+ expect(obj).to receive(:admin_save)
86
+
87
+ subject.update_attributes(obj, {:foo => 'bar'}, with_admin_save: true)
88
+ end
81
89
  end
82
90
 
83
91
  describe '#destroy' do
@@ -261,7 +269,7 @@ describe ApplicationService do
261
269
 
262
270
  it "should invoke subsequent callbacks if a callback is skipped with options" do
263
271
  service_klass = Class.new(ApplicationService) do
264
- before :save, :before_save_callback, if: 'false'
272
+ before :save, :before_save_callback, if: -> { false }
265
273
  before :save, :before_save_callback_2
266
274
 
267
275
  end
@@ -288,7 +296,7 @@ describe ApplicationService do
288
296
 
289
297
  it "should invoke callback if conditional is true" do
290
298
  service_klass = Class.new(ApplicationService) do
291
- before :save, :before_save_callback, if: 'true'
299
+ before :save, :before_save_callback, if: -> { true }
292
300
  end
293
301
 
294
302
  service = service_klass.new
@@ -336,7 +344,7 @@ describe ApplicationService do
336
344
 
337
345
  it "should invoke callback if conditional is true" do
338
346
  service_klass = Class.new(ApplicationService) do
339
- after :save, :after_save_callback, if: 'true'
347
+ after :save, :after_save_callback, if: -> { true }
340
348
  end
341
349
 
342
350
  service = service_klass.new
@@ -346,7 +354,7 @@ describe ApplicationService do
346
354
 
347
355
  it 'should not invoke callback if conditional is false' do
348
356
  service_klass = Class.new(ApplicationService) do
349
- after :save, :after_save_callback, if: 'false'
357
+ after :save, :after_save_callback, if: -> { false }
350
358
  end
351
359
 
352
360
  service = service_klass.new
data/spec/spec_helper.rb CHANGED
@@ -5,8 +5,8 @@ require 'application_service'
5
5
 
6
6
  # Requires supporting files with custom matchers and macros, etc,
7
7
  # in ./support/ and its subdirectories.
8
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
8
+ Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].sort.each { |f| require f }
9
9
 
10
10
  RSpec.configure do |config|
11
-
11
+
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: application_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Woodhull
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-03 00:00:00.000000000 Z
11
+ date: 2022-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 5.0.0.1
20
- - - "~>"
21
- - !ruby/object:Gem::Version
22
- version: '5.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 5.0.0.1
30
- - - "~>"
31
- - !ruby/object:Gem::Version
32
- version: '5.0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rspec
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -45,40 +39,56 @@ dependencies:
45
39
  - !ruby/object:Gem::Version
46
40
  version: '3.5'
47
41
  - !ruby/object:Gem::Dependency
48
- name: jeweler
42
+ name: rubocop
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - ">="
52
46
  - !ruby/object:Gem::Version
53
- version: 2.2.1
54
- - - "~>"
55
- - !ruby/object:Gem::Version
56
- version: '2.2'
47
+ version: '0'
57
48
  type: :development
58
49
  prerelease: false
59
50
  version_requirements: !ruby/object:Gem::Requirement
60
51
  requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.2'
61
62
  - - ">="
62
63
  - !ruby/object:Gem::Version
63
64
  version: 2.2.1
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
64
69
  - - "~>"
65
70
  - !ruby/object:Gem::Version
66
71
  version: '2.2'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.2.1
67
75
  description: A service layer scaffold for rails apps extracted from Agra
68
76
  email: woodhull@gmail.com
69
77
  executables: []
70
78
  extensions: []
71
79
  extra_rdoc_files:
72
80
  - LICENSE.txt
73
- - README.rdoc
81
+ - README.md
74
82
  files:
75
83
  - ".document"
84
+ - ".github/workflows/ci.yml"
76
85
  - ".rspec"
86
+ - ".rubocop.yml"
77
87
  - ".ruby-gemset"
78
88
  - ".ruby-version"
79
89
  - Gemfile
80
90
  - LICENSE.txt
81
- - README.rdoc
91
+ - README.md
82
92
  - Rakefile
83
93
  - VERSION
84
94
  - application_service.gemspec
@@ -104,8 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
114
  - !ruby/object:Gem::Version
105
115
  version: '0'
106
116
  requirements: []
107
- rubyforge_project:
108
- rubygems_version: 2.6.12
117
+ rubygems_version: 3.2.32
109
118
  signing_key:
110
119
  specification_version: 4
111
120
  summary: Service Layer Scaffold
data/README.rdoc DELETED
@@ -1,19 +0,0 @@
1
- = application_service
2
-
3
- A service layer for rails apps.
4
-
5
- == Contributing to application_service
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
- * Fork the project.
10
- * Start a feature/bugfix branch.
11
- * Commit and push until you are happy with your contribution.
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2013 Nathan Woodhull. See LICENSE.txt for
18
- further details.
19
-