operatic 0.2.0 → 0.4.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: f5f46398654b0cda4099550dc86d85e82833fa9671722f901dfeb09a0c9ef6e5
4
- data.tar.gz: c5098edb779caedbefc2ddf39861ffd6e005315f5928da73b5eaaa04046c68fc
3
+ metadata.gz: aeb2128119d4f471de6cd2ef4bc70e7d2a5ad73bf3a21867cbd8ead4d6e2a387
4
+ data.tar.gz: 53ba7951114c31a60a360f95c801b4900603daf010e9f8d4f8aeded22ea657db
5
5
  SHA512:
6
- metadata.gz: 93c89546ab8bc0a51fd1e58e059a5ec5da145443fdffadc4072e8af304fad195d1034f31b37a446870fe7e230292d7a40bf0168cfc1cc536ceab4e7b251907fb
7
- data.tar.gz: 8a14b3e513e2416c55fc768612f0445697da7dabd331594d651c88f8da42c866db3bef42933d22ba44b3ef29b37dc5a6aa77b00af93360b7738c1563d32280c3
6
+ metadata.gz: 2f50a0a06fc96f281822f2ccc5696e2608d387b7720c49bf861f735a566e6d717fe90c3d57aed36ffcd09ddfebe9501c27d8e8cc7abfb7c1fb28c9e349a25972
7
+ data.tar.gz: f47a4fb2db7a8facc43235ae6bbd9d8c0f86e3a55c998a73666e360caee833227c1385a64b4c6b47212c41ecd640832f3248fc16f68db09745a75cf1ecce5c1f
@@ -1,6 +1,6 @@
1
1
  name: Ruby
2
2
 
3
- on: [push]
3
+ on: push
4
4
 
5
5
  jobs:
6
6
  rspec:
@@ -8,24 +8,16 @@ jobs:
8
8
  strategy:
9
9
  matrix:
10
10
  ruby:
11
- - '2.5.x'
12
- - '2.6.x'
13
-
11
+ - '2.5'
12
+ - '2.6'
13
+ - '2.7'
14
+ - '3.0'
15
+ - '3.1'
14
16
  name: Ruby ${{ matrix.ruby }} RSpec
15
-
16
17
  steps:
17
- - uses: actions/checkout@v1
18
-
19
- - name: Set up Ruby
20
- uses: actions/setup-ruby@v1
18
+ - uses: actions/checkout@v2
19
+ - uses: ruby/setup-ruby@v1
21
20
  with:
21
+ bundler-cache: true
22
22
  ruby-version: ${{ matrix.ruby }}
