verbalize 2.0.0 → 2.0.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
2
  SHA1:
3
- metadata.gz: ca403601a9b7decbc85e77a20103926c8d92765a
4
- data.tar.gz: ad015b2d9a8bfa2afa3e9524be0bc8dcfe4260d8
3
+ metadata.gz: 28277ada3b560d5fd8ed11a9b568dd03f8c0156a
4
+ data.tar.gz: 9ff1315685ffa11c9a997a15a07206fe0e21f112
5
5
  SHA512:
6
- metadata.gz: 10d7fcf1fda2c00aa8b12d571858595222bc329d8714234ffc4d52a247e31c66fa183e5c0da9d52475a88ca76de7c407a9d6ced73c30aa9dbe2ba88b8a103d38
7
- data.tar.gz: c0699fbe4b2c5da4e8f40f143058c552e90c2ffb421ebbc42946d138269c6b7f16d5167cb783885239e76d8ac4e2ba86fa22a2cad2ff01657690b9c4afb06ac2
6
+ metadata.gz: e4049ff78ca84f4e44f34c6525089edb96b74206ca6318f3b84c78779dd303863a612f0be86059e9e6bd1d8fce2f364a62e3d65b6269575ee13cd1dc7bbd44b9
7
+ data.tar.gz: a6528d2fa2ec1dc97d9524f6feb75426a249cc6a8bd2b656d7491d2bb5698512ec9718c836f16b33c0bc85d65aba5551a6d135170e2e1ebfb5fdf37c86770948
@@ -0,0 +1,7 @@
1
+ engines:
2
+ rubocop:
3
+ enabled: true
4
+
5
+ ratings:
6
+ paths:
7
+ - "**.rb"
data/circle.yml CHANGED
@@ -1,7 +1,3 @@
1
1
  machine:
2
2
  ruby:
3
3
  version: '2.2'
4
-
5
- test:
6
- post:
7
- - bundle exec rubocop
@@ -1,10 +1,7 @@
1
+ require_relative 'build'
1
2
  require_relative 'error'
2
- require_relative 'build_initialize_method'
3
- require_relative 'build_safe_action_method'
4
- require_relative 'build_dangerous_action_method'
5
- require_relative 'build_attribute_readers'
6
- require_relative 'success'
7
3
  require_relative 'failure'
4
+ require_relative 'success'
8
5
 
9
6
  module Verbalize
10
7
  module Action
@@ -19,46 +16,19 @@ module Verbalize
19
16
  end
20
17
 
21
18
  module ClassMethods
22
- def input( # rubocop:disable Metrics/MethodLength
23
- *required_keywords,
24
- optional: [],
25
- **other_keyword_arguments
26
- )
27
- unless other_keyword_arguments.empty?
28
- raise(
29
- ArgumentError,
30
- "Unsupported keyword arguments received: #{other_keyword_arguments.inspect}"
31
- )
32
- end
33
-
34
- optional_keywords = Array(optional)
35
-
36
- class_eval BuildSafeActionMethod.call(
37
- required_keywords: required_keywords,
38
- optional_keywords: optional_keywords
39
- )
40
-
41
- class_eval BuildDangerousActionMethod.call(
42
- required_keywords: required_keywords,
43
- optional_keywords: optional_keywords
44
- )
45
-
46
- class_eval BuildInitializeMethod.call(
47
- required_keywords: required_keywords,
48
- optional_keywords: optional_keywords
49
- )
50
-
51
- class_eval BuildAttributeReaders.call(
52
- attributes: required_keywords + optional_keywords
53
- )
19
+ def input(*required_keywords, optional: [])
20
+ class_eval Build.call(required_keywords, Array(optional))
54
21
  end
55
22
 
23
+ # Because call/call! are defined when Action.input is called, they would
24
+ # not be defined when there is no input. So we pre-define them here, and
25
+ # if there is any input, they are overwritten
56
26
  def call
57
- __verbalized_send
27
+ __proxied_call
58
28
  end
59
29
 
60
30
  def call!
