service_objects 0.0.1 → 0.0.2
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/.metrics +5 -2
- data/.travis.yml +7 -2
- data/Gemfile +2 -0
- data/Rakefile +9 -4
- data/lib/service_objects/listener.rb +20 -5
- data/lib/service_objects/version.rb +1 -1
- data/service_objects.gemspec +20 -20
- data/spec/spec_helper.rb +2 -7
- data/spec/tests/listener_spec.rb +46 -23
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06222ac3c2f9261f41273db8c895a31223a3ef29
|
4
|
+
data.tar.gz: 4e4ea02438691b0d12bdd91841caa3d96799bc7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d780885f32cee67e8759d31a9dfd9851506bfe6294bac74dade103fba8fa90a56be2749cce93706ecb4a963bbf986950ef40abf6baebb2218a069917b6a7602
|
7
|
+
data.tar.gz: e3356c69b601603fce0b240e4534c568fbe1739eacaca7c658c240829d1740a757f8956e8947bd4e46422220bcd915171d95a2549aac6f6a6518759caa4700f4
|
data/.metrics
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Settings for metric_fu and its packages are collected in the `config/metrics`
|
2
2
|
# and loaded by the Hexx::Suit::Metrics::MetricFu.
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
begin
|
5
|
+
require "hexx-suit"
|
6
|
+
Hexx::Suit::Metrics::MetricFu.load
|
7
|
+
rescue LoadError
|
8
|
+
end
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -10,8 +10,13 @@ end
|
|
10
10
|
Bundler::GemHelper.install_tasks
|
11
11
|
|
12
12
|
# Loads the Hexx::Suit and its tasks
|
13
|
-
|
14
|
-
|
13
|
+
begin
|
14
|
+
require "hexx-suit"
|
15
|
+
Hexx::Suit.install_tasks
|
16
|
+
rescue LoadError
|
17
|
+
require "hexx-rspec"
|
18
|
+
Hexx::RSpec.install_tasks
|
19
|
+
end
|
15
20
|
|
16
|
-
# Sets the Hexx::
|
17
|
-
task default:
|
21
|
+
# Sets the Hexx::RSpec task by default
|
22
|
+
task default: :test
|
@@ -9,7 +9,7 @@ module ServiceObjects
|
|
9
9
|
# @example (see #finalize)
|
10
10
|
#
|
11
11
|
# @api public
|
12
|
-
class Listener
|
12
|
+
class Listener
|
13
13
|
|
14
14
|
# @!scope class
|
15
15
|
# @!method new(object)
|
@@ -21,7 +21,7 @@ module ServiceObjects
|
|
21
21
|
# object = Object.new
|
22
22
|
#
|
23
23
|
# listener = ServiceObjects::Listener.new object
|
24
|
-
# listener.send :
|
24
|
+
# listener.send :object
|
25
25
|
# # => object
|
26
26
|
#
|
27
27
|
# @param [Object] object
|
@@ -29,6 +29,9 @@ module ServiceObjects
|
|
29
29
|
# @return [ServiceObjects::Listener]
|
30
30
|
#
|
31
31
|
# @api public
|
32
|
+
def initialize(object)
|
33
|
+
@object = object
|
34
|
+
end
|
32
35
|
|
33
36
|
# The method called by {#finalize} when no other method has been checked
|
34
37
|
#
|
@@ -84,14 +87,26 @@ module ServiceObjects
|
|
84
87
|
#
|
85
88
|
# Remembers the fact that any defined method has been checked
|
86
89
|
#
|
87
|
-
# @example
|
88
|
-
# respond_to? :finalize, false # => true
|
89
|
-
#
|
90
90
|
# @return [Boolean]
|
91
|
+
#
|
92
|
+
# @api private
|
91
93
|
def respond_to?(*)
|
92
94
|
super ? (@notified = true) : false
|
93
95
|
end
|
94
96
|
|
97
|
+
# @private
|
98
|
+
def respond_to_missing?(*args)
|
99
|
+
object.respond_to?(*args)
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
attr_reader :object
|
105
|
+
|
106
|
+
def method_missing(*args, &block)
|
107
|
+
object.send(*args, &block)
|
108
|
+
end
|
109
|
+
|
95
110
|
end # class Listener
|
96
111
|
|
97
112
|
end # module ServiceObjects
|
data/service_objects.gemspec
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
$:.push File.expand_path("../lib", __FILE__)
|
2
2
|
require "service_objects/version"
|
3
3
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
|
6
|
+
gem.name = "service_objects"
|
7
|
+
gem.version = ServiceObjects::VERSION.dup
|
8
|
+
gem.author = "Andrew Kozin"
|
9
|
+
gem.email = "andrew.kozin@gmail.com"
|
10
|
+
gem.homepage = "https://github.com/nepalez/service_objects"
|
11
|
+
gem.summary = "Service objects (interactors)."
|
12
|
+
gem.description = "Base class for objects, that implements" \
|
12
13
|
" both the Interactor and Observer design patterns."
|
13
|
-
|
14
|
-
s.platform = Gem::Platform::RUBY
|
15
|
-
s.required_ruby_version = "~> 2.1"
|
14
|
+
gem.license = "MIT"
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
18
|
+
gem.test_files = Dir["spec/**/*.rb"]
|
19
|
+
gem.extra_rdoc_files = Dir["README.md", "LICENSE"]
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
gem.required_ruby_version = "~> 2.1"
|
22
|
+
gem.add_runtime_dependency "activemodel", "~> 4.1"
|
23
|
+
gem.add_runtime_dependency "extlib", "~> 0.9"
|
24
|
+
gem.add_runtime_dependency "naught", "~> 1.0"
|
25
|
+
gem.add_runtime_dependency "wisper", "~> 1.6"
|
26
|
+
gem.add_development_dependency "hexx-rspec", "~> 0.3"
|
26
27
|
|
27
|
-
s.add_development_dependency "hexx-suit", "~> 0.0"
|
28
28
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
# Loads the RSpec test suit.
|
4
|
-
require "hexx-
|
5
|
-
|
6
|
-
# Loads the RSpec support files.
|
7
|
-
Dir.chdir File.expand_path("..", __FILE__) do
|
8
|
-
Dir["./support/config/*.rb"].each { |file| require file }
|
9
|
-
end
|
4
|
+
require "hexx-rspec"
|
10
5
|
|
11
6
|
# Loads runtime metrics in the current scope
|
12
|
-
Hexx::
|
7
|
+
Hexx::RSpec.load_metrics_for(self)
|
13
8
|
|
14
9
|
# Loads the code of the module.
|
15
10
|
require "service_objects"
|
data/spec/tests/listener_spec.rb
CHANGED
@@ -2,11 +2,18 @@
|
|
2
2
|
|
3
3
|
describe ServiceObjects::Listener do
|
4
4
|
|
5
|
-
|
5
|
+
let(:object) { double :object, foo: nil }
|
6
|
+
subject { described_class.new object }
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
describe ".new" do
|
9
|
+
|
10
|
+
it "provides a decorator" do
|
11
|
+
expect(subject).to respond_to :foo
|
12
|
+
expect(object).to receive(:foo)
|
13
|
+
subject.foo
|
14
|
+
end
|
15
|
+
|
16
|
+
end # .new
|
10
17
|
|
11
18
|
describe "#otherwise" do
|
12
19
|
|
@@ -18,32 +25,48 @@ describe ServiceObjects::Listener do
|
|
18
25
|
|
19
26
|
describe "#finalize" do
|
20
27
|
|
21
|
-
before
|
22
|
-
subject.__getobj__.singleton_class.send(:define_method, :item) { nil }
|
23
|
-
subject.singleton_class.send(:define_method, :on_success) { nil }
|
24
|
-
subject.singleton_class.send(:define_method, :otherwise) { nil }
|
25
|
-
end
|
28
|
+
before { subject.singleton_class.send(:define_method, :on_success) { nil } }
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
+
shared_examples "calling #otherwise" do
|
31
|
+
after { subject.finalize }
|
32
|
+
it { is_expected.to receive :otherwise }
|
30
33
|
end
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
subject.finalize
|
35
|
+
shared_examples "skipping #otherwise" do
|
36
|
+
after { subject.finalize }
|
37
|
+
it { is_expected.not_to receive :otherwise }
|
36
38
|
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
shared_examples "mutating" do
|
41
|
+
it "returns self" do
|
42
|
+
expect(subject.finalize).to eq subject
|
43
|
+
end
|
42
44
|
end
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
46
|
+
context "when no callbacks has been checked" do
|
47
|
+
|
48
|
+
it_behaves_like "calling #otherwise"
|
49
|
+
it_behaves_like "mutating"
|
50
|
+
|
51
|
+
end # context
|
52
|
+
|
53
|
+
context "when undefined callback has been checked" do
|
54
|
+
|
55
|
+
before { subject.respond_to? :on_error }
|
56
|
+
|
57
|
+
it_behaves_like "calling #otherwise"
|
58
|
+
it_behaves_like "mutating"
|
59
|
+
|
60
|
+
end # context
|
61
|
+
|
62
|
+
context "when defined callback has been checked" do
|
63
|
+
|
64
|
+
before { subject.respond_to? :on_success }
|
65
|
+
|
66
|
+
it_behaves_like "skipping #otherwise"
|
67
|
+
it_behaves_like "mutating"
|
68
|
+
|
69
|
+
end # context
|
47
70
|
|
48
71
|
end # #finalize
|
49
72
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: service_objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kozin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -67,19 +67,19 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.6'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: hexx-
|
70
|
+
name: hexx-rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
75
|
+
version: '0.3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
82
|
+
version: '0.3'
|
83
83
|
description: Base class for objects, that implements both the Interactor and Observer
|
84
84
|
design patterns.
|
85
85
|
email: andrew.kozin@gmail.com
|
@@ -88,7 +88,6 @@ extensions: []
|
|
88
88
|
extra_rdoc_files:
|
89
89
|
- README.md
|
90
90
|
- LICENSE
|
91
|
-
- config/metrics/STYLEGUIDE
|
92
91
|
files:
|
93
92
|
- ".coveralls.yml"
|
94
93
|
- ".metrics"
|
@@ -161,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
160
|
version: '0'
|
162
161
|
requirements: []
|
163
162
|
rubyforge_project:
|
164
|
-
rubygems_version: 2.
|
163
|
+
rubygems_version: 2.4.6
|
165
164
|
signing_key:
|
166
165
|
specification_version: 4
|
167
166
|
summary: Service objects (interactors).
|