service_objects 0.1.0 → 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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.metrics +1 -0
  4. data/.travis.yml +9 -1
  5. data/.yardopts +1 -1
  6. data/Gemfile +1 -1
  7. data/Guardfile +29 -8
  8. data/LICENSE +1 -1
  9. data/README.md +179 -342
  10. data/Rakefile +3 -3
  11. data/config/metrics/churn.yml +1 -1
  12. data/config/metrics/flay.yml +1 -1
  13. data/config/metrics/metric_fu.yml +1 -0
  14. data/config/metrics/rubocop.yml +4 -4
  15. data/config/metrics/simplecov.yml +1 -1
  16. data/lib/service_objects.rb +6 -9
  17. data/lib/service_objects/base.rb +190 -17
  18. data/lib/service_objects/listener.rb +21 -75
  19. data/lib/service_objects/message.rb +15 -96
  20. data/lib/service_objects/version.rb +1 -1
  21. data/service_objects.gemspec +11 -9
  22. data/spec/lib/base_spec.rb +247 -0
  23. data/spec/lib/listener_spec.rb +96 -0
  24. data/spec/lib/message_spec.rb +48 -0
  25. data/spec/spec_helper.rb +8 -6
  26. metadata +56 -93
  27. data/bin/service +0 -17
  28. data/config/metrics/pippi.yml +0 -3
  29. data/lib/service_objects/cli.rb +0 -117
  30. data/lib/service_objects/cli/locale.erb +0 -20
  31. data/lib/service_objects/cli/service.erb +0 -125
  32. data/lib/service_objects/cli/spec.erb +0 -87
  33. data/lib/service_objects/helpers.rb +0 -17
  34. data/lib/service_objects/helpers/dependable.rb +0 -63
  35. data/lib/service_objects/helpers/exceptions.rb +0 -64
  36. data/lib/service_objects/helpers/messages.rb +0 -95
  37. data/lib/service_objects/helpers/parameterized.rb +0 -85
  38. data/lib/service_objects/helpers/parameters.rb +0 -71
  39. data/lib/service_objects/helpers/validations.rb +0 -54
  40. data/lib/service_objects/invalid.rb +0 -55
  41. data/lib/service_objects/null.rb +0 -26
  42. data/lib/service_objects/parsers.rb +0 -13
  43. data/lib/service_objects/parsers/dependency.rb +0 -69
  44. data/lib/service_objects/parsers/notification.rb +0 -85
  45. data/lib/service_objects/rspec.rb +0 -75
  46. data/lib/service_objects/utils/normal_hash.rb +0 -34
  47. data/spec/tests/base_spec.rb +0 -43
  48. data/spec/tests/bin/service_spec.rb +0 -18
  49. data/spec/tests/cli_spec.rb +0 -179
  50. data/spec/tests/helpers/dependable_spec.rb +0 -77
  51. data/spec/tests/helpers/exceptions_spec.rb +0 -112
  52. data/spec/tests/helpers/messages_spec.rb +0 -64
  53. data/spec/tests/helpers/parameterized_spec.rb +0 -136
  54. data/spec/tests/helpers/parameters_spec.rb +0 -71
  55. data/spec/tests/helpers/validations_spec.rb +0 -60
  56. data/spec/tests/invalid_spec.rb +0 -69
  57. data/spec/tests/listener_spec.rb +0 -73
  58. data/spec/tests/message_spec.rb +0 -191
  59. data/spec/tests/null_spec.rb +0 -17
  60. data/spec/tests/parsers/dependency_spec.rb +0 -29
  61. data/spec/tests/parsers/notification_spec.rb +0 -84
  62. data/spec/tests/rspec_spec.rb +0 -86
  63. data/spec/tests/utils/normal_hash_spec.rb +0 -16
