verbalize 2.1.1 → 2.2.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
  SHA1:
3
- metadata.gz: fbb81a57e922f9eb1725daf38886898e1ec0e0d8
4
- data.tar.gz: 1ce4904ec6243de8e40e269b7e773ebd516d0d9b
3
+ metadata.gz: 69dc4bbf8a11fde19d5c0b7f84e0f5ea76cdbd4f
4
+ data.tar.gz: 7aaa0f4b6d81861140a5b37c555371cec36aa6a2
5
5
  SHA512:
6
- metadata.gz: 2b9acacd50f16370208e8adde4c37b2822051ec77fd0fa9979e2fcddac898053ecdb3413a6db3d87ec821bceed104c453881d7ced95dfef726bda5eb6c2f24b6
7
- data.tar.gz: a89f9934e93a7dbbb1124ff443cc9551ae2e3af5fb3346ffb0b1445787c77095b3dc6b6c2e9012f1ad84770207d7b9b489c475249036c8d9a4383884eb757c3c
6
+ metadata.gz: 7a39dcb9fb9c3458c00a9cda65018a3b2e68f5487b1e2f7a483d65d5590e196283de48dfb8b61d847771718313c7dbcb8532d02b4a1506357b022742e924927b
7
+ data.tar.gz: 412d8f380f07a076783c6ff5335a19d29c93cc2220211c9e79a7b72e59f396edf208f1147e415b06937489e03fbc2ad8cbcdc9e1823f2d569592e2d8e3efd70d
data/CHANGELOG.md ADDED
@@ -0,0 +1,81 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/).
6
+
7
+ ## 2.2.0 - 2017-08-19
8
+ ### Added
9
+ - changelog started
10
+ - You can now specify default values for optional inputs in the `input` call.
11
+ Use a regular value to load it once, at load-time, and a lambda to lazily load
12
+ the value each time the action is called.
13
+ ### Changed
14
+ - privatize Action.input. Now that we have Action.inputs, we want to avoid calling Action.input (no s) outside of the action itself
15
+
16
+ ## 2.1.1 - 2017-02-21
17
+ ### Fixed
18
+ - ensure Verbalize::Action.optional_input always returns an array
19
+
20
+ ## 2.1.0 - 2017-02-21
21
+ ### Added
22
+ - introspect Action input using Action.inputs, Action.required_inputs, and Action.optional_inputs
23
+
24
+ ## 2.0.2 - 2017-2-21 [YANKED]
25
+ - new functionality was added, so minor version should have been increased instead of patch
26
+
27
+ ## 2.0.1 - 2016-12-16
28
+ ### Changed
29
+ - internal refactoring
30
+
31
+ ## 2.0.0 - 2016-02-14
32
+ ### Added
33
+ - execution of action routed through Action#perform to better support stubbing
34
+ - 100% test coverage!!!
35
+ ### Changed
36
+ - calling Failure#value now raises an error, use Failure#failure instead? Did this happen in 1.3?
37
+ ### Removed
38
+ - removes action implementation methods other than #call/#call!
39
+
40
+ ## 1.4.1 - 2016-12-14
41
+ ### Added
42
+ - Failure#failure added to replace Failure#value
43
+ ### Changed
44
+ - Result split into Success/Failure
45
+ ### Deprecated
46
+ - stop including Verbalize itself, use Verbalize::Action instead
47
+ - stop using action implementation methods other than #call/#call!
48
+ - stop using Failure#value, used Failure#failure instead
49
+
50
+ ## 1.4.0 [YANKED] - 2016-12-14
51
+ ### Fixed
52
+ - error while uploading to ruby gems, yanked and released v1.4.1
53
+
54
+ ## 1.3.0 - 2016-11-09
55
+ ### Changed
56
+ - better failure handling
57
+
58
+ ## 1.2.0 - 2016-11-07
59
+ ### Added
60
+ - alias Result.success? to Result.succeeded?
61
+ - alias Result.failure? to Result.failed?
62
+ ### Changed
63
+ - Action now implements #to_ary instead of subclassing Array
64
+
65
+ ## 1.1.2 - 2016-11-07 [YANKED]
66
+ - new functionality was added, so minor version should have been increased instead of patch
67
+
68
+ ## 1.1.1 - 2016-08-25
69
+ ### Changed
70
+ - internal refactoring
71
+
72
+ ## 1.0.1 - 2016-08-10
73
+ ### Fixed
74
+ - Use send to call Action#call so that Action#call can be privatized
75
+
76
+ ## 1.0.0 - 2016-08-09
77
+ ### Added
78
+ - optional input
79
+
80
+ ## 0.1.0 - 2016-08-07
81
+ - initial release
data/README.md CHANGED
@@ -53,6 +53,35 @@ Add.call # => [:ok, 42]
53
53
  Add.call(a: 660, b: 6) # => [:ok, 666]
54
54
  ```
55
55
 
56
+ ## Default Values
57
+
58
+ ```ruby
59
+ # You can define defaults via key/value pairs, as so:
60
+ class Add
61
+ include Verbalize::Action
62
+ # note that these values are evaluated at load-time as they are not wrapped
63
+ # in lambdas.
64
+ input optional: [a: 35, b: 7]
65
+ def call; a + b; end
66
+ end
67
+
68
+ # default values can be lazily loaded by passing in a lambda, e.g.:
69
+
70
+ class Tomorrow
71
+ include Verbalize::Action
72
+ input optional: [as_of: -> { Time.now }]
73
+ def call
74
+ as_of + 1
75
+ end
76
+ end
77
+
78
+ start_time = Tomorrow.call!
79
+ sleep(1)
80
+ end_time = Tomorrow.call!
81
+ end_time - start_time # ~1s; the default is executed each call.
82
+ ```
83
+
84
+
56
85
  ```ruby
