riposte 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e9cda507520daceedc0086ce4849f3295d6fa2e
4
- data.tar.gz: 824567160f1b611ed44468ca7555514be2d6cd8c
3
+ metadata.gz: 5722c850e819bf9da6bf3294e890af95790649b1
4
+ data.tar.gz: 51b2fdaa6632edcb5894b143590359817c429cb2
5
5
  SHA512:
6
- metadata.gz: af45e32761319a78417c5946e140039d60c6d4d627e15ae4db8a7b5299e4d8179c6919f5017b0a6962e141b7bcbefe8deb47968becd6e9ccd540cf4c8dead25e
7
- data.tar.gz: 3dfd8b6637d685e7ee0f60fed3fa4f0014eef8fb1467b3c95191228db660ff767382809def44cd0675126607680a562b586d93d4ecfc5ae93569eb5d416d3af6
6
+ metadata.gz: ff17b14997e51448b45a5f471f94ca557612b3817517773ffe5c85e4bffcfc3b0f95e1563393855bd1599b8250e8c4445c97bfdf514fa4e5ee9b40c9401547e1
7
+ data.tar.gz: bb913c7059542917a85b366c3c4aa18275c50bf35c3a01a9ef5121ea2c5d3c877fbb50319becfcf6ada8c7799f6464ce309583b267919dfc43f7ad07ff183670
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ cache: bundle
3
+
4
+ rvm:
5
+ - jruby
6
+ - 2.0.0
7
+ - 2.2.1
8
+ - rbx
9
+
10
+ script: 'CODECLIMATE_REPO_TOKEN=66c92c9cdc6ae744eab70823c420d5db97e97c6b4c404f3fee04ee21c47dc35d bundle exec rake'
11
+
12
+ notifications:
13
+ email:
14
+ recipients:
15
+ - amos@binarynoggin.com
16
+ on_failure: change
17
+ on_success: never
data/README.md CHANGED
@@ -1,9 +1,17 @@
1
1
  # Riposte
