service_objects 0.0.1 → 0.0.2

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
2
  SHA1:
3
- metadata.gz: b235fa6809000778410a4af3b1844d7665a600b9
4
- data.tar.gz: 0f352e8303b2a39fd6e7ad72750b95f14b53c6dc
3
+ metadata.gz: 06222ac3c2f9261f41273db8c895a31223a3ef29
4
+ data.tar.gz: 4e4ea02438691b0d12bdd91841caa3d96799bc7e
5
5
  SHA512:
6
- metadata.gz: 34c1d9c63afd08d42d7d37102bd85acb98e8e49f53024d469ef66ce6ed1be0b5ea0522a6b86009e694539635c134b94a49484d9bd8a9be6c919c7da1dd75b5d8
7
- data.tar.gz: 2ede947fcf3c189e3ff82cd275ad43e5aefdc83bf7de3bee4cc0e2746aa425aed85e8d4b21e608b23c9dc098de3a2fcb3c76415674e160f89212a052a96615ae
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
- require "hexx-suit"
5
- Hexx::Suit::Metrics::MetricFu.load
4
+ begin
5
+ require "hexx-suit"
6
+ Hexx::Suit::Metrics::MetricFu.load
7
+ rescue LoadError
8
+ end
data/.travis.yml CHANGED
@@ -1,4 +1,9 @@
1
+ ---
1
2
  language: ruby
3
+ bundler_args: --without metrics
4
+ script: rake test:coverage:run
2
5
  rvm:
3
- - 2.1
4
- - 2.2
6
+ - '2.0'
7
+ - '2.1'
8
+ - '2.2'
9
+ - ruby-head
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ gem "hexx-suit", "~> 2.0", group: :metrics if RUBY_ENGINE == "ruby"
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
- require "hexx-suit"
14
- Hexx::Suit.install_tasks
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::Suit check:coverage rake task by default
17
- task default: "check:coverage"
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 < SimpleDelegator
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 :__getobj__
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
@@ -4,6 +4,6 @@ module ServiceObjects
4
4
 
5
5
  # The semantic version of the module.
6
6
  # @see http://semver.org/ Semantic versioning 2.0
7
- VERSION = "0.0.1".freeze
7
+ VERSION = "0.0.2".freeze
8
8
 
9
9
  end # module ServiceObjects
@@ -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 |s|
5
- s.name = "service_objects"
6
- s.version = ServiceObjects::VERSION.dup
7
- s.author = "Andrew Kozin"
8
- s.email = "andrew.kozin@gmail.com"
9
- s.homepage = "https://github.com/nepalez/service_objects"
10
- s.summary = "Service objects (interactors)."
11
- s.description = "Base class for objects, that implements" \
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
- s.license = "MIT"
14
- s.platform = Gem::Platform::RUBY
15
- s.required_ruby_version = "~> 2.1"
14
+ gem.license = "MIT"
16
15
 
17
- s.require_paths = ["lib"]
18
- s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
19
- s.test_files = Dir["spec/**/*.rb"]
20
- s.extra_rdoc_files = Dir["README.md", "LICENSE", "config/metrics/STYLEGUIDE"]
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
- s.add_runtime_dependency "activemodel", "~> 4.1"
23
- s.add_runtime_dependency "extlib", "~> 0.9"
24
- s.add_runtime_dependency "naught", "~> 1.0"
25
- s.add_runtime_dependency "wisper", "~> 1.6"
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-suit"
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::Suit.load_metrics_for(self)
7
+ Hexx::RSpec.load_metrics_for(self)
13
8
 
14
9
  # Loads the code of the module.
15
10
  require "service_objects"
@@ -2,11 +2,18 @@
2
2
 
3
3
  describe ServiceObjects::Listener do
4
4
 
5
- subject { described_class.new double }
5
+ let(:object) { double :object, foo: nil }
6
+ subject { described_class.new object }
6
7
 
7
- it "is a simple delegator" do
8
- expect(subject).to be_kind_of SimpleDelegator
9
- end
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 do
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
- it "calls #otherwise when no other methods has been checked" do
28
- expect(subject).to receive(:otherwise)
29
- subject.finalize
30
+ shared_examples "calling #otherwise" do
31
+ after { subject.finalize }
32
+ it { is_expected.to receive :otherwise }
30
33
  end
31
34
 
32
- it "calls #otherwise when undefined method has been checked" do
33
- expect(subject).to receive(:otherwise)
34
- subject.respond_to? :on_error
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
- it "doesn't call #otherwise when defined method has been checked" do
39
- expect(subject).not_to receive(:otherwise)
40
- subject.respond_to? :on_success
41
- subject.finalize
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
- it "returns self" do
45
- expect(subject.finalize).to eq subject
46
- end
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.1
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-02-26 00:00:00.000000000 Z
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-suit
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.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.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.2.2
163
+ rubygems_version: 2.4.6
165
164
  signing_key:
166
165
  specification_version: 4
167
166
  summary: Service objects (interactors).