57
86
  class Divide
58
87
  include Verbalize::Action
@@ -324,6 +353,13 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
324
353
 
325
354
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
326
355
 
356
+ ## Releasing
357
+
358
+ - Update changelog, and VERSION
359
+ - Commit to master and push to github
360
+ - [Create a new release on github](https://github.com/taylorzr/verbalize/releases/new)
361
+ -
362
+
327
363
  ## Contributing
328
364
 
329
365
  Bug reports and pull requests are welcome on GitHub at https://github.com/taylorzr/verbalize.
data/bin/console CHANGED
@@ -6,9 +6,5 @@ require 'verbalize'
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require 'irb'
14
- IRB.start
9
+ require 'pry'
10
+ Pry.start
@@ -16,14 +16,6 @@ module Verbalize
16
16
  end
17
17
 
18
18
  module ClassMethods
19
- def input(*required_keywords, optional: [])
20
- @required_inputs = required_keywords
21
- optional = Array(optional)
22
- @optional_inputs = optional
23
-
24
- class_eval Build.call(required_keywords, optional)
25
- end
26
-
27
19
  def required_inputs
28
20
  @required_inputs || []
29
21
  end
@@ -32,8 +24,16 @@ module Verbalize
32
24
  @optional_inputs || []
33
25
  end
34
26
 
27
+ def default_inputs
28
+ (@defaults || {}).keys
29
+ end
30
+
35
31
  def inputs
36
- required_inputs + optional_inputs
32
+ required_inputs + optional_inputs + default_inputs
33
+ end
34
+
35
+ def defaults
36
+ @defaults
37
37
  end
38
38
 
39
39
  # Because call/call! are defined when Action.input is called, they would
@@ -50,6 +50,22 @@ module Verbalize
50
50
 
51
51
  private
52
52
 
53
+ def input(*required_keywords, optional: [])
54
+ @required_inputs = required_keywords
55
+ optional = Array(optional)
56
+ @optional_inputs = optional.reject { |kw| kw.is_a?(Hash) }
57
+ assign_defaults(optional)
58
+
59
+ class_eval Build.call(required_inputs, optional_inputs, default_inputs)
60
+ end
61
+
62
+ def assign_defaults(optional)
63
+ @defaults = optional.select { |kw| kw.is_a?(Hash) }.reduce(&:merge)
64
+ @defaults = (@defaults || {})
65
+ .map { |k, v| [k, v.respond_to?(:call) ? v : -> { v }] }
66
+ .to_h
67
+ end
68
+
53
69
  def perform(*args)
54
70
  new(*args).send(:call)
55
71
  end
@@ -1,12 +1,13 @@
1
1
  module Verbalize
2
2
  class Build
3
- def self.call(required_keywords = [], optional_keywords = [])
4
- new(required_keywords, optional_keywords).call
3
+ def self.call(required_keywords = [], optional_keywords = [], default_keywords = [])
4
+ new(required_keywords, optional_keywords, default_keywords).call
5
5
  end
6
6
 
7
- def initialize(required_keywords, optional_keywords)
7
+ def initialize(required_keywords, optional_keywords, default_keywords)
8
8
  @required_keywords = required_keywords
9
9
  @optional_keywords = optional_keywords
10
+ @default_keywords = default_keywords
10
11
  end
11
12
 
12
13
  def call
@@ -34,18 +35,19 @@ attr_reader #{attribute_readers_string}
34
35
  CODE
35
36
  end
36
37
 
37
- attr_reader :required_keywords, :optional_keywords
38
+ attr_reader :required_keywords, :optional_keywords, :default_keywords
38
39
 
39
40
  private
40
41
 
41
42
  def all_keywords
42
- required_keywords + optional_keywords
43
+ required_keywords + optional_keywords + default_keywords
43
44
  end
44
45
 
45
46
  def declaration_arguments_string
46
- required_segments = required_keywords.map { |keyword| "#{keyword}:" }
47
- optional_segments = optional_keywords.map { |keyword| "#{keyword}: nil" }
48
- (required_segments + optional_segments).join(', ')
47
+ required_segments = required_keywords.map { |keyword| "#{keyword}:" }
48
+ optional_segments = optional_keywords.map { |keyword| "#{keyword}: nil" }
49
+ default_segments = default_keywords.map { |keyword| "#{keyword}: self.defaults[:#{keyword}].call" }
50
+ (required_segments + optional_segments + default_segments).join(', ')
49
51
  end
50
52
 
51
53
  def forwarding_arguments_string
@@ -1,3 +1,3 @@
1
1
  module Verbalize
2
- VERSION = '2.1.1'.freeze
2
+ VERSION = '2.2.0'.freeze
3
3
  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.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-21 00:00:00.000000000 Z
11
+ date: 2017-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,6 +106,7 @@ files:
106
106
  - ".rspec"
107
107
  - ".rubocop.yml"
108
108
  - ".travis.yml"
109
+ - CHANGELOG.md
109
110
  - Gemfile
110
111
  - LICENSE.txt
111
112
  - README.md
@@ -142,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
143
  version: '0'
143
144
  requirements: []
144
145
  rubyforge_project:
145
- rubygems_version: 2.4.8
146
+ rubygems_version: 2.6.11
146
147
  signing_key:
147
148
  specification_version: 4
148
149
  summary: Verb based class pattern