lasershark 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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lasershark.gemspec +27 -0
- data/lib/lasershark.rb +33 -0
- data/lib/lasershark/common_context.rb +158 -0
- data/lib/lasershark/context_methods.rb +11 -0
- data/lib/lasershark/version.rb +3 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4cc32e3d2b7b1000e189afcdda6faeddb437f665
|
4
|
+
data.tar.gz: 4dd2d1590e1ebe2ca46d271ae47f54624e50e463
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5ac08a10316c0fa9d0457f90bdb1f339fbc4f0dd107db72d259e3e2635fa3301fd3381bb0613b823517b741c9f2243b3cff9f2e81b2fca05627fd3c3ac561d62
|
7
|
+
data.tar.gz: 5ca38bd5c687d860b95c25b986153e888fd8356bd883e61004a0d91728776f2fa5b11d7e162cb0bf9fdf0108f4040d9fd741571394c3a6e8d584feef0f6e08eb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Jon Stokes
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Lasershark
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/lasershark`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'lasershark'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install lasershark
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/lasershark.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "lasershark"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
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(__FILE__)
|
data/bin/setup
ADDED
data/lasershark.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "lasershark/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lasershark"
|
8
|
+
spec.version = Lasershark::VERSION
|
9
|
+
spec.authors = ["Jon Stokes"]
|
10
|
+
spec.email = ["jon@jonstokes.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{The interactor gem with BYO context obects.}
|
13
|
+
spec.homepage = "http://github.com/jonstokes/lasershark"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency 'interactor', '~> 3.1'
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
data/lib/lasershark.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "interactor"
|
2
|
+
require "lasershark/version"
|
3
|
+
require "lasershark/common_context"
|
4
|
+
require "lasershark/context_methods"
|
5
|
+
|
6
|
+
module Lasershark
|
7
|
+
def self.included(base)
|
8
|
+
Interactor.class_eval do
|
9
|
+
def initialize(context = {})
|
10
|
+
@context = new_context(context)
|
11
|
+
end
|
12
|
+
|
13
|
+
def new_context(context)
|
14
|
+
if context_class
|
15
|
+
context_class.build(context)
|
16
|
+
elsif context.class.respond_to?(:build)
|
17
|
+
context.class.build(context)
|
18
|
+
else
|
19
|
+
Interactor::Context.build(context)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def context_class
|
24
|
+
self.class.context_class
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
base.class_eval do
|
29
|
+
include Interactor
|
30
|
+
extend ContextMethods
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
module Lasershark
|
2
|
+
module CommonContext
|
3
|
+
module ClassMethods
|
4
|
+
# Internal: Initialize an Interactor::Context or preserve an existing one.
|
5
|
+
# If the argument given is an Interactor::Context, the argument is returned.
|
6
|
+
# Otherwise, a new Interactor::Context is initialized from the provided
|
7
|
+
# hash.
|
8
|
+
#
|
9
|
+
# The "build" method is used during interactor initialization.
|
10
|
+
#
|
11
|
+
# context - A Hash whose key/value pairs are used in initializing a new
|
12
|
+
# Interactor::Context object. If an existing Interactor::Context
|
13
|
+
# is given, it is simply returned. (default: {})
|
14
|
+
#
|
15
|
+
# Examples
|
16
|
+
#
|
17
|
+
# context = Interactor::Context.build(foo: "bar")
|
18
|
+
# # => #<Interactor::Context foo="bar">
|
19
|
+
# context.object_id
|
20
|
+
# # => 2170969340
|
21
|
+
# context = Interactor::Context.build(context)
|
22
|
+
# # => #<Interactor::Context foo="bar">
|
23
|
+
# context.object_id
|
24
|
+
# # => 2170969340
|
25
|
+
#
|
26
|
+
# Returns the Interactor::Context.
|
27
|
+
def build(context = {})
|
28
|
+
self === context ? context : new(context)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.included(base)
|
33
|
+
base.extend(ClassMethods)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Public: Whether the Interactor::Context is successful. By default, a new
|
37
|
+
# context is successful and only changes when explicitly failed.
|
38
|
+
#
|
39
|
+
# The "success?" method is the inverse of the "failure?" method.
|
40
|
+
#
|
41
|
+
# Examples
|
42
|
+
#
|
43
|
+
# context = Interactor::Context.new
|
44
|
+
# # => #<Interactor::Context>
|
45
|
+
# context.success?
|
46
|
+
# # => true
|
47
|
+
# context.fail!
|
48
|
+
# # => Interactor::Failure: #<Interactor::Context>
|
49
|
+
# context.success?
|
50
|
+
# # => false
|
51
|
+
#
|
52
|
+
# Returns true by default or false if failed.
|
53
|
+
def success?
|
54
|
+
!failure?
|
55
|
+
end
|
56
|
+
|
57
|
+
# Public: Whether the Interactor::Context has failed. By default, a new
|
58
|
+
# context is successful and only changes when explicitly failed.
|
59
|
+
#
|
60
|
+
# The "failure?" method is the inverse of the "success?" method.
|
61
|
+
#
|
62
|
+
# Examples
|
63
|
+
#
|
64
|
+
# context = Interactor::Context.new
|
65
|
+
# # => #<Interactor::Context>
|
66
|
+
# context.failure?
|
67
|
+
# # => false
|
68
|
+
# context.fail!
|
69
|
+
# # => Interactor::Failure: #<Interactor::Context>
|
70
|
+
# context.failure?
|
71
|
+
# # => true
|
72
|
+
#
|
73
|
+
# Returns false by default or true if failed.
|
74
|
+
def failure?
|
75
|
+
@failure || false
|
76
|
+
end
|
77
|
+
|
78
|
+
# Public: Fail the Interactor::Context. Failing a context raises an error
|
79
|
+
# that may be rescued by the calling interactor. The context is also flagged
|
80
|
+
# as having failed.
|
81
|
+
#
|
82
|
+
# Optionally the caller may provide a hash of key/value pairs to be merged
|
83
|
+
# into the context before failure.
|
84
|
+
#
|
85
|
+
# context - A Hash whose key/value pairs are merged into the existing
|
86
|
+
# Interactor::Context instance. (default: {})
|
87
|
+
#
|
88
|
+
# Examples
|
89
|
+
#
|
90
|
+
# context = Interactor::Context.new
|
91
|
+
# # => #<Interactor::Context>
|
92
|
+
# context.fail!
|
93
|
+
# # => Interactor::Failure: #<Interactor::Context>
|
94
|
+
# context.fail! rescue false
|
95
|
+
# # => false
|
96
|
+
# context.fail!(foo: "baz")
|
97
|
+
# # => Interactor::Failure: #<Interactor::Context foo="baz">
|
98
|
+
#
|
99
|
+
# Raises Interactor::Failure initialized with the Interactor::Context.
|
100
|
+
def fail!(context = {})
|
101
|
+
modifiable.update(context)
|
102
|
+
@failure = true
|
103
|
+
raise Interactor::Failure, self
|
104
|
+
end
|
105
|
+
|
106
|
+
# Internal: Track that an Interactor has been called. The "called!" method
|
107
|
+
# is used by the interactor being invoked with this context. After an
|
108
|
+
# interactor is successfully called, the interactor instance is tracked in
|
109
|
+
# the context for the purpose of potential future rollback.
|
110
|
+
#
|
111
|
+
# interactor - An Interactor instance that has been successfully called.
|
112
|
+
#
|
113
|
+
# Returns nothing.
|
114
|
+
def called!(interactor)
|
115
|
+
_called << interactor
|
116
|
+
end
|
117
|
+
|
118
|
+
# Public: Roll back the Interactor::Context. Any interactors to which this
|
119
|
+
# context has been passed and which have been successfully called are asked
|
120
|
+
# to roll themselves back by invoking their "rollback" instance methods.
|
121
|
+
#
|
122
|
+
# Examples
|
123
|
+
#
|
124
|
+
# context = MyInteractor.call(foo: "bar")
|
125
|
+
# # => #<Interactor::Context foo="baz">
|
126
|
+
# context.rollback!
|
127
|
+
# # => true
|
128
|
+
# context
|
129
|
+
# # => #<Interactor::Context foo="bar">
|
130
|
+
#
|
131
|
+
# Returns true if rolled back successfully or false if already rolled back.
|
132
|
+
def rollback!
|
133
|
+
return false if @rolled_back
|
134
|
+
_called.reverse_each(&:rollback)
|
135
|
+
@rolled_back = true
|
136
|
+
end
|
137
|
+
|
138
|
+
# Internal: An Array of successfully called Interactor instances invoked
|
139
|
+
# against this Interactor::Context instance.
|
140
|
+
#
|
141
|
+
# Examples
|
142
|
+
#
|
143
|
+
# context = Interactor::Context.new
|
144
|
+
# # => #<Interactor::Context>
|
145
|
+
# context._called
|
146
|
+
# # => []
|
147
|
+
#
|
148
|
+
# context = MyInteractor.call(foo: "bar")
|
149
|
+
# # => #<Interactor::Context foo="baz">
|
150
|
+
# context._called
|
151
|
+
# # => [#<MyInteractor @context=#<Interactor::Context foo="baz">>]
|
152
|
+
#
|
153
|
+
# Returns an Array of Interactor instances or an empty Array.
|
154
|
+
def _called
|
155
|
+
@called ||= []
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lasershark
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jon Stokes
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: interactor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.15'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.15'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- jon@jonstokes.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/console
|
68
|
+
- bin/setup
|
69
|
+
- lasershark.gemspec
|
70
|
+
- lib/lasershark.rb
|
71
|
+
- lib/lasershark/common_context.rb
|
72
|
+
- lib/lasershark/context_methods.rb
|
73
|
+
- lib/lasershark/version.rb
|
74
|
+
homepage: http://github.com/jonstokes/lasershark
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.6.12
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: The interactor gem with BYO context obects.
|
98
|
+
test_files: []
|