actionizer 0.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7d4a6febf9f8f524d048670f7d5448ca762f11c8
4
+ data.tar.gz: 0adcb11a4177e39bebf7388e414372b2cd45dc37
5
+ SHA512:
6
+ metadata.gz: 3018b241c4e794f31c5fd22a8f1f3c987ffb9520f2d9a102fe63e3e9c682eed98663a53a5af082806017fae7521d691b44ea17c5d91d87b62d8f8de97985b102
7
+ data.tar.gz: 81b4b7072f415438303a66fe04e198b953214c925f28a73f0011f823cc3c3d84d0ddf06a64e3146346f4a4d0c739448d79cbb2dd2aa340822d096dc9c4786737
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ *.gem
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format progress
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+
4
+ Style/Documentation:
5
+ Enabled: false
6
+ Style/EmptyLinesAroundBlockBody:
7
+ Enabled: false
8
+ Style/EmptyLinesAroundClassBody:
9
+ Enabled: false
10
+ Style/MutableConstant:
11
+ Enabled: false
12
+ Style/TrivialAccessors:
13
+ Enabled: false
data/.simplecov ADDED
@@ -0,0 +1,8 @@
1
+ SimpleCov.start do
2
+ track_files '**/*.rb'
3
+
4
+ add_filter '/spec'
5
+ add_filter '/lib/actionizer/version'
6
+
7
+ minimum_coverage 100.00
8
+ end
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at mykphyre@yahoo.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in actionizer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Mike Nichols
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,117 @@
1
+ # Actionizer
2
+
3
+ ## Turn your classes into small, modular, resuable Actions!
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'actionizer'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install actionizer
20
+
21
+ ## Usage
22
+
23
+ Here's how you define an Action:
24
+
25
+ ```ruby
26
+ module Action
27
+ module Users
28
+
29
+ class Create
30
+ include Actionizer
31
+
32
+ def call
33
+ # Do stuff here
34
+ output.user = user
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+ ```
41
+
42
+ You can immediately stop execution with the `fail!` method
43
+ ```ruby
44
+ module Action
45
+ module Users
46
+
47
+ class Delete
48
+ include Actionizer
49
+
50
+ def call
51
+ # Possibly failing code here
52
+ fail!(error: "Nope, didn't work") if failure_condition
53
+
54
+ # This code never runs
55
+ output.foo = 'bar'
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ ```
62
+
63
+ Here's how you invoke it:
64
+ ```ruby
65
+ module Action
66
+ module Users
67
+
68
+ class Onboard
69
+ include Actionizer
70
+
71
+ def call
72
+ result = Action::Users::Create.call(name: name, email: email)
73
+ fail!(error: result.error) if result.failure?
74
+
75
+ result = Action::Users::SendWelcomeEmail.call(name: name, email: email)
76
+ fail!(error: result.error) if result.failure?
77
+ end
78
+ end
79
+
80
+ end
81
+ end
82
+ ```
83
+
84
+ This pattern is so common, there's a shorthand: `call_and_check_failure!`
85
+ ```ruby
86
+ module Action
87
+ module Users
88
+
89
+ class Onboard
90
+ include Actionizer
91
+
92
+ def call
93
+ # This code is identical to the example above
94
+ call_and_check_failure!(Action::Users::Create, name: name, email: email)
95
+ call_and_check_failure!(Action::Users::SendWelcomeEmail, name: name, email: email)
96
+ end
97
+ end
98
+
99
+ end
100
+ end
101
+ ```
102
+
103
+
104
+ ## Development
105
+
106
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests and `rubocop -D` to check for style errors. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
107
+
108
+ 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).
109
+
110
+ ## Contributing
111
+
112
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mikenichols/actionizer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
113
+
114
+
115
+ ## License
116
+
117
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'actionizer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'actionizer'
8
+ spec.version = Actionizer::VERSION
9
+ spec.authors = ['Mike Nichols']
10
+ spec.email = ['mykphyre@yahoo.com']
11
+
12
+ spec.summary = 'Turn your classes into small, modular, reusable Actions'
13
+ spec.homepage = 'https://github.com/mikenichols/actionizer'
14
+ spec.license = 'MIT'
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ unless spec.respond_to?(:metadata)
19
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
20
+ end
21
+
22
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_runtime_dependency 'hashie'
30
+
31
+ spec.add_development_dependency 'bundler', '~> 1.11'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'byebug', '~> 8.2'
35
+ spec.add_development_dependency 'rubocop', '~> 0.37'
36
+ spec.add_development_dependency 'simplecov', '~> 0.11'
37
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'actionizer'
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
data/bin/setup ADDED
@@ -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
data/lib/actionizer.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'actionizer/result'
2
+ require 'actionizer/failure'
3
+ require 'actionizer/version'
4
+
5
+ module Actionizer
6
+ attr_reader :output
7
+
8
+ def self.included(base)
9
+ base.class_eval do
10
+ extend ClassMethods
11
+ end
12
+ end
13
+
14
+ module ClassMethods
15
+ def call(inputs = {})
16
+ new(inputs).tap(&:call).output
17
+ rescue Actionizer::Failure => af
18
+ af.output
19
+ end
20
+ end
21
+
22
+ def initialize(inputs = {})
23
+ @output = Actionizer::Result.new
24
+
25
+ inputs.each_pair do |key, value|
26
+ next if key.to_s == 'output'
27
+
28
+ instance_variable_set("@#{key}".to_sym, value)
29
+
30
+ self.class.class_eval do
31
+ attr_reader key
32
+ end
33
+ end
34
+ end
35
+
36
+ def fail!(params = {})
37
+ params.each_pair { |key, value| output[key] = value }
38
+
39
+ output.fail
40
+
41
+ raise Actionizer::Failure.new('Failed!', output)
42
+ end
43
+
44
+ def call_and_check_failure!(action_class, params = {})
45
+ unless action_class.include? Actionizer
46
+ raise ArgumentError, "#{action_class.name} must include Actionizer"
47
+ end
48
+
49
+ result = action_class.call(params)
50
+ fail!(error: result.error) if result.failure?
51
+
52
+ result
53
+ end
54
+ end
@@ -0,0 +1,11 @@
1
+ module Actionizer
2
+ class Failure < StandardError
3
+ attr_reader :output
4
+
5
+ def initialize(msg, output)
6
+ @output = output
7
+ super msg
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ require 'hashie'
2
+
3
+ module Actionizer
4
+ class Result < Hashie::Mash
5
+
6
+ def initialize
7
+ @success = true
8
+ end
9
+
10
+ def success?
11
+ @success
12
+ end
13
+
14
+ def failure?
15
+ !@success
16
+ end
17
+
18
+ def fail
19
+ @success = false
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Actionizer
2
+ VERSION = '0.2.0'
3
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: actionizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Nichols
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
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
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '8.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '8.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.37'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.37'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.11'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.11'
111
+ description:
112
+ email:
113
+ - mykphyre@yahoo.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".rubocop.yml"
121
+ - ".simplecov"
122
+ - ".travis.yml"
123
+ - CODE_OF_CONDUCT.md
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - actionizer.gemspec
129
+ - bin/console
130
+ - bin/setup
131
+ - lib/actionizer.rb
132
+ - lib/actionizer/failure.rb
133
+ - lib/actionizer/result.rb
134
+ - lib/actionizer/version.rb
135
+ homepage: https://github.com/mikenichols/actionizer
136
+ licenses:
137
+ - MIT
138
+ metadata:
139
+ allowed_push_host: https://rubygems.org
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.5.1
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Turn your classes into small, modular, reusable Actions
160
+ test_files: []