@@ -1,17 +0,0 @@
1
- # encoding: utf-8
2
-
3
- describe ServiceObjects::NULL do
4
-
5
- it "respond to arbitrary method" do
6
- expect(true).to eq subject.respond_to?(:arbitrary_method)
7
- end
8
-
9
- it "returns itself" do
10
- expect(subject.arbitrary_method).to eq subject
11
- end
12
-
13
- it "is a singleton" do
14
- expect(subject.class.instance.__id__).to eq subject.__id__
15
- end
16
-
17
- end # describe ServiceObjects::NULL
@@ -1,29 +0,0 @@
1
- # encoding: utf-8
2
- require "service_objects/parsers/dependency"
3
-
4
- describe ServiceObjects::Parsers::Dependency do
5
-
6
- subject { described_class.new "Get_item{add/item.do.chain}" }
7
-
8
- describe "#name" do
9
-
10
- it "returns the dependency name in snake case" do
11
- expect(subject.name).to eq "get_item"
12
- end
13
- end
14
-
15
- describe "#type" do
16
-
17
- it "returns the dependency type as is" do
18
- expect(subject.type).to eq "Add::Item.do.chain"
19
- end
20
- end
21
-
22
- describe "#listener" do
23
-
24
- it "returns the dependency listener name" do
25
- expect(subject.listener).to eq "GetItemListener"
26
- end
27
- end
28
-
29
- end # describe ServiceObjects::Parsers::Dependency
@@ -1,84 +0,0 @@
1
- # encoding: utf-8
2
- require "service_objects/parsers/notification"
3
-
4
- describe ServiceObjects::Parsers::Notification do
5
-
6
- describe "#name" do
7
-
8
- it "returns the name of the notification" do
9
- subject = described_class.new "not_found:item:messages"
10
- expect(subject.name).to eq "not_found"
11
- end
12
-
13
- end # describe #name
14
-
15
- describe "#exception" do
16
-
17
- it "returns the name of the exception" do
18
- subject = described_class.new "not_found:item:messages"
19
- expect(subject.exception).to eq "NotFound"
20
- end
21
-
22
- end # describe #exception
23
-
24
- describe "#args" do
25
-
26
- it "returns all notification arguments" do
27
- subject = described_class.new "success:messages:info:item"
28
- expect(subject.args).to eq %w(messages info item)
29
- end
30
-
31
- end # describe #args" do
32
-
33
- describe "#non_messages" do
34
-
35
- it "returns all args except for messages" do
36
- subject = described_class.new "success:messages:info:item"
37
- expect(subject.non_messages).to eq %w(info item)
38
- end
39
-
40
- end # describe #non_messages
41
-
42
- describe "#publish_messages?" do
43
-
44
- it "returns true if messages published" do
45
- subject = described_class.new "found:item:messages"
46
- expect(subject.publish_messages?).to eq true
47
- end
48
-
49
- it "returns false unless messages published" do
50
- subject = described_class.new "found:item:info"
51
- expect(subject.publish_messages?).to eq false
52
- end
53
-
54
- end # describe #publish_messages?
55
-
56
- describe "#error?" do
57
-
58
- it "returns true for errors" do
59
- subject = described_class.new "error:messages"
60
- expect(subject).to be_error
61
- end
62
-
63
- it "returns false otherwise" do
64
- subject = described_class.new "found:messages"
65
- expect(subject).not_to be_error
66
- end
67
-
68
- end # describe #error?
69
-
70
- describe "#order" do
71
-
72
- it "returns 1 for errors" do
73
- subject = described_class.new "error:messages"
74
- expect(subject.order).to eq 1
75
- end
76
-
77
- it "returns 0 otherwise" do
78
- subject = described_class.new "found:messages"
79
- expect(subject.order).to eq 0
80
- end
81
-
82
- end # describe #order
83
-
84
- end # describe ServiceObjects::Parsers::Notification
@@ -1,86 +0,0 @@
1
- # encoding: utf-8
2
- require "service_objects/rspec"
3
-
4
- describe ServiceObjects::RSpec do
5
-
6
- let(:test_class) { Class.new(Object).__send__(:include, described_class) }
7
- subject { test_class.new }
8
-
9
- describe "#params" do
10
-
11
- it "returns a hash" do
12
- expect(subject.params).to eq({})
13
- end
14
-
15
- end # describe #params
16
-
17
- describe "listener" do
18
-
19
- it "should be spy" do
20
- expect(subject.listener).to be_kind_of ::RSpec::Mocks::Double
21
- end
22
-
23
- end # describe #listener
24
-
25
- describe "#service" do
26
-
27
- let(:service_class) { ServiceObjects::Base }
28
- before { allow(subject).to receive(:described_class) { service_class } }
29
-
30
- it "returns the object of described class" do
31
- expect(subject.service).to be_kind_of(service_class)
32
- end
33
-
34
- it "initializes the object with given params" do
35
- allow(subject).to receive(:params) { { foo: :bar } }
36
-
37
- expect(service_class)
38
- .to receive(:new)
39
- .with(subject.params)
40
- .and_call_original
41
- subject.service
42
- end
43
-
44
- it "subscribes the listener" do
45
- listener = double
46
- allow(subject).to receive(:listener) { listener }
47
-
48
- expect(service_class)
49
- .to receive_message_chain(:new, :subscribe)
50
- .with(listener)
51
- subject.service
52
- end
53
-
54
- end # describe #service
55
-
56
- describe "#service_double" do
57
-
58
- it "returns a service object" do
59
- expect(subject.service_double).to be_kind_of ServiceObjects::Base
60
- end
61
-
62
- it "runs given block in the service's scope" do
63
- service_double = subject.service_double(:foo) { |name| publish name }
64
- expect(service_double).to receive(:publish).with(:foo)
65
- service_double.run
66
- end
67
-
68
- end # describe #service_double
69
-
70
- describe "#inject" do
71
-
72
- let(:service_class) { Class.new ServiceObjects::Base }
73
- let(:injection) { double }
74
- let(:params) { double }
75
-
76
- before { allow(subject).to receive(:described_class) { service_class } }
77
-
78
- it "makes service dependency to construct given object" do
79
- subject.inject :foo, with: params, constructs: injection
80
-
81
- expect(subject.service.foo.new(params)).to eq injection
82
- end
83
-
84
- end # describe #inject
85
-
86
- end # describe ServiceObjects::RSpec
@@ -1,16 +0,0 @@
1
- # encoding: utf-8
2
-
3
- describe ServiceObjects::Utils::NormalHash do
4
-
5
- describe ".from" do
6
-
7
- it "symbolizes keys of existing hash" do
8
- source = { "foo" => "foo", "bar" => { "bar" => "bar", "baz" => nil } }
9
- target = { foo: "foo", bar: { bar: "bar", baz: nil } }
10
-
11
- expect(described_class.from(source)).to eq target
12
- end
13
-
14
- end # .new
15
-
16
- end # ServiceObjects::Utils::NormalHash