telephone 0.1.0 → 1.0.0

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
  SHA256:
3
- metadata.gz: 2961c1545d60c8daef9cdc90a8ecea01c12ecd14357d446dbfe86cae84cc43c2
4
- data.tar.gz: 27dad4361e48e380776fb3c32ea59855f95804e024b1aad879d84ad292f96a23
3
+ metadata.gz: b95df7745edfdcccffb9d141f444fb2b487b55d0cd20ae6e1dd86a51033f064a
4
+ data.tar.gz: 3d680e1fecccb620ab8823e0e46cba6b9fa506f1718b5486e38750ccf4ab86ab
5
5
  SHA512:
6
- metadata.gz: 70159c4118b77a694873f4cf9f14d28bfbaae52692c28eaa95eafec80b06a91e8fd65dd76db1a849efdd5e7b5a294c5d1836a5b924c6df81eb9b9a636145c14e
7
- data.tar.gz: 2bd95f410bc0bc92960c1e6065ecf5b0971dbc6792dff760cebef1494d1cdbc8efd5e87499d53a7eaae1786f8904a4280b570c9d59327995877a17fad20a8773
6
+ metadata.gz: dd79447632f18c1ac6237254589df28980098b1988172886b10c3a46e2e2ea6bf6122d81219653111a51dbfc75edefea2b79450905c099875bb48ab5e6fcdd1b
7
+ data.tar.gz: d40dd3b806a554920571c40841ccc539a1531eef7cde07800a171cfc9b5cbcf4a2f98c140fa702f22bbc1e3d2e68077c55cd21c45eafbf2af464dfdc9a2431cb
@@ -16,6 +16,18 @@ module Telephone
16
16
  # Telephone::Service.call(foo: bar).result # "baz"
17
17
  attr_accessor :result
18
18
 
19
+ ##
20
+ # Primary responsibility of initialize is to instantiate the
21
+ # attributes of the service object with the expected values.
22
+ def initialize(attributes = {})
23
+ self.class.defaults.merge(attributes).each do |key, value|
24
+ send("#{key}=", value)
25
+ end
26
+
27
+ super
28
+ yield self if block_given?
29
+ end
30
+
19
31
  ##
20
32
  # Determines whether or not the action of the service
21
33
  # object was successful.
@@ -28,6 +40,11 @@ module Telephone
28
40
  errors.empty?
29
41
  end
30
42
 
43
+ def call
44
+ self.result = __call if valid?
45
+ self
46
+ end
47
+
31
48
  class << self
32
49
  ##
33
50
  # Defines a getter/setter for a service object argument. This also allows you
@@ -66,9 +83,19 @@ module Telephone
66
83
  # @example
67
84
  # Telephone::Service.call(foo: bar)
68
85
  def call(**args)
69
- instance = new(defaults.merge(args))
70
- instance.result = instance.call if instance.valid?
71
- instance
86
+ new(args).call
87
+ end
88
+
89
+ ##
90
+ # When the subclass overwrites the #call method, reassign it to #__call.
91
+ # This allows us to still control what happens in the instance level of #call.
92
+ def method_added(method_name)
93
+ if method_name == :call
94
+ alias_method :__call, :call
95
+ send(:remove_method, :call)
96
+ else
97
+ super
98
+ end
72
99
  end
73
100
  end
74
101
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Telephone
4
- VERSION = "0.1.0"
4
+ VERSION = "1.0.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telephone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Hargett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-31 00:00:00.000000000 Z
11
+ date: 2022-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  version: '0'
57
57
  requirements:
58
58
  - none
59
- rubygems_version: 3.0.3
59
+ rubygems_version: 3.1.6
60
60
  signing_key:
61
61
  specification_version: 4
62
62
  summary: Utility class for creating and calling service objects.