superlime 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bc812e30e0e32bfedeae06f12f53fcf3c76ee61deaf1df87bf5a47236ec29b86
4
+ data.tar.gz: 966de652036a5b8be1e42a7405ada5f9d43272541f836325cb626ba46d593bff
5
+ SHA512:
6
+ metadata.gz: 870f31129f15de7dcf97a77ac9adbd6dfb5081f538d277628305799dc234ba5cba21f29a54da797a26745520d0fd11b8e8e2192e6326e00bc97a91219676efd6
7
+ data.tar.gz: 968fef5cdde05593ec65e5a135c60a797e74bc132454091449a5910167810785d445ae06577184bb5622e622a34abcf7e9bc0a7e45d4989e0ee3f16076dacdb2
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.idea
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in superlime.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ superlime (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.14.0)
10
+ rake (13.0.1)
11
+
12
+ PLATFORMS
13
+ x64-mingw32
14
+
15
+ DEPENDENCIES
16
+ minitest (~> 5.0)
17
+ rake (~> 13.0)
18
+ superlime!
19
+
20
+ BUNDLED WITH
21
+ 2.2.0.rc.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Lee Machin
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.
@@ -0,0 +1,68 @@
1
+ # Superlime
2
+
3
+ A replacement for [Rectify::Command](https://github.com/andypike/rectify#commands) that uses Ruby 2.7 pattern matching in place of events.
4
+ Uses a mostly-compatible API.
5
+
6
+ ## Usage
7
+
8
+ When creating a command, have it inherit from `Superlime::Command` (instead of `Rectify::Command` if refactoring).
9
+
10
+ ```ruby
11
+ class Payment::Send < Superlime::Command
12
+ attr_reader :params
13
+
14
+ def initialize(params)
15
+ @params = params
16
+ end
17
+
18
+ def call
19
+ broadcast(:no_payee) if params[:payee].nil?
20
+ transaction = make_payment!
21
+ broadcast(:success, tx_id: transaction.id)
22
+ rescue PaymentError, SomeSillyError => err
23
+ broadcast(:error, err)
24
+ end
25
+
26
+ private
27
+
28
+ def make_payment!
29
+ # do the payment...
30
+ # raise if payment_failed
31
+ end
32
+ end
33
+ ```
34
+
35
+ The behaviour is mostly the same, except you don't require a `return` invocation when calling `broadcast`.
36
+
37
+ In order to use this command, you can use Ruby's brand new pattern matching niceness. It's a little bit different but
38
+ offers a lot of flexibility depending on the complexity of your command.
39
+
40
+ ```ruby
41
+ class PaymentController < ApplicationController
42
+ def create
43
+ case Payment::Send.call(payment_params)
44
+ in success: result then render json: result
45
+ in :no_payee then head :bad_request
46
+ in error: PaymentError => err then render json: err.message, status: :internal_server_error
47
+ in error: SomeSillyError then redirect_to 'http://www.zombo.com'
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def payment_params
54
+ params.require(:payment).permit(:payee, :card_details_and_stuff)
55
+ end
56
+ end
57
+ ```
58
+
59
+ Ruby's pattern matching allows you to match against types, hashes, arrays, while also being able to destructure them,
60
+ so these destructurings can be as simple or complex as you like (including destructuring of custom classes).
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mrleedev/superlime.
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,23 @@
1
+ # Ruby
2
+ # Package your Ruby project.
3
+ # Add steps that install rails, analyze code, save build artifacts, deploy, and more:
4
+ # https://docs.microsoft.com/azure/devops/pipelines/languages/ruby
5
+
6
+ trigger:
7
+ - master
8
+
9
+ pool:
10
+ vmImage: 'ubuntu-latest'
11
+
12
+ steps:
13
+ - task: UseRubyVersion@0
14
+ inputs:
15
+ versionSpec: '>= 2.5'
16
+
17
+ - script: |
18
+ gem install bundler
19
+ bundle install --retry=3 --jobs=4
20
+ displayName: 'bundle install'
21
+
22
+ - script: bundle exec rake
23
+ displayName: 'bundle exec rake'
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ #!/usr/bin/env ruby
4
+
5
+ require "bundler/setup"
6
+ require "superlime"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require "irb"
16
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'superlime/version'
4
+ require 'superlime/command'
5
+
6
+ module Superlime
7
+ end
@@ -0,0 +1,23 @@
1
+ module Superlime
2
+ class Command
3
+ def self.call(args)
4
+ catch(:broadcast) do
5
+ new(args).call
6
+ end
7
+ end
8
+
9
+ def initialize(*args)
10
+ raise NotImplementedError, "must implement #initialize on subclass"
11
+ end
12
+
13
+ def call
14
+ raise NotImplementedError, "must implement #call on subclass"
15
+ end
16
+
17
+ private
18
+
19
+ def broadcast(event, payload)
20
+ throw(:broadcast, event => payload)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superlime
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/superlime/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "superlime"
7
+ spec.version = Superlime::VERSION
8
+ spec.authors = ["Lee Machin"]
9
+ spec.email = ["me@mrlee.dev"]
10
+
11
+ spec.summary = "Pattern-based controller commands"
12
+ spec.homepage = "https://github.com/mrleedev/superlime"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/mrleedev/superlime"
18
+ spec.metadata["changelog_uri"] = "https://github.com/mrleedev/superlime"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: superlime
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lee Machin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-08-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - me@mrlee.dev
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - Gemfile.lock
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - azure-pipelines.yml
27
+ - bin/console
28
+ - bin/setup
29
+ - lib/superlime.rb
30
+ - lib/superlime/command.rb
31
+ - lib/superlime/version.rb
32
+ - superlime.gemspec
33
+ homepage: https://github.com/mrleedev/superlime
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://github.com/mrleedev/superlime
38
+ source_code_uri: https://github.com/mrleedev/superlime
39
+ changelog_uri: https://github.com/mrleedev/superlime
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.3.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.1.2
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Pattern-based controller commands
59
+ test_files: []