2
+ [![Version
3
+ ](https://img.shields.io/gem/v/riposte.svg?style=flat)](https://rubygems.org/gems/riposte)
4
+ [![Build
5
+ Status](https://travis-ci.org/BinaryNoggin/riposte.svg?branch=master)](https://travis-ci.org/BinaryNoggin/riposte)
6
+ [![Code
7
+ Climate](https://codeclimate.com/github/BinaryNoggin/riposte/badges/gpa.svg)](https://codeclimate.com/github/BinaryNoggin/riposte)
8
+ [![Test
9
+ Coverage](https://codeclimate.com/github/BinaryNoggin/riposte/badges/coverage.svg)](https://codeclimate.com/github/BinaryNoggin/riposte)
2
10
 
3
11
  Riposte was put together to scratch an itch that I had when working with
4
12
  multiple outcomes of telling an object what to do and then responding
5
13
  differently depending on the results of the action. This happens all the
6
- time in the software that I right. I want to save an object to the
14
+ time in the software that I write. I want to save an object to the
7
15
  database and I can't because of the object not meeting the database
8
16
  requirements, or the database is down. I might have a whole host of
9
17
  different responses for the user. This is where Riposte is geared. It is
@@ -39,7 +47,7 @@ class MyController < ApplicationController
39
47
  @article.publish { |on|
40
48
  on.published { send_email_to_subscribers }
41
49
  on.invalid { handle_invalid }
42
- on.exception { database_down_handler }
50
+ on.exception { |e| database_down_handler(e) }
43
51
  }
44
52
 
45
53
  respond_with @artcile
@@ -58,7 +66,43 @@ class Article < ActiveRecord::Base
58
66
  react_to :invalid, &block
59
67
  end
60
68
  rescue SomeError => e
61
- react_to :exception, &block
69
+ react_to :exception, e, &block #passing an argument for reactions
70
+ end
71
+ end
72
+ ```
73
+
74
+ You may prefer not to use blocks. This is powerful as you can pass the
75
+ response object around. You can also use the object multiple times in
76
+ different places and with different blocks.
77
+
78
+
79
+ ```ruby
80
+ class MyController < ApplicationController
81
+ def create
82
+ @article = Article.new
83
+
84
+ on = @article.publish
85
+ on.published { send_email_to_subscribers }
86
+ on.invalid { handle_invalid }
87
+ on.exception { |e| database_down_handler(e) }
88
+
89
+ respond_with @artcile
90
+ end
91
+ end
92
+
93
+ class Article < ActiveRecord::Base
94
+ include Riposte::Helper
95
+
96
+ def publish
97
+ if valid?
98
+ #publish logic
99
+ react_to :published
100
+ else
101
+ #failure logic
102
+ react_to :invalid
103
+ end
104
+ rescue SomeError => e
105
+ react_to :exception, e, &block #passing an argument for reactions
62
106
  end
63
107
  end
64
108
  ```
@@ -1,7 +1,7 @@
1
1
  module Riposte
2
2
  module Helper
3
- def react_to(type)
4
- Reaction.new(type).tap { |reaction|
3
+ def react_to(type, *params)
4
+ Reaction.new(type, *params).tap { |reaction|
5
5
  yield reaction if block_given?
6
6
  }
7
7
  end
@@ -1,14 +1,17 @@
1
1
  module Riposte
2
2
  class Reaction
3
- attr_accessor :type
3
+ attr_accessor :type, :params
4
+ private :type=, :params=
5
+ protected :params, :type
4
6
 
5
- def initialize(type)
7
+ def initialize(type, *params)
6
8
  self.type = type
9
+ self.params = params
7
10
  end
8
11
 
9
12
  def method_missing(name, *)
10
13
  if name == type
11
- yield if block_given?
14
+ yield(*params) if block_given?
12
15
  end
13
16
  end
14
17
 
@@ -17,7 +20,7 @@ module Riposte
17
20
  end
18
21
 
19
22
  def ==(other)
20
- [self.class, self.type] == [other.class, other.type]
23
+ [self.class, self.type, self.params] == [other.class, other.type, other.params]
21
24
  end
22
25
  end
23
26
  end
@@ -1,3 +1,3 @@
1
1
  module Riposte
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -20,4 +20,6 @@ Gem::Specification.new do |spec|
20
20
  spec.add_development_dependency "bundler", "~> 1.7"
21
21
  spec.add_development_dependency "rake", "~> 10.0"
22
22
  spec.add_development_dependency "rspec", "~> 3.2.0"
23
+ spec.add_development_dependency "coveralls"
24
+ spec.add_development_dependency "codeclimate-test-reporter"
23
25
  end
@@ -1,3 +1,4 @@
1
+ require "spec_helper"
1
2
  require "riposte/helper"
2
3
 
3
4
  module Riposte
@@ -10,15 +11,31 @@ module Riposte
10
11
 
11
12
  subject { described_class.new }
12
13
 
13
- context "#react_to with no block" do
14
- it do
15
- expect(subject.react_to(:foo)).to eq(Riposte::Reaction.new(:foo))
14
+ context "with no params" do
15
+ context "#react_to with no block" do
16
+ it do
17
+ expect(subject.react_to(:foo)).to eq(Riposte::Reaction.new(:foo))
18
+ end
19
+ end
20
+
21
+ context "#react_to with a block" do
22
+ it do
23
+ expect {|b| subject.react_to(:foo, &b) }.to yield_with_args(Riposte::Reaction.new(:foo))
24
+ end
16
25
  end
17
26
  end
18
27
 
19
- context "#react_to with a block" do
20
- it do
21
- expect {|b| subject.react_to(:foo, &b) }.to yield_with_args(Riposte::Reaction.new(:foo))
28
+ context "with params" do
29
+ context "#react_to with no block" do
30
+ it do
31
+ expect(subject.react_to(:foo, :param)).to eq(Riposte::Reaction.new(:foo, :param))
32
+ end
33
+ end
34
+
35
+ context "#react_to with a block" do
36
+ it do
37
+ expect {|b| subject.react_to(:foo, :param, &b) }.to yield_with_args(Riposte::Reaction.new(:foo, :param))
38
+ end
22
39
  end
23
40
  end
24
41
  end
@@ -1,3 +1,4 @@
1
+ require "spec_helper"
1
2
  require "riposte/reaction"
2
3
 
3
4
  module Riposte
@@ -10,19 +11,41 @@ module Riposte
10
11
  end
11
12
 
12
13
  it "doesn't call a block when it isn't the response type" do
13
- subject.public_send(random_method) do
14
- fail "shoud have not run the block"
15
- end
14
+ expect{ |b| subject.public_send(random_method, &b) }.not_to yield_control
16
15
  end
17
16
 
18
- it "calls the block when it is the response type" do
19
- called = false
20
- subject.response_type { called = true }
21
- expect(called).to be_truthy
17
+ context "with no params" do
18
+ subject { described_class.new(:response_type) }
19
+
20
+ it "calls the block when it is the response type" do
21
+ expect{ |b| subject.public_send(:response_type, &b) }.to yield_control
22
+ end
23
+
24
+ it "is equal to another reaction with the same type" do
25
+ expect(subject).to eq(described_class.new(:response_type))
26
+ end
27
+
28
+ it "is not equal to another reaction with a different type" do
29
+ expect(subject).not_to eq(described_class.new(:other_type))
30
+ end
22
31
  end
23
32
 
24
- it "is equal to another reaction with the same type" do
25
- expect(subject).to eq(described_class.new(:response_type))
33
+ context "with params" do
34
+ let(:param) { double(:param) }
35
+ let(:param2) { double(:param2) }
36
+ subject { described_class.new(:response_type, param, param2) }
37
+
38
+ it "calls the block when it is the response type" do
39
+ expect{ |b| subject.public_send(:response_type, &b) }.to yield_with_args(param, param2)
40
+ end
41
+
42
+ it "is equal to another reaction with the same type" do
43
+ expect(subject).to eq(described_class.new(:response_type, param, param2))
44
+ end
45
+
46
+ it "is not equal if they have different params" do
47
+ expect(subject).to_not eq(described_class.new(:response_type, param2, param))
48
+ end
26
49
  end
27
50
  end
28
51
  end
@@ -0,0 +1,5 @@
1
+ require "coveralls"
2
+ Coveralls.wear!
3
+
4
+ require "codeclimate-test-reporter"
5
+ CodeClimate::TestReporter.start
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riposte
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amos L King
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-11 00:00:00.000000000 Z
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
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: codeclimate-test-reporter
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'
55
83
  description:
56
84
  email:
57
85
  - amos.l.king@gmail.com
@@ -59,7 +87,9 @@ executables: []
59
87
  extensions: []
60
88
  extra_rdoc_files: []
61
89
  files:
90
+ - .coveralls.yml
62
91
  - .gitignore
92
+ - .travis.yml
63
93
  - Gemfile
64
94
  - LICENSE.txt
65
95
  - README.md
@@ -71,6 +101,7 @@ files:
71
101
  - riposte.gemspec
72
102
  - spec/helper_spec.rb
73
103
  - spec/reaction_spec.rb
104
+ - spec/spec_helper.rb
74
105
  homepage: https://github.com/BinaryNoggin/riposte
75
106
  licenses:
76
107
  - MIT
@@ -98,3 +129,4 @@ summary: A micro-gem for handling different outcomes of an action
98
129
  test_files:
99
130
  - spec/helper_spec.rb
100
131
  - spec/reaction_spec.rb
132
+ - spec/spec_helper.rb