23
-
24
- - name: Install latest bundler
25
- run: gem install bundler
26
-
27
- - name: Install operatic dependencies
28
- run: bundle install --jobs 4
29
-
30
- - name: Run RSpec
31
- run: bundle exec rspec
23
+ - run: bundle exec rspec
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # CHANGELOG
2
+
3
+ ## Version 0.4.0 - 2022-05-25
4
+
5
+ - Switch to keyword arguments. <https://github.com/benpickles/operatic/pull/8>
6
+
7
+ ## Version 0.3.1 - 2020-01-05
8
+
9
+ - Less specific Rake dependency. <https://github.com/benpickles/operatic/pull/6>
10
+
11
+ ## Version 0.3.0 - 2019-11-27
12
+
13
+ - Implement `#to_h` not `#to_hash`. <https://github.com/benpickles/operatic/pull/4>
14
+
15
+ ## Version 0.2.0 - 2019-11-23
16
+
17
+ First official version hosted on [RubyGems.org](https://rubygems.org/gems/operatic).
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![GitHub Actions status](https://github.com/benpickles/operatic/workflows/Ruby/badge.svg)](https://github.com/benpickles/operatic)
4
4
 
5
+ A minimal standard interface for your operations.
6
+
5
7
  ## Installation
6
8
 
7
9
  Add Operatic to your application's Gemfile and run `bundle install`.
@@ -36,13 +38,13 @@ end
36
38
  result = SayHello.call(name: 'Dave')
37
39
  result.success? # => true
38
40
  result.message # => "Hello Dave"
39
- result.to_hash # => {:message=>"Hello Dave"}
41
+ result.to_h # => {:message=>"Hello Dave"}
40
42
 
41
43
  result = SayHello.call
42
44
  result.failure? # => true
43
45
  result.success? # => false
44
46
  result.message # => nil
45
- result.to_hash # => {}
47
+ result.to_h # => {}
46
48
  ```
47
49
 
48
50
  A Rails controller might use Operatic like this:
@@ -4,7 +4,7 @@ module Operatic
4
4
  # wouldn't normally be called directly, see {ClassMethods#result} for
5
5
  # example usage.
6
6
  #
7
- # @param attrs [Array<Symbol>] a list of accessors to the result's data.
7
+ # @param attrs [Array<Symbol>] a list of convenience data accessors.
8
8
  def self.generate(*attrs)
9
9
  Class.new(self) do
10
10
  attrs.each do |name|
@@ -24,16 +24,13 @@ module Operatic
24
24
  @success = true
25
25
  end
26
26
 
27
- # Mark the result as a failure, optionally attach data, and freeze the
28
- # object so it cannot be modified further.
27
+ # Mark the result as a failure, optionally attach +data+ via kwargs, and
28
+ # freeze the object so it cannot be modified further.
29
29
  #
30
- # *Note*: After calling this method calling {#success!} or {#failure!}
31
- # again will raise a +FrozenError+.
32
- #
33
- # @param data [Hash<Symbol, anything>] an optional hash of data to attach
34
- # to the result.
35
- def failure!(data = nil)
36
- set_data(data) if data
30
+ # *Note*: Calling {#success!} or {#failure!} more than once will raise a
31
+ # +FrozenError+.
32
+ def failure!(**data)
33
+ set_data(**data)
37
34
  @success = false
38
35
  freeze
39
36
  end
@@ -47,20 +44,17 @@ module Operatic
47
44
  super
48
45
  end
49
46
 
50
- # Mark the result as a success, optionally attach data, and freeze the
51
- # object so it cannot be modified further.
47
+ # Mark the result as a success, optionally attach +data+ via kwargs, and
48
+ # freeze the object so it cannot be modified further.
52
49
  #
53
- # Calling this is not strictly necessary as a result defaults to being a
50
+ # Calling this is not strictly necessary as a +Result+ defaults to being a
54
51
  # success, but it's a convenient means of attaching data and of indicating
55
52
  # intent in the consuming code.
56
53
  #
57
- # *Note*: After calling this method calling {#success!} or {#failure!}
58
- # again will raise a +FrozenError+.
59
- #
60
- # @param data [Hash<Symbol, anything>] an optional hash of data to attach
61
- # to the result.
62
- def success!(data = nil)
63
- set_data(data) if data
54
+ # *Note*: Calling {#success!} or {#failure!} more than once will raise a
55
+ # +FrozenError+.
56
+ def success!(**data)
57
+ set_data(**data)
64
58
  @success = true
65
59
  freeze
66
60
  end
@@ -69,16 +63,16 @@ module Operatic
69
63
  @success
70
64
  end
71
65
 
72
- # Returns the full hash of data attached to the result via {#success!},
73
- # {#failure!}, or convenience accessors added with {.generate}.
66
+ # Returns the full (frozen) hash of data attached to the result via
67
+ # {#success!}, {#failure!}, or convenience accessors added with {.generate}.
74
68
  #
75
- # @return [Hash]
76
- def to_hash
69
+ # @return [Hash<Symbol, anything>]
70
+ def to_h
77
71
  @data
78
72
  end
79
73
 
80
74
  private
81
- def set_data(data)
75
+ def set_data(**data)
82
76
  data.each do |key, value|
83
77
  @data[key] = value
84
78
  end
@@ -1,3 +1,3 @@
1
1
  module Operatic
2
- VERSION = '0.2.0'
2
+ VERSION = '0.4.0'
3
3
  end
data/lib/operatic.rb CHANGED
@@ -11,15 +11,12 @@ module Operatic
11
11
  module ClassMethods
12
12
  # The main way of calling an operation.
13
13
  #
14
- # The class is instantiated with supplied +attrs+ and calls {Operatic#call}
15
- # returning a frozen {Result} instance.
14
+ # The class is instantiated with the supplied +attrs+ keyword arguments and
15
+ # calls {Operatic#call} returning a frozen {Result} instance.
16
16
  #
17
- # @param attrs [Hash<Symbol, anything>] an optional hash of key/values to
18
- # to the result. The class must have corresponding +attr_reader+s
19
- #
20
- # @return a [Result] which is fro
21
- def call(attrs = nil)
22
- new(attrs)
17
+ # @return [Result]
18
+ def call(**attrs)
19
+ new(**attrs)
23
20
  .tap(&:call)
24
21
  .result
25
22
  .freeze
@@ -30,8 +27,8 @@ module Operatic
30
27
  # test setups, etc.
31
28
  #
32
29
  # @return [Result]
33
- def call!(attrs = nil)
34
- call(attrs).tap { |result|
30
+ def call!(**attrs)
31
+ call(**attrs).tap { |result|
35
32
  raise FailureError if result.failure?
36
33
  }
37
34
  end
@@ -55,8 +52,11 @@ module Operatic
55
52
  # result = SayHello.call(name: 'Dave')
56
53
  # result.success? # => true
57
54
  # result.message # => "Hello Dave"
58
- def result(*args)
59
- @result_class = Result.generate(*args)
55
+ #
56
+ # @param attrs [Array<Symbol>] a list of convenience data accessors to
57
+ # define on the {Result}.
58
+ def result(*attrs)
59
+ @result_class = Result.generate(*attrs)
60
60
  end
61
61
 
62
62
  def result_class
@@ -69,17 +69,17 @@ module Operatic
69
69
  # @return [Result]
70
70
  attr_reader :result
71
71
 
72
- def initialize(attrs = nil)
72
+ def initialize(**attrs)
73
73
  @result = self.class.result_class.new
74
74
 
75
75
  attrs.each do |key, value|
76
76
  instance_variable_set("@#{key}", value)
77
- end if attrs
77
+ end
78
78
  end
79
79
 
80
80
  # Override this method with your implementation. Use {#success!} or
81
81
  # {#failure!} methods to communicate the {#result}'s status and to attach
82
- # data it. Define convenience result accessors with {ClassMethods#result}.
82
+ # data to it. Define convenience result accessors with {ClassMethods#result}.
83
83
  #
84
84
  # @example
85
85
  # class SayHello
@@ -87,6 +87,8 @@ module Operatic
87
87
  #
88
88
  # attr_reader :name
89
89
  #
90
+ # result :message
91
+ #
90
92
  # def call
91
93
  # return failure! unless name
92
94
  # success!(message: "Hello #{name}")
@@ -94,23 +96,26 @@ module Operatic
94
96
  # end
95
97
  #
96
98
  # result = SayHello.call(name: 'Dave')
99
+ # result.failure? # => false
97
100
  # result.success? # => true
98
- # result.to_hash # => {:message=>"Hello Dave"}
101
+ # result.message # => "Hello Dave"
102
+ # result.to_h # => {:message=>"Hello Dave"}
99
103
  #
100
104
  # result = SayHello.call
101
105
  # result.failure? # => true
102
106
  # result.success? # => false
103
- # result.to_hash # => {}
107
+ # result.message # => nil
108
+ # result.to_h # => {}
104
109
  def call
105
110
  end
106
111
 
107
112
  # Convenience shortcut to the operation's {Result#failure!}.
108
- def failure!(data = nil)
109
- result.failure!(data)
113
+ def failure!(**data)
114
+ result.failure!(**data)
110
115
  end
111
116
 
112
117
  # Convenience shortcut to the operation's {Result#success!}.
113
- def success!(data = nil)
114
- result.success!(data)
118
+ def success!(**data)
119
+ result.success!(**data)
115
120
  end
116
121
  end
data/operatic.gemspec CHANGED
@@ -8,22 +8,22 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ['Ben Pickles']
9
9
  spec.email = ['spideryoung@gmail.com']
10
10
 
11
- spec.summary = 'Operations'
12
- spec.description = ''
11
+ spec.summary = 'A minimal standard interface for your operations'
12
+ spec.description = spec.summary
13
13
  spec.homepage = 'https://github.com/benpickles/operatic'
14
14
  spec.license = 'MIT'
15
15
 
16
- # spec.metadata['allowed_push_host'] = 'TODO: Set to 'http://mygemserver.com''
17
-
18
- spec.metadata['homepage_uri'] = spec.homepage
19
- # spec.metadata['source_code_uri'] = 'TODO: Put your gem's public repo URL here.'
20
- # spec.metadata['changelog_uri'] = 'TODO: Put your gem's CHANGELOG.md URL here.'
16
+ spec.metadata = {
17
+ 'changelog_uri' => 'https://github.com/benpickles/operatic/blob/master/CHANGELOG.md',
18
+ 'documentation_uri' => 'https://rubydoc.info/gems/operatic',
19
+ 'source_code_uri' => 'https://github.com/benpickles/operatic',
20
+ }
21
21
 
22
22
  spec.required_ruby_version = '>= 2.5.0'
23
23
 
24
24
  # Specify which files should be added to the gem when it is released.
25
25
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
26
+ spec.files = Dir.chdir(__dir__) do
27
27
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
28
  end
29
29
  spec.bindir = 'exe'
@@ -31,6 +31,6 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ['lib']
32
32
 
33
33
  spec.add_development_dependency 'bundler'
34
- spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'rake'
35
35
  spec.add_development_dependency 'rspec', '~> 3.0'
36
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: operatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Pickles
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-23 00:00:00.000000000 Z
11
+ date: 2022-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
- description: ''
55
+ description: A minimal standard interface for your operations
56
56
  email:
57
57
  - spideryoung@gmail.com
58
58
  executables: []
@@ -62,6 +62,7 @@ files:
62
62
  - ".github/workflows/ruby.yml"
63
63
  - ".gitignore"
64
64
  - ".rspec"
65
+ - CHANGELOG.md
65
66
  - CODE_OF_CONDUCT.md
66
67
  - Gemfile
67
68
  - LICENSE.txt
@@ -78,8 +79,10 @@ homepage: https://github.com/benpickles/operatic
78
79
  licenses:
79
80
  - MIT
80
81
  metadata:
81
- homepage_uri: https://github.com/benpickles/operatic
82
- post_install_message:
82
+ changelog_uri: https://github.com/benpickles/operatic/blob/master/CHANGELOG.md
83
+ documentation_uri: https://rubydoc.info/gems/operatic
84
+ source_code_uri: https://github.com/benpickles/operatic
85
+ post_install_message:
83
86
  rdoc_options: []
84
87
  require_paths:
85
88
  - lib
@@ -94,8 +97,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
97
  - !ruby/object:Gem::Version
95
98
  version: '0'
96
99
  requirements: []
97
- rubygems_version: 3.0.3
98
- signing_key:
100
+ rubygems_version: 3.1.6
101
+ signing_key:
99
102
  specification_version: 4
100
- summary: Operations
103
+ summary: A minimal standard interface for your operations
101
104
  test_files: []