state_run_media 0.0.1.pre

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ state_run_media
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - jruby-19mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in state_run_media.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 User Testing, Inc.
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,32 @@
1
+ [![Code Climate](https://codeclimate.com/github/usertesting/state_run_media.png)](https://codeclimate.com/github/usertesting/state_run_media)
2
+ [![Build Status](https://travis-ci.org/usertesting/state_run_media.png)](https://travis-ci.org/usertesting/state_run_media)
3
+
4
+ # state_run_media
5
+
6
+ Automatically publish events upon state transitions. All you have to do is subscribe.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'state_run_media'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install state_run_media
21
+
22
+ ## Usage
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new pull request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ task :default => [:test]
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.test_files = FileList['test/**/*.rb']
8
+ t.verbose = true
9
+ end
@@ -0,0 +1,3 @@
1
+ require "state_run_media/version"
2
+ require "state_run_media/state_machine_observer"
3
+ require "state_run_media/state_machine/machine"
@@ -0,0 +1,7 @@
1
+ require 'state_machine/machine'
2
+
3
+ StateMachine::Machine.class_eval do
4
+ def after_initialize
5
+ self.before_transition StateRunMedia::StateMachineObserver.method(:before_transition)
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ require 'wisper'
2
+
3
+ module StateRunMedia
4
+ class StateMachineObserver
5
+ class << self
6
+ include Wisper::Publisher
7
+
8
+ def underscore(string)
9
+ word = string.dup
10
+ #word.gsub!(/::/, '_')
11
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
12
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
13
+ #word.tr!("-", "_")
14
+ word.downcase!
15
+ word
16
+ end
17
+
18
+ def before_transition(object, transition)
19
+ name = [underscore(object.class.name), transition.attribute, transition.from_name, 'to', transition.to_name].join('_')
20
+ publish(name.to_sym, object)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module StateRunMedia
2
+ VERSION = "0.0.1.pre"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'state_run_media/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "state_run_media"
8
+ spec.version = StateRunMedia::VERSION
9
+ spec.authors = ["Ryan Montgomery", "Ryan Platte"]
10
+ spec.email = ["rep@usertesting.com"]
11
+ spec.description = %q{Automatically publish events upon state transitions. All you have to do is subscribe.}
12
+ spec.summary = %q{Publish state news}
13
+ spec.homepage = "https://github.com/usertesting/state_run_media"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_dependency "state_machine", "~> 1.2.0"
22
+ spec.add_dependency "wisper", "~> 1.2.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+ require 'rubygems'
3
+ require 'state_machine'
4
+ require 'state_run_media'
5
+
6
+ class MyMinimalStateMachine
7
+ state_machine :foo, :initial => :beginning_state do
8
+ state :another_state
9
+ event :change_something do
10
+ transition :beginning_state => :another_state
11
+ end
12
+ end
13
+ end
14
+
15
+ class FooListener
16
+ attr_reader :call_log
17
+
18
+ def initialize
19
+ @call_log = []
20
+ end
21
+
22
+ def my_minimal_state_machine_foo_beginning_state_to_another_state(*args)
23
+ @call_log << [:my_minimal_state_machine_foo_beginning_state_to_another_state, args]
24
+ end
25
+ end
26
+
27
+ class RegistrationTest < Test::Unit::TestCase
28
+ def test_basic_transition_publishes
29
+ foo_machine = MyMinimalStateMachine.new
30
+ listener = FooListener.new
31
+ Wisper.with_listeners(listener) do
32
+ foo_machine.change_something!
33
+ end
34
+ assert_equal([[:my_minimal_state_machine_foo_beginning_state_to_another_state, [foo_machine]]], listener.call_log)
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ require 'test/unit'
2
+ lib = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: state_run_media
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Montgomery
9
+ - Ryan Platte
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-09-21 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: state_machine
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 1.2.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 1.2.0
31
+ - !ruby/object:Gem::Dependency
32
+ name: wisper
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 1.2.0
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.2.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '1.3'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rake
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ description: Automatically publish events upon state transitions. All you have to
80
+ do is subscribe.
81
+ email:
82
+ - rep@usertesting.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - .gitignore
88
+ - .ruby-gemset
89
+ - .ruby-version
90
+ - .travis.yml
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/state_run_media.rb
96
+ - lib/state_run_media/state_machine/machine.rb
97
+ - lib/state_run_media/state_machine_observer.rb
98
+ - lib/state_run_media/version.rb
99
+ - state_run_media.gemspec
100
+ - test/functional/state_machine_test.rb
101
+ - test/test_helper.rb
102
+ homepage: https://github.com/usertesting/state_run_media
103
+ licenses:
104
+ - MIT
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>'
119
+ - !ruby/object:Gem::Version
120
+ version: 1.3.1
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.25
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Publish state news
127
+ test_files:
128
+ - test/functional/state_machine_test.rb
129
+ - test/test_helper.rb