aces 0.0.1.beta.1
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 +8 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +72 -0
- data/Guardfile +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +10 -0
- data/aces.gemspec +34 -0
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/lib/aces.rb +123 -0
- data/lib/aces/version.rb +3 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 85cf80aa916ba644badb8f947b09a9a9f2ca283d
|
4
|
+
data.tar.gz: a1e3ac688481e36b0a8d76f8c7869efbc9e46de2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bab9ef64c57deb8340ec888384c1ca797202fc0ede6c13be886d98ca32528ede400a24204269ab81a08ca0c16f022a45767d4f37a950baad06180fcd87964038
|
7
|
+
data.tar.gz: 4de565971dd7dad40e404ed35e277c15f4cfdfdc6a926a5d23ea3a74a6cec94c788a7517f87e9fb1712e4859e1713cfc2ff6b9efb73921b2f628f5ac9260429a
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
aces (0.0.1.beta.1)
|
5
|
+
activesupport
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (5.2.1)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (>= 0.7, < 2)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
tzinfo (~> 1.1)
|
15
|
+
coderay (1.1.2)
|
16
|
+
concurrent-ruby (1.0.5)
|
17
|
+
ffi (1.9.25)
|
18
|
+
formatador (0.2.5)
|
19
|
+
guard (2.14.2)
|
20
|
+
formatador (>= 0.2.4)
|
21
|
+
listen (>= 2.7, < 4.0)
|
22
|
+
lumberjack (>= 1.0.12, < 2.0)
|
23
|
+
nenv (~> 0.1)
|
24
|
+
notiffany (~> 0.0)
|
25
|
+
pry (>= 0.9.12)
|
26
|
+
shellany (~> 0.0)
|
27
|
+
thor (>= 0.18.1)
|
28
|
+
guard-compat (1.2.1)
|
29
|
+
guard-minitest (2.4.6)
|
30
|
+
guard-compat (~> 1.2)
|
31
|
+
minitest (>= 3.0)
|
32
|
+
i18n (1.1.0)
|
33
|
+
concurrent-ruby (~> 1.0)
|
34
|
+
listen (3.1.5)
|
35
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
36
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
37
|
+
ruby_dep (~> 1.2)
|
38
|
+
lumberjack (1.0.13)
|
39
|
+
method_source (0.9.0)
|
40
|
+
minitest (5.11.3)
|
41
|
+
nenv (0.3.0)
|
42
|
+
notiffany (0.1.1)
|
43
|
+
nenv (~> 0.1)
|
44
|
+
shellany (~> 0.0)
|
45
|
+
pry (0.11.3)
|
46
|
+
coderay (~> 1.1.0)
|
47
|
+
method_source (~> 0.9.0)
|
48
|
+
rake (10.5.0)
|
49
|
+
rb-fsevent (0.10.3)
|
50
|
+
rb-inotify (0.9.10)
|
51
|
+
ffi (>= 0.5.0, < 2)
|
52
|
+
ruby_dep (1.5.0)
|
53
|
+
shellany (0.0.1)
|
54
|
+
thor (0.20.0)
|
55
|
+
thread_safe (0.3.6)
|
56
|
+
tzinfo (1.2.5)
|
57
|
+
thread_safe (~> 0.1)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
ruby
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
aces!
|
64
|
+
bundler (~> 1.16)
|
65
|
+
guard
|
66
|
+
guard-minitest
|
67
|
+
minitest (~> 5.0)
|
68
|
+
pry
|
69
|
+
rake (~> 10.0)
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
1.16.2
|
data/Guardfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
guard :minitest do
|
19
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
|
20
|
+
watch(%r{^test/.+_test\.rb$})
|
21
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Dan Ott
|
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
|
+
# Aces [HIGHLY EXPERIMENTAL]
|
2
|
+
|
3
|
+
Services objects that always land.
|
4
|
+
|
5
|
+
This is my playground for playing with some ideas for how to build composable service objects that are easy to learn at a glance, and highly powerful with experience.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'aces'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install aces
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: I'll write some usage instructions if this ever gets beyond experimentation.
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. 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]/aces.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/aces.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "aces/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "aces"
|
8
|
+
spec.version = Aces::VERSION
|
9
|
+
spec.authors = ["Dan Ott"]
|
10
|
+
spec.email = ["rubygems@danott.us"]
|
11
|
+
|
12
|
+
spec.summary = %q{[HIGHLEY EXPERIMENTAL] Service objects that always land}
|
13
|
+
spec.description = %q{[HIGHLEY EXPERIMENTAL] Service objects that always land}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "guard"
|
28
|
+
spec.add_development_dependency "guard-minitest"
|
29
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
30
|
+
spec.add_development_dependency "pry"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
|
33
|
+
spec.add_dependency "activesupport"
|
34
|
+
end
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/aces.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require "aces/version"
|
2
|
+
require "active_support"
|
3
|
+
|
4
|
+
module Aces
|
5
|
+
class ResultMissing < StandardError; end
|
6
|
+
class UnhandledResult < StandardError; end
|
7
|
+
|
8
|
+
module Service
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def call(*args)
|
13
|
+
set(
|
14
|
+
*args,
|
15
|
+
success: Aces::ConfiguredService::NOOP,
|
16
|
+
failure: Aces::ConfiguredService::NOOP,
|
17
|
+
).call
|
18
|
+
end
|
19
|
+
|
20
|
+
def set(*positional_arguments, service: self, success: nil, failure: nil, **keyword_arguments)
|
21
|
+
Aces::ConfiguredService.new(
|
22
|
+
service: service,
|
23
|
+
success: success,
|
24
|
+
failure: failure,
|
25
|
+
positional_arguments: positional_arguments,
|
26
|
+
keyword_arguments: keyword_arguments,
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def success(**attributes)
|
32
|
+
Aces::Result.new(success: true, **attributes)
|
33
|
+
end
|
34
|
+
|
35
|
+
def failure(**attributes)
|
36
|
+
Aces::Result.new(success: false, **attributes)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class ConfiguredService
|
41
|
+
attr_reader :configured_positional_arguments, :configured_keyword_arguments, :service, :success, :failure
|
42
|
+
|
43
|
+
NOOP = ->(_result) {}
|
44
|
+
IDENTITY = ->(result) { result }
|
45
|
+
UNCONFIGURED = ->(_result) { raise UnhandledResult }
|
46
|
+
|
47
|
+
def initialize(service:, success: nil, failure: nil, positional_arguments:, keyword_arguments:)
|
48
|
+
@service = service
|
49
|
+
@success = success == :identity ? IDENTITY : (success || UNCONFIGURED)
|
50
|
+
@failure = failure == :identity ? IDENTITY : (failure || UNCONFIGURED)
|
51
|
+
@configured_positional_arguments = positional_arguments
|
52
|
+
@configured_keyword_arguments = keyword_arguments
|
53
|
+
end
|
54
|
+
|
55
|
+
def set(*positional_arguments, **keyword_arguments)
|
56
|
+
configured_positional_arguments.push *positional_arguments unless positional_arguments.size.zero?
|
57
|
+
configured_keyword_arguments.merge!(keyword_arguments)
|
58
|
+
end
|
59
|
+
|
60
|
+
def call(*callsite_positional_arguments, **callsite_keyword_arguments)
|
61
|
+
combined_arguments = configured_positional_arguments + callsite_positional_arguments
|
62
|
+
combined_keyword_arguments = configured_keyword_arguments.merge(callsite_keyword_arguments)
|
63
|
+
combined_arguments.push combined_keyword_arguments if combined_keyword_arguments.keys.any?
|
64
|
+
|
65
|
+
service.new(*combined_arguments).call.tap do |result|
|
66
|
+
raise ResultMissing, "#{service}.call didn't return a result!" unless result.is_a?(Aces::Result)
|
67
|
+
callback = result.success? ? success : failure
|
68
|
+
callback.call(result) if callback.respond_to?(:call)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Result
|
74
|
+
attr_reader :failure, :attributes
|
75
|
+
|
76
|
+
def initialize(success: true, failure: !success, **attributes)
|
77
|
+
@failure = !!failure
|
78
|
+
@attributes = attributes
|
79
|
+
end
|
80
|
+
|
81
|
+
def success?
|
82
|
+
!failure?
|
83
|
+
end
|
84
|
+
|
85
|
+
def failure?
|
86
|
+
failure
|
87
|
+
end
|
88
|
+
|
89
|
+
def merge(other_result)
|
90
|
+
next_attributes = attributes.merge(other_result.attributes)
|
91
|
+
next_failure = failure || other_result.failure
|
92
|
+
self.class.new(failure: failure, **next_attributes)
|
93
|
+
end
|
94
|
+
|
95
|
+
def respond_to_missing?(method_name, _include_private = false)
|
96
|
+
attributes.key?(method_name)
|
97
|
+
end
|
98
|
+
|
99
|
+
def method_missing(method_name, *args)
|
100
|
+
attributes.fetch(method_name) { super }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
class Lambda
|
105
|
+
include Aces::Service
|
106
|
+
|
107
|
+
attr_reader :arguments, :callable
|
108
|
+
|
109
|
+
def initialize(*positional_arguments, callable:, **keyword_arguments)
|
110
|
+
@arguments = positional_arguments
|
111
|
+
@arguments.push(keyword_arguments) if keyword_arguments.any?
|
112
|
+
@callable = callable
|
113
|
+
end
|
114
|
+
|
115
|
+
def call
|
116
|
+
instance_exec(*arguments, &callable)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.lambda(success: Aces::ConfiguredService::NOOP, failure: Aces::ConfiguredService::NOOP)
|
121
|
+
Aces::Lambda.set(callable: Proc.new, success: success, failure: failure)
|
122
|
+
end
|
123
|
+
end
|
data/lib/aces/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aces
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.beta.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Ott
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-27 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: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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-minitest
|
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: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.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: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: "[HIGHLEY EXPERIMENTAL] Service objects that always land"
|
112
|
+
email:
|
113
|
+
- rubygems@danott.us
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
120
|
+
- Gemfile
|
121
|
+
- Gemfile.lock
|
122
|
+
- Guardfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- aces.gemspec
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- lib/aces.rb
|
130
|
+
- lib/aces/version.rb
|
131
|
+
homepage: ''
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">"
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: 1.3.1
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.5.2.3
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: "[HIGHLEY EXPERIMENTAL] Service objects that always land"
|
155
|
+
test_files: []
|