haltable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 37e7c0750250355a8bf0154dd9b828a831e37fc0
4
+ data.tar.gz: 10fd5467b7d4b88cf40df1592f8ddb898111731f
5
+ SHA512:
6
+ metadata.gz: 89cae40b2b9eee0cee4cf1084803c28b71dd4230369e3a73f81515de25ec99415d599b48ef31ed7080df268c81d8ef19efbe165f35c7bec4e10373bd4d4bc837
7
+ data.tar.gz: 8bff808fbb01912c2cddb6c92ba905ad25bc5773882aefcf4279a34ad361894a12b319303c1ecb0384920437d3b3a04d6d9c7071a022d46fe0cd5005a82223ca
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in haltable.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Guillaume Malette
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Haltable
2
+
3
+ Haltable is a gem that allows halting controller actions to simplify the flows.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'haltable'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install haltable
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ class AwesomesController < ApplicationController
25
+ def update
26
+ haltable do
27
+ verify_something
28
+ verify_something_else
29
+
30
+ awesome.update(params)
31
+ end
32
+ end
33
+
34
+ private
35
+ def verify_something
36
+ return if something.valid?
37
+ render :somethings_not_valid
38
+ halt
39
+ end
40
+ end
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( https://github.com/[my-github-username]/haltable/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/haltable.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'haltable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "haltable"
8
+ spec.version = Haltable::VERSION
9
+ spec.authors = ["Guillaume Malette"]
10
+ spec.email = ["gmalette@gmail.com"]
11
+ spec.summary = %q{Haltable gem for Ruby}
12
+ spec.description = %q{Haltable is a gem that allows halting controller actions to simplify the flows.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.1.0"
24
+ end
data/lib/haltable.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "haltable/version"
2
+
3
+ module Haltable
4
+ protected
5
+ def haltable
6
+ catch(:halt) do
7
+ yield if block_given?
8
+ return false
9
+ end
10
+ true
11
+ end
12
+
13
+ def halt
14
+ throw(:halt)
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Haltable
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+ require 'haltable'
3
+
4
+ module Spec
5
+ class Controller
6
+ include Haltable
7
+
8
+ def halted_action
9
+ halted = haltable do
10
+ update
11
+ halt
12
+ fail
13
+ end
14
+
15
+ render
16
+ halted
17
+ end
18
+
19
+ def unhalted_action
20
+ halted = haltable do
21
+ update
22
+ end
23
+
24
+ halted
25
+ end
26
+
27
+ def update
28
+ end
29
+
30
+ def render
31
+ end
32
+ end
33
+ end
34
+
35
+ RSpec.describe Haltable do
36
+ let(:controller) { Spec::Controller.new }
37
+
38
+ it 'returns early when halted' do
39
+ allow(controller).to receive(:update).once
40
+ allow(controller).to receive(:render).once
41
+ allow(controller).to receive(:fail).never
42
+
43
+ controller.halted_action
44
+ end
45
+
46
+ it 'returns true if halted' do
47
+ expect(controller.halted_action).to be true
48
+ end
49
+
50
+ it 'returns false if not halted' do
51
+ expect(controller.unhalted_action).to be false
52
+ end
53
+ end
@@ -0,0 +1,21 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |expectations|
3
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4
+ end
5
+
6
+ config.mock_with :rspec do |mocks|
7
+ mocks.verify_partial_doubles = true
8
+ end
9
+
10
+ config.disable_monkey_patching!
11
+
12
+ config.warnings = true
13
+
14
+ if config.files_to_run.one?
15
+ config.default_formatter = 'doc'
16
+ end
17
+
18
+ config.order = :random
19
+
20
+ Kernel.srand config.seed
21
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: haltable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Guillaume Malette
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-25 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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.1.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.1.0
55
+ description: Haltable is a gem that allows halting controller actions to simplify
56
+ the flows.
57
+ email:
58
+ - gmalette@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - haltable.gemspec
71
+ - lib/haltable.rb
72
+ - lib/haltable/version.rb
73
+ - spec/haltable_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: ''
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Haltable gem for Ruby
99
+ test_files:
100
+ - spec/haltable_spec.rb
101
+ - spec/spec_helper.rb