hammy 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dc787edc7fd7d6ddbd692313209f890c4de8c426d6f382ab456918927902c463
4
+ data.tar.gz: e5cbf31778c2347ff1d95f7f097c96a59e29849bd3292fc4084f0dd139847c1c
5
+ SHA512:
6
+ metadata.gz: 6d494343ae80d5a386e99ee1a8687bbdc39b7310103f7986ff7632d67c16a08e14138841c36667573d62d05d1b66f5d3ab6675757ce16e1763014e8a62fe76cc
7
+ data.tar.gz: f5ef424dd216fc2be77094a02b0468c7af710546159ce40c3adf22eb27895a6ffd68cbace82620baa4c5458cf7de8d1dbbe39162dad19425a08353fcb5cf341d
@@ -0,0 +1,28 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ release:
10
+ name: Check and Release New Version
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout Code
14
+ uses: actions/checkout@v2
15
+ with:
16
+ fetch-depth: 2
17
+
18
+ - name: Setup Ruby
19
+ uses: actions/setup-ruby@v1
20
+ with:
21
+ ruby-version: 2.6
22
+
23
+ - name: Release Gem
24
+ id: release-gem
25
+ uses: salsify/action-release-gem@76815459482984159ec020def58da8aed594e618
26
+ env:
27
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28
+ RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,39 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ Exclude:
4
+ - 'vendor/**/*'
5
+ - 'gemfiles/vendor/**/*'
6
+
7
+ Layout/EmptyLinesAroundClassBody:
8
+ EnforcedStyle: beginning_only
9
+
10
+ Layout/MultilineMethodCallIndentation:
11
+ EnforcedStyle: indented_relative_to_receiver
12
+
13
+ Metrics/AbcSize:
14
+ Enabled: false
15
+
16
+ Metrics/LineLength:
17
+ Enabled: false
18
+
19
+ Metrics/MethodLength:
20
+ Enabled: false
21
+
22
+ Style/Documentation:
23
+ Enabled: false
24
+
25
+ Style/FrozenStringLiteralComment:
26
+ Enabled: true
27
+
28
+ Style/ModuleFunction:
29
+ Enabled: false
30
+
31
+ Style/RaiseArgs:
32
+ Enabled: false
33
+
34
+ Style/StringLiterals:
35
+ EnforcedStyle: double_quotes
36
+
37
+ Style/SymbolArray:
38
+ Enabled: false
39
+
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ hammy
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.6.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
6
+
7
+ ## 0.2.0 - 2021-02-05
8
+ ### Added
9
+ - Add release automation
10
+
11
+ ## 0.1.0 - 2019-02-23
12
+ ### Added
13
+ - Initial version
14
+ - Add `ServiceObject`
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # override the :github shortcut to be secure by using HTTPS
6
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
7
+
8
+ # Specify your gem's dependencies in hammy.gemspec
9
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ guard :rubocop do
4
+ watch(/.+\.rb$/)
5
+ watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
6
+ end
7
+
8
+ guard :rspec, cmd: "bundle exec rspec --format progress", notification: true do
9
+ watch("spec/spec_helper.rb") { "spec" }
10
+ watch(%r{^spec\/.+_spec\.rb$})
11
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
12
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Erik Kessler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Hammy
2
+
3
+ Various Ruby stuff.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'hammy'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install hammy
20
+
21
+ ## Usage
22
+
23
+ ### ServiceObject
24
+
25
+ Easily build "thing doer" classes by subclassing `Hammy::ServiceObject#build`.
26
+ Available argument styles: `keyword` and `positional`.
27
+
28
+ ```ruby
29
+ class ThingDoer < Hammy::ServiceObject.keyword(:one, :two)
30
+
31
+ def do_the_thing
32
+ puts "Doing the thing with #{one} and #{two}..."
33
+ end
34
+ end
35
+
36
+ ThingDoer.do_the_thing(one: :a, two: :b)
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
42
+ run `rake spec` to run the tests. You can also run `bin/console` for an
43
+ interactive prompt that will allow you to experiment.
44
+
45
+ To install this gem onto your local machine, run `bundle exec rake install`.
46
+
47
+ To release a new version, update the version number in `version.rb`, and then
48
+ run `bundle exec rake release`, which will create a git tag for the version,
49
+ push git commits and tags, and push the `.gem` file to
50
+ [rubygems.org](https://rubygems.org)
51
+ .
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at
56
+ https://github.com/erikkessler1/hammy.## License
57
+
58
+ The gem is available as open source under the terms of the
59
+ [MIT License](http://opensource.org/licenses/MIT).
60
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "pry"
6
+
7
+ require "hammy"
8
+
9
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -v
5
+
6
+ bundle update
data/hammy.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "hammy/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ raise "RubyGems 2.0 or newer is required!" unless spec.respond_to?(:metadata)
9
+
10
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
11
+
12
+ spec.name = "hammy"
13
+ spec.version = Hammy::VERSION
14
+ spec.authors = ["Erik Kessler"]
15
+ spec.email = ["erik.kessler1@gmail.com"]
16
+
17
+ spec.summary = "Some Ruby utils and fun."
18
+ spec.description = spec.summary
19
+ spec.homepage = "https://github.com/erikkessler1/hammy"
20
+
21
+ spec.license = "MIT"
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.bindir = "bin"
25
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.required_ruby_version = ">= 2.5"
29
+
30
+ spec.add_development_dependency "bundler"
31
+ spec.add_development_dependency "guard"
32
+ spec.add_development_dependency "guard-rspec"
33
+ spec.add_development_dependency "guard-rubocop"
34
+ spec.add_development_dependency "pry"
35
+ spec.add_development_dependency "rake"
36
+ spec.add_development_dependency "rspec", "~> 3.8"
37
+ spec.add_development_dependency "rubocop"
38
+ end
data/lib/hammy.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./hammy/service_object"
4
+ require_relative "./hammy/version"
5
+
6
+ module Hammy
7
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hammy
4
+ class AbstractServiceObject
5
+
6
+ def self.build(*args, **kargs)
7
+ new(*args, **kargs).klass
8
+ end
9
+
10
+ def initialize(*args, **kargs)
11
+ @args = args
12
+ @kargs = kargs
13
+ end
14
+
15
+ def klass
16
+ this = self
17
+
18
+ Class.new do
19
+ eigenclass = class << self; self; end
20
+ eigenclass.class_eval do
21
+ define_method(:method_missing) do |method, *args, **kargs, &block|
22
+ return super(method, *args, **kargs, &block) unless this.valid_action?(self, method)
23
+
24
+ new(args, kargs).send(method)
25
+ end
26
+
27
+ define_method(:respond_to_missing?) do |method, include_private = false|
28
+ this.valid_action?(self, method) || super(method, include_private)
29
+ end
30
+ end
31
+
32
+ define_method(:initialize) do |args, kargs|
33
+ this.validate_args!(args, kargs)
34
+
35
+ this.initial_instance_variables(args, kargs).each do |var, value|
36
+ instance_variable_set(var, value)
37
+ end
38
+ end
39
+
40
+ this.public_getters.each do |getter|
41
+ attr_reader(getter)
42
+ end
43
+
44
+ protected
45
+
46
+ this.protected_getters.each do |getter|
47
+ attr_reader(getter)
48
+ end
49
+
50
+ private
51
+
52
+ this.private_getters.each do |getter|
53
+ attr_reader(getter)
54
+ end
55
+ end
56
+ end
57
+
58
+ def valid_action?(klass, method)
59
+ klass.instance_methods(false).include?(method)
60
+ end
61
+
62
+ def validate_args!(args, kargs); end
63
+
64
+ def initial_instance_variables(_args, _kargs)
65
+ {}
66
+ end
67
+
68
+ def public_getters
69
+ []
70
+ end
71
+
72
+ def protected_getters
73
+ []
74
+ end
75
+
76
+ def private_getters
77
+ []
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./abstract_service_object"
4
+
5
+ module Hammy
6
+ class KeywordServiceObject < Hammy::AbstractServiceObject
7
+
8
+ def validate_args!(args, kargs)
9
+ raise ArgumentError.new("wrong number of arguments (given #{args.size}, expected 0; required keywords: #{@args.join(', ')})") unless args.empty?
10
+
11
+ missing = @args - kargs.keys
12
+ raise ArgumentError.new("missing keywords: #{missing.join(', ')}") unless missing.empty?
13
+
14
+ unknown = kargs.keys - @args
15
+ raise ArgumentError.new("unknown keywords: #{unknown.join(', ')}") unless unknown.empty?
16
+ end
17
+
18
+ def initial_instance_variables(_args, kargs)
19
+ @args.map do |a|
20
+ ["@#{a}", kargs[a]]
21
+ end
22
+ end
23
+
24
+ def private_getters
25
+ @args
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./abstract_service_object"
4
+
5
+ module Hammy
6
+ class PositionalServiceObject < Hammy::AbstractServiceObject
7
+
8
+ def validate_args!(pargs, kargs)
9
+ args = all_args(pargs, kargs)
10
+ raise ArgumentError.new("wrong number of arguments (given #{args.size}, expected #{@args.size})") if args.size != @args.size
11
+ end
12
+
13
+ def initial_instance_variables(pargs, kargs)
14
+ args = all_args(pargs, kargs)
15
+ @args.zip(args).map { |a, b| ["@#{a}", b] }
16
+ end
17
+
18
+ def private_getters
19
+ @args
20
+ end
21
+
22
+ private
23
+
24
+ def all_args(pargs, kargs)
25
+ return pargs unless kargs.any?
26
+
27
+ pargs + [kargs]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./keyword_service_object"
4
+ require_relative "./positional_service_object"
5
+
6
+ module Hammy
7
+ module ServiceObject
8
+ extend self
9
+
10
+ def positional(*args, **kargs)
11
+ Hammy::PositionalServiceObject.build(*args, **kargs)
12
+ end
13
+
14
+ def keyword(*args, **kargs)
15
+ Hammy::KeywordServiceObject.build(*args, **kargs)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hammy
4
+ VERSION = "0.2.0"
5
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hammy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Erik Kessler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.8'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.8'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Some Ruby utils and fun.
126
+ email:
127
+ - erik.kessler1@gmail.com
128
+ executables:
129
+ - console
130
+ - setup
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".github/workflows/release.yml"
135
+ - ".gitignore"
136
+ - ".rspec"
137
+ - ".rubocop.yml"
138
+ - ".ruby-gemset"
139
+ - ".ruby-version"
140
+ - CHANGELOG.md
141
+ - Gemfile
142
+ - Guardfile
143
+ - LICENSE.txt
144
+ - README.md
145
+ - Rakefile
146
+ - bin/console
147
+ - bin/setup
148
+ - hammy.gemspec
149
+ - lib/hammy.rb
150
+ - lib/hammy/abstract_service_object.rb
151
+ - lib/hammy/keyword_service_object.rb
152
+ - lib/hammy/positional_service_object.rb
153
+ - lib/hammy/service_object.rb
154
+ - lib/hammy/version.rb
155
+ homepage: https://github.com/erikkessler1/hammy
156
+ licenses:
157
+ - MIT
158
+ metadata:
159
+ allowed_push_host: https://rubygems.org
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '2.5'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubygems_version: 3.0.3
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: Some Ruby utils and fun.
179
+ test_files: []