aasm-bang 0.1.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.
- data/CHANGELOG.txt +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +7 -0
- data/Rakefile +39 -0
- data/aasm-bang.gemspec +18 -0
- data/lib/aasm/bang.rb +41 -0
- metadata +73 -0
data/CHANGELOG.txt
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) 2011 Wegowise Inc.
|
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
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
def gemspec_name
|
5
|
+
@gemspec_name ||= Dir['*.gemspec'][0]
|
6
|
+
end
|
7
|
+
|
8
|
+
def gemspec
|
9
|
+
@gemspec ||= eval(File.read(gemspec_name), binding, gemspec_name)
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Build the gem"
|
13
|
+
task :gem=>:gemspec do
|
14
|
+
sh "gem build #{gemspec_name}"
|
15
|
+
FileUtils.mkdir_p 'pkg'
|
16
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "Install the gem locally"
|
20
|
+
task :install => :gem do
|
21
|
+
sh %{gem install pkg/#{gemspec.name}-#{gemspec.version}}
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Generate the gemspec"
|
25
|
+
task :generate do
|
26
|
+
puts gemspec.to_ruby
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Validate the gemspec"
|
30
|
+
task :gemspec do
|
31
|
+
gemspec.validate
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'Run tests'
|
35
|
+
task :test do |t|
|
36
|
+
sh 'rspec spec'
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :test
|
data/aasm-bang.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'rubygems' unless defined? Gem
|
3
|
+
require File.dirname(__FILE__) + "/lib/aasm/bang"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "aasm-bang"
|
7
|
+
s.version = AASM::Bang::VERSION
|
8
|
+
s.authors = ["Gabriel Horner", "Barun Singh"]
|
9
|
+
s.email = "ghorner@wegowise.com, bsingh@wegowise.com"
|
10
|
+
s.homepage = "http://wegowise.com"
|
11
|
+
s.summary = "Adds a bang aasm event!"
|
12
|
+
s.description = "Ever wanted an aasm event with an extra bang? Well ... now you can!"
|
13
|
+
s.required_rubygems_version = ">= 1.3.5"
|
14
|
+
s.add_dependency 'aasm', '>= 2.2.0'
|
15
|
+
s.files = Dir.glob(%w[{lib,test}/**/*.rb [A-Z]*.{txt,rdoc,md}]) + %w{Rakefile aasm-bang.gemspec}
|
16
|
+
s.extra_rdoc_files = ["README.md", "LICENSE.txt"]
|
17
|
+
s.license = 'MIT'
|
18
|
+
end
|
data/lib/aasm/bang.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'aasm'
|
2
|
+
|
3
|
+
module AASM
|
4
|
+
module ClassMethods; end
|
5
|
+
class TransitionFailure < RuntimeError; end
|
6
|
+
|
7
|
+
module Bang
|
8
|
+
VERSION = '0.1.0'
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def aasm_bang_event(name, options = {}, &block)
|
12
|
+
aasm_event(name, options, &block)
|
13
|
+
define_aasm_bang_method(name)
|
14
|
+
end
|
15
|
+
|
16
|
+
def define_aasm_bang_method(name)
|
17
|
+
define_method("#{name}!") do |*args|
|
18
|
+
options = args[-1].is_a?(Hash) ? args.pop : {}
|
19
|
+
if options[:lifecycle] == false
|
20
|
+
if send(name)
|
21
|
+
self.class.where(:id => self.id).update_all(:updated_at => Time.now, :aasm_state => self.aasm_current_state)
|
22
|
+
else
|
23
|
+
raise(AASM::TransitionFailure, "cannot transition from '#{self.aasm_current_state}' to '#{name}'")
|
24
|
+
end
|
25
|
+
else
|
26
|
+
old_state = self.aasm_current_state
|
27
|
+
aasm_fire_event(name, true, *args) || begin
|
28
|
+
if errors.any?
|
29
|
+
raise(AASM::TransitionFailure, "record is invalid: #{errors.to_a.inspect}")
|
30
|
+
else
|
31
|
+
raise(AASM::TransitionFailure, "cannot transition from '#{old_state}' to '#{name}'")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
ClassMethods.send :include, Bang::ClassMethods
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aasm-bang
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gabriel Horner
|
9
|
+
- Barun Singh
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2011-08-12 00:00:00 -04:00
|
15
|
+
default_executable:
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: aasm
|
19
|
+
prerelease: false
|
20
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
21
|
+
none: false
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 2.2.0
|
26
|
+
type: :runtime
|
27
|
+
version_requirements: *id001
|
28
|
+
description: Ever wanted an aasm event with an extra bang? Well ... now you can!
|
29
|
+
email: ghorner@wegowise.com, bsingh@wegowise.com
|
30
|
+
executables: []
|
31
|
+
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files:
|
35
|
+
- README.md
|
36
|
+
- LICENSE.txt
|
37
|
+
files:
|
38
|
+
- lib/aasm/bang.rb
|
39
|
+
- CHANGELOG.txt
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- aasm-bang.gemspec
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://wegowise.com
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.3.5
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.6.2
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Adds a bang aasm event!
|
72
|
+
test_files: []
|
73
|
+
|