61
- __verbalized_send!
31
+ __proxied_call!
62
32
  end
63
33
 
64
34
  private
@@ -67,7 +37,13 @@ module Verbalize
67
37
  new(*args).send(:call)
68
38
  end
69
39
 
70
- def __verbalized_send(*args)
40
+ # We used __proxied_call/__proxied_call! for 2 reasons:
41
+ # 1. The declaration of call/call! needs to be explicit so that tools
42
+ # like rspec-mocks can verify the actions keywords actually
43
+ # exist when stubbing
44
+ # 2. Because #1, meta-programming a simple interface to these proxied
45
+ # methods is much simpler than meta-programming the full methods
46
+ def __proxied_call(*args)
71
47
  error = catch(:verbalize_error) do
72
48
  value = perform(*args)
73
49
  return Success.new(value)
@@ -76,7 +52,7 @@ module Verbalize
76
52
  Failure.new(error)
77
53
  end
78
54
 
79
- def __verbalized_send!(*args)
55
+ def __proxied_call!(*args)
80
56
  perform(*args)
81
57
  rescue UncaughtThrowError => uncaught_throw_error
82
58
  fail_value = uncaught_throw_error.value
@@ -0,0 +1,58 @@
1
+ module Verbalize
2
+ class Build
3
+ def self.call(required_keywords = [], optional_keywords = [])
4
+ new(required_keywords, optional_keywords).call
5
+ end
6
+
7
+ def initialize(required_keywords, optional_keywords)
8
+ @required_keywords = required_keywords
9
+ @optional_keywords = optional_keywords
10
+ end
11
+
12
+ def call
13
+ <<-CODE
14
+ def self.call(#{declaration_arguments_string})
15
+ __proxied_call(#{forwarding_arguments_string})
16
+ end
17
+
18
+ def self.call!(#{declaration_arguments_string})
19
+ __proxied_call!(#{forwarding_arguments_string})
20
+ end
21
+
22
+ def initialize(#{declaration_arguments_string})
23
+ #{initialize_body}
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader #{attribute_readers_string}
29
+ CODE
30
+ end
31
+
32
+ attr_reader :required_keywords, :optional_keywords
33
+
34
+ private
35
+
36
+ def all_keywords
37
+ required_keywords + optional_keywords
38
+ end
39
+
40
+ def declaration_arguments_string
41
+ required_segments = required_keywords.map { |keyword| "#{keyword}:" }
42
+ optional_segments = optional_keywords.map { |keyword| "#{keyword}: nil" }
43
+ (required_segments + optional_segments).join(', ')
44
+ end
45
+
46
+ def forwarding_arguments_string
47
+ all_keywords.map { |keyword| "#{keyword}: #{keyword}" }.join(', ')
48
+ end
49
+
50
+ def initialize_body
51
+ all_keywords.map { |keyword| "@#{keyword} = #{keyword}" }.join("\n ")
52
+ end
53
+
54
+ def attribute_readers_string
55
+ all_keywords.map { |keyword| ":#{keyword}" }.join(', ')
56
+ end
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module Verbalize
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.0.1'.freeze
3
3
  end
@@ -24,6 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
25
25
  spec.add_development_dependency 'rspec'
26
26
  spec.add_development_dependency 'coveralls'
27
- spec.add_development_dependency 'rubocop'
27
+ spec.add_development_dependency 'rubocop', '0.45'
28
28
  spec.add_development_dependency 'pry'
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verbalize
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-14 00:00:00.000000000 Z
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '0.45'
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.45'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pry
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -101,6 +101,7 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - ".codeclimate.yml"
104
105
  - ".gitignore"
105
106
  - ".rspec"
106
107
  - ".rubocop.yml"
@@ -114,11 +115,7 @@ files:
114
115
  - circle.yml
115
116
  - lib/verbalize.rb
116
117
  - lib/verbalize/action.rb
117
- - lib/verbalize/build_attribute_readers.rb
118
- - lib/verbalize/build_dangerous_action_method.rb
119
- - lib/verbalize/build_initialize_method.rb
120
- - lib/verbalize/build_method_base.rb
121
- - lib/verbalize/build_safe_action_method.rb
118
+ - lib/verbalize/build.rb
122
119
  - lib/verbalize/error.rb
123
120
  - lib/verbalize/failure.rb
124
121
  - lib/verbalize/result.rb
@@ -1,20 +0,0 @@
1
- module Verbalize
2
- class BuildAttributeReaders
3
- def self.call(attributes: [])
4
- new(attributes: attributes).call
5
- end
6
-
7
- def initialize(attributes: [])
8
- @attributes = attributes
9
- end
10
-
11
- def call
12
- return '' if attributes.empty?
13
- "attr_reader #{attributes.map(&:inspect).join ', '}"
14
- end
15
-
16
- private
17
-
18
- attr_reader :attributes
19
- end
20
- end
@@ -1,15 +0,0 @@
1
- require_relative 'build_method_base'
2
-
3
- module Verbalize
4
- class BuildDangerousActionMethod < BuildMethodBase
5
- private
6
-
7
- def declaration
8
- declare('self.call!')
9
- end
10
-
11
- def body
12
- verbalized_send_string(bang: true)
13
- end
14
- end
15
- end
@@ -1,21 +0,0 @@
1
- require_relative 'build_method_base'
2
-
3
- module Verbalize
4
- class BuildInitializeMethod < BuildMethodBase
5
- private
6
-
7
- def declaration
8
- declare('initialize')
9
- end
10
-
11
- def body
12
- return if all_keywords.empty?
13
-
14
- lines = all_keywords.map do |keyword|
15
- " @#{keyword} = #{keyword}"
16
- end
17
-
18
- lines.join("\n")
19
- end
20
- end
21
- end
@@ -1,68 +0,0 @@
1
- module Verbalize
2
- class BuildMethodBase
3
- def self.call(required_keywords: [], optional_keywords: [])
4
- new(
5
- required_keywords: required_keywords,
6
- optional_keywords: optional_keywords
7
- ).call
8
- end
9
-
10
- def initialize(required_keywords: [], optional_keywords: [])
11
- @required_keywords = required_keywords
12
- @optional_keywords = optional_keywords
13
- end
14
-
15
- def call
16
- parts.compact.join "\n"
17
- end
18
-
19
- private
20
-
21
- attr_reader :required_keywords, :optional_keywords
22
-
23
- def parts
24
- [declaration, body, "end\n"]
25
- end
26
-
27
- def declaration
28
- raise NotImplementedError
29
- end
30
-
31
- def body
32
- raise NotImplementedError
33
- end
34
-
35
- def declare(method_name)
36
- "def #{method_name}(#{declaration_keyword_arguments})"
37
- end
38
-
39
- def all_keywords
40
- required_keywords + optional_keywords
41
- end
42
-
43
- def required_keyword_segments
44
- required_keywords.map { |keyword| "#{keyword}:" }
45
- end
46
-
47
- def optional_keyword_segments
48
- optional_keywords.map { |keyword| "#{keyword}: nil" }
49
- end
50
-
51
- def declaration_keyword_arguments
52
- return if all_keywords.empty?
53
- (required_keyword_segments + optional_keyword_segments).join(', ')
54
- end
55
-
56
- def initialize_keywords_and_values
57
- all_keywords.map { |variable| "#{variable}: #{variable}" }.join(', ')
58
- end
59
-
60
- def verbalized_send_string(bang: false)
61
- send_string = ' __verbalized_send'
62
- send_string += '!' if bang
63
-
64
- return send_string if all_keywords.empty?
65
- send_string + "(#{initialize_keywords_and_values})"
66
- end
67
- end
68
- end
@@ -1,15 +0,0 @@
1
- require_relative 'build_method_base'
2
-
3
- module Verbalize
4
- class BuildSafeActionMethod < BuildMethodBase
5
- private
6
-
7
- def declaration
8
- declare('self.call')
9
- end
10
-
11
- def body
12
- verbalized_send_string(bang: false)
13
- end
14
- end
15
- end