wisper_interactor 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4a60a0ad078fc3f8f258b3c2a483093db2d74220
4
+ data.tar.gz: fd5dc44eb7f936c7eda789098a89c980c0a39de1
5
+ SHA512:
6
+ metadata.gz: 490c9908be91ec557671fc5d65e411003d89b2450f07432035e95b1dd58ef11290e8df2e62383513af7ac566cdb0ecd51f13f96442c15246118621c48fd249d2
7
+ data.tar.gz: 6aed3834b14c5c07ffb4d9bf7493717d116cc7a733a59c5f891538cc2633d564c87fc39ccfd19096a3d0c7d41deae6d313ad111476e0535a5f0f33e83b05b69a
@@ -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,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wisper_interactor.gemspec
4
+ gemspec
@@ -0,0 +1,42 @@
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
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Matthew Solt
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,122 @@
1
+ # WisperInteractor
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/wisper_interactor.svg?style=flat)](https://rubygems.org/gems/wisper_interactor)
4
+ [![Build Status](https://secure.travis-ci.org/activefx/wisper_interactor.png)](http://travis-ci.org/activefx/wisper_interactor)
5
+ [![Code Climate](https://codeclimate.com/github/activefx/wisper_interactor/badges/gpa.svg)](https://codeclimate.com/github/activefx/wisper_interactor)
6
+ [![Dependency Status](https://gemnasium.com/activefx/wisper_interactor.png)](https://gemnasium.com/activefx/wisper_interactor)
7
+ [![Test Coverage](https://codeclimate.com/github/activefx/wisper_interactor/badges/coverage.svg)](https://codeclimate.com/github/activefx/wisper_interactor)
8
+
9
+ WisperInteractor extends [Interactor](https://github.com/collectiveidea/interactor) with PubSub capabilities using [Wisper](https://github.com/krisleech/wisper). Instead of including the Interactor module, your interactor classes should inherit from WisperInteractor::Base. All Interactor methods are available such as the before, after, and around hooks, the rollback method, and the interactor class is still intialized or called with the context options.
10
+
11
+ As an interactor is designed to encapsulate your application's business logic and keep it out of your controllers, it makes sense to combine that functionality with Wisper's PubSub capabilities, further decoupling business logic from application code and external concerns.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'wisper_interactor'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install wisper_interactor
28
+
29
+ ## Usage
30
+
31
+ ````ruby
32
+ class NewsletterSignup < WisperInteractor::Base
33
+
34
+ # Subscribe a class that listens to Wisper events. For example,
35
+ # if your NewletterSignup interactor is going to publish a
36
+ # :signup_successful event, your AddMailchimpSubscriber listener
37
+ # should have a #signup_successful and possibly also a #signup_failed
38
+ # method to handle to the corresponding events. See the Wisper
39
+ # documentation for futher information.
40
+ #
41
+ # .subscribe can be called multiple times in a WisperInteractor, and
42
+ # can also accept options that are passed to the Wisper publisher.
43
+ #
44
+ subscribe AddMailchimpSubscriber
45
+ subscribe NewsletterAnalyticsService, async: true
46
+
47
+ # Runs after all other Interactor hooks when the interactor executes
48
+ # successfully. It is recommended that you broadcast a success
49
+ # message here that Wisper listeners can subscribe to in the future.
50
+ #
51
+ on_success do
52
+ broadcast(:newsletter_signup_succeeded, context.params)
53
+ end
54
+
55
+ # Runs in the event of any failure of the interactor. Keep in mind that
56
+ # the interactor before hook, as well as the first portion of an
57
+ # around hook will have run in the event of a failure. It is recommended
58
+ # that you broadcast a failure message here that Wisper listeners can
59
+ # subscribe to in the future.
60
+ #
61
+ on_failure do
62
+ broadcast(:newsletter_signup_failed, context.params)
63
+ end
64
+
65
+ # This is where you should place the core business logic of your
66
+ # interactor. This is evaulated in the context of the instance,
67
+ # and will have access to any instance methods you have defined
68
+ # as well as the interactor context method. You should use this
69
+ # for your logic instead of #call as specified in the Interactor
70
+ # documentation.
71
+ #
72
+ # If this block executes successfully, the on_success callback is
73
+ # called, and if it fails or raises an error, the on_failure
74
+ # callback is executed.
75
+ #
76
+ perform do
77
+ if form.validate(context.params)
78
+ form.save
79
+ else
80
+ context.fail!(message: "Failed to create model.")
81
+ end
82
+ end
83
+
84
+ # Example instance method
85
+ #
86
+ def form
87
+ context.form ||= NewsletterSignupForm.new
88
+ end
89
+
90
+ # As interactors can be chained together using an Interactor::Organizer,
91
+ # you may for example want to include logic to unsubscribe a user from
92
+ # your newsletter should a future interactor fail. This is of course
93
+ # completely optional.
94
+ #
95
+ def rollback
96
+ # logic for undoing interactor action
97
+ end
98
+ end
99
+
100
+ # Example execution of the NewsletterSignup interactor
101
+ #
102
+ NewsletterSignup.call(params: { email: 'info@example.com'})
103
+ ````
104
+
105
+ ## Development
106
+
107
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
108
+
109
+ 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).
110
+
111
+ ## Contributing
112
+
113
+ 1. Fork it ( https://github.com/[my-github-username]/wisper_interactor/fork )
114
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
115
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
116
+ 4. Push to the branch (`git push origin my-new-feature`)
117
+ 5. Create a new Pull Request
118
+
119
+ ## License
120
+
121
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
122
+
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wisper_interactor"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "wisper_interactor/version"
2
+ require "wisper_interactor/base"
3
+
4
+ module WisperInteractor
5
+ end
@@ -0,0 +1,93 @@
1
+ require 'interactor'
2
+ require 'wisper'
3
+
4
+ module WisperInteractor
5
+ class Base
6
+ include Interactor
7
+ include Wisper::Publisher
8
+
9
+ def self.on_success(&blk)
10
+ self.on_success_callback = blk
11
+ end
12
+
13
+ def self.on_failure(&blk)
14
+ self.on_failure_callback = blk
15
+ end
16
+
17
+ def self.perform(&blk)
18
+ self.instructions = blk
19
+ end
20
+
21
+ def self.on_success_callback=(value)
22
+ @on_success_callback = value
23
+ end
24
+
25
+ def self.on_success_callback
26
+ @on_success_callback
27
+ end
28
+
29
+ def self.on_failure_callback=(value)
30
+ @on_failure_callback = value
31
+ end
32
+
33
+ def self.on_failure_callback
34
+ @on_failure_callback
35
+ end
36
+
37
+ def self.instructions=(value)
38
+ @instructions = value
39
+ end
40
+
41
+ def self.instructions
42
+ @instructions
43
+ end
44
+
45
+ def self.subscribers
46
+ @subscribers ||= []
47
+ end
48
+
49
+ def self.subscribe(subscriber, **options)
50
+ self.subscribers << [ subscriber, options ]
51
+ end
52
+
53
+ # Override Interactor#run!
54
+ #
55
+ def run!
56
+ subscribe_listeners
57
+ perform_instructions
58
+ end
59
+
60
+ def call
61
+ execute :instructions
62
+ end
63
+
64
+ private
65
+
66
+ def subscribe_listeners
67
+ self.class.subscribers.each do |subscriber|
68
+ self.subscribe(*subscriber)
69
+ end
70
+ end
71
+
72
+ def perform_instructions
73
+ begin
74
+ with_hooks do
75
+ call
76
+ context.called!(self)
77
+ end
78
+ execute :on_success_callback
79
+ rescue
80
+ execute :on_failure_callback
81
+ context.rollback!
82
+ raise
83
+ end
84
+ end
85
+
86
+ def execute(key)
87
+ if blk = self.class.send(key)
88
+ instance_exec &blk
89
+ end
90
+ end
91
+
92
+ end
93
+ end
@@ -0,0 +1,3 @@
1
+ module WisperInteractor
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wisper_interactor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wisper_interactor"
8
+ spec.version = WisperInteractor::VERSION
9
+ spec.authors = ["Matt Solt"]
10
+ spec.email = ["mattsolt@gmail.com"]
11
+
12
+ spec.summary = %q{Extend Interactor (https://github.com/collectiveidea/interactor) with PubSub capabilities using Wisper (https://github.com/krisleech/wisper).}
13
+ spec.description = %q{Extend Interactor (https://github.com/collectiveidea/interactor) with PubSub capabilities using Wisper (https://github.com/krisleech/wisper).}
14
+ spec.homepage = "https://github.com/activefx/wisper_interactor"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "guard-rspec"
26
+ spec.add_development_dependency "wisper-rspec"
27
+
28
+ spec.add_dependency "wisper", "~> 1.0", "< 2"
29
+ spec.add_dependency "interactor", "~> 3.0", "< 4"
30
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wisper_interactor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Solt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-09 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
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: wisper-rspec
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: wisper
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: '2'
93
+ type: :runtime
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.0'
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: '2'
103
+ - !ruby/object:Gem::Dependency
104
+ name: interactor
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.0'
110
+ - - "<"
111
+ - !ruby/object:Gem::Version
112
+ version: '4'
113
+ type: :runtime
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '3.0'
120
+ - - "<"
121
+ - !ruby/object:Gem::Version
122
+ version: '4'
123
+ description: Extend Interactor (https://github.com/collectiveidea/interactor) with
124
+ PubSub capabilities using Wisper (https://github.com/krisleech/wisper).
125
+ email:
126
+ - mattsolt@gmail.com
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - ".gitignore"
132
+ - ".rspec"
133
+ - ".travis.yml"
134
+ - Gemfile
135
+ - Guardfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - lib/wisper_interactor.rb
142
+ - lib/wisper_interactor/base.rb
143
+ - lib/wisper_interactor/version.rb
144
+ - wisper_interactor.gemspec
145
+ homepage: https://github.com/activefx/wisper_interactor
146
+ licenses:
147
+ - MIT
148
+ metadata: {}
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 2.4.5.1
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: Extend Interactor (https://github.com/collectiveidea/interactor) with PubSub
169
+ capabilities using Wisper (https://github.com/krisleech/wisper).
170
+ test_files: []