ansible-rails 0.9.3

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6dde237388f6dfd8ebe49bf6698e70667264c9e0
4
+ data.tar.gz: e1e91a0cdecd898ea47ca4b588a4d120231381ac
5
+ SHA512:
6
+ metadata.gz: b5cb85706b21354afdcebd3a4cfb81a5af835573b8d59db2464fa3cb2dc03cc4067c52987f7da6df392ee920c4ab5951a5227c32842241b69e62f3d72e19db96
7
+ data.tar.gz: 6ff924ecd91f2a842831b847fb565d88710efa8fb405accc61c0b231b3fc46732d96b724074bc8dbe882520c2aaa01f329bf56c0b3f098550af73b656b3dca76
@@ -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/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm gemset use ansible
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ansible.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Derek Parker
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.
@@ -0,0 +1,69 @@
1
+ # Ansible
2
+
3
+ Ansible provides a conveviance method to wrap the ActionController::Live functionality in Rails 4.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ansible-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ansible-rails
18
+
19
+ ## Usage
20
+
21
+ To use Ansible, simply create a routable action in your controller that will represent the event source for transmitting the Server-Sent Events, and then use the `transmit` method to send accross an event and data payload to the client.
22
+
23
+ ```ruby
24
+ FoosController < ActionController::Base
25
+
26
+ ...
27
+
28
+ def transmit_action
29
+ transmit 'event', my: 'really', cool: 'message'
30
+ end
31
+
32
+ ...
33
+
34
+ end
35
+ ```
36
+
37
+ This will create a properly formatted Server-Sent Event using the functionality of ActionController::Live.
38
+
39
+ To consume this event on the client side, simply use the Javascript EventSource API:
40
+
41
+ ```javascript
42
+ $(document).ready(function(){
43
+ var source = new EventSource('your/eventsource/url');
44
+ source.addEventListener('your_event', function(message){
45
+ // now the data that you send along will be available in
46
+ // message.data, and will come in the form of a JSON document
47
+ });
48
+ });
49
+ ```
50
+
51
+ ## Requirements
52
+
53
+ * Ansible relies on the ActionController::Live functionality of Rails 4
54
+
55
+ ## Known Issues
56
+
57
+ * There is currently no way to configure the retry time that is sent with the SSE, a configuration strategy will be added in v1.0.
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
66
+
67
+ ## License
68
+
69
+ MIT
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new :spec do |spec|
5
+ spec.pattern = FileList['spec/**/*_spec.rb']
6
+ end
7
+
8
+ task default: [:spec]
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ansible/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ansible-rails"
8
+ spec.version = Ansible::VERSION
9
+ spec.authors = ["Derek Parker"]
10
+ spec.email = ["parkerderek86@gmail.com"]
11
+ spec.description = "Ansible provides a conveniance method to your Rails controllers for creating SSEs."
12
+ spec.summary = "Ansible is a conveniant way to generate Server-Sent Events"
13
+ spec.homepage = "https://www.github.com/dparker1990/ansible-rails"
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rails", "4.0.0.rc1"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "rspec-rails"
26
+ spec.add_development_dependency "rspec-spies"
27
+ spec.add_development_dependency "pg"
28
+ end
@@ -0,0 +1,7 @@
1
+ require 'ansible/sse'
2
+ require 'ansible/constant_resolver'
3
+ require 'ansible/transmit_controller'
4
+
5
+ ActiveSupport.on_load(:action_controller) do
6
+ include Ansible::TransmitController
7
+ end
@@ -0,0 +1,17 @@
1
+ module Ansible
2
+ class ConstantResolver
3
+ def initialize(name)
4
+ @name = name
5
+ end
6
+
7
+ def lookup_constant
8
+ name.constantize
9
+ end
10
+
11
+ private
12
+
13
+ def name
14
+ @name.to_s.titleize
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ require 'json'
2
+
3
+ module Ansible
4
+ class SSE
5
+ attr_reader :stream
6
+
7
+ def initialize(stream)
8
+ @stream = stream
9
+ end
10
+
11
+ def write(event, message)
12
+ stream.write "event: #{event}\n"
13
+ stream.write "retry: 1000\n"
14
+ stream.write "data: #{JSON.dump message}\n\n"
15
+ end
16
+
17
+ def close
18
+ stream.close
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module Ansible
2
+ module TransmitController
3
+ def transmit(event, message)
4
+ begin
5
+ headers['Content-Type'] = 'text/event-stream'
6
+ sse = SSE.new response.stream
7
+ sse.write event, message
8
+ ensure
9
+ response.stream.close
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Ansible
2
+ MAJOR = 0
3
+ MINOR = 9
4
+ TINY = 3
5
+
6
+ VERSION = [MAJOR, MINOR, TINY].join "."
7
+ end
@@ -0,0 +1,5 @@
1
+ development:
2
+ thing: yeah
3
+
4
+ test:
5
+ thing: yeah
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require 'ansible/constant_resolver'
3
+
4
+ describe Ansible::ConstantResolver do
5
+ describe '#lookup_constant' do
6
+ before { class Space; end }
7
+
8
+ it 'resolves the constant' do
9
+ described_class.new("Space").lookup_constant.should eq Space
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ require 'fixtures/fake_rails_app'
2
+
3
+ class TestsController < ActionController::Base
4
+ include Rails.application.routes.url_helpers
5
+ include ActionController::Live
6
+
7
+ def new
8
+ render text: "new"
9
+ end
10
+
11
+ def create
12
+ head :ok
13
+ end
14
+
15
+ def space_beacon
16
+ transmit 'space', expanding: true
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ require 'active_support/all'
2
+ require 'action_controller'
3
+ require 'action_dispatch'
4
+ require 'active_model'
5
+ require 'active_record'
6
+ require 'rails'
7
+ require 'ostruct'
8
+ require 'ansible-rails'
9
+
10
+ module Rails
11
+ class App
12
+ def env_config; {} end
13
+
14
+ def routes
15
+ return @routes if defined? @routes
16
+
17
+ @routes = ActionDispatch::Routing::RouteSet.new.tap do |routes|
18
+ routes.draw do
19
+ post '/test' => 'tests#create'
20
+ get '/test/space_beacon' => 'tests#space_beacon'
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ def self.application
27
+ @app ||= App.new
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ require 'fixtures/controllers'
2
+ require 'rspec/rails'
3
+ require 'spec_helper'
4
+
5
+ describe TestsController, type: :controller do
6
+ describe 'GET space_beacon' do
7
+ before do
8
+ get :space_beacon
9
+ end
10
+
11
+ it 'sets the content-type to text/event-stream' do
12
+ response.headers['Content-Type'].should eq 'text/event-stream'
13
+ end
14
+
15
+ it 'sends the next messages in the que concerning the current modal' do
16
+ sleep 0.1 until response.stream.closed?
17
+ response.body.should eq %{event: space\nretry: 1000\ndata: {"expanding":true}\n\n}
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ require 'fixtures/fake_rails_app'
2
+ require 'fixtures/controllers'
3
+ require 'rspec-spies'
4
+
5
+ ActiveRecord::Base.establish_connection :adapter => :postgresql,
6
+ :adapter => 'postgresql',
7
+ :database => 'ansible_test',
8
+ :pool => 5,
9
+ :timeout => 5000,
10
+ :host => 'localhost'
@@ -0,0 +1,23 @@
1
+ require 'ansible/sse'
2
+
3
+ describe Ansible::SSE do
4
+ let(:io) { stub(write: true) }
5
+ let(:sse) { Ansible::SSE.new(io) }
6
+
7
+ describe '#write' do
8
+ context 'with an event specified' do
9
+ it 'sends data accross the pipe in the correct format' do
10
+ sse.write(:message, hello: 'hello')
11
+ io.should have_received(:write).with("event: message\n")
12
+ io.should have_received(:write).with(%{data: {\"hello\":\"hello\"}\n\n})
13
+ end
14
+ end
15
+ end
16
+
17
+ describe '#close' do
18
+ it 'closes the IO connection' do
19
+ io.should_receive :close
20
+ sse.close
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ansible-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.3
5
+ platform: ruby
6
+ authors:
7
+ - Derek Parker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-07 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.0.rc1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 4.0.0.rc1
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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: rspec-rails
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: rspec-spies
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pg
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Ansible provides a conveniance method to your Rails controllers for creating
112
+ SSEs.
113
+ email:
114
+ - parkerderek86@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - .rvmrc
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - ansible.gemspec
126
+ - lib/ansible-rails.rb
127
+ - lib/ansible/constant_resolver.rb
128
+ - lib/ansible/sse.rb
129
+ - lib/ansible/transmit_controller.rb
130
+ - lib/ansible/version.rb
131
+ - lib/generators/ansible/templates/ansible.yml
132
+ - spec/constant_resolver_spec.rb
133
+ - spec/fixtures/controllers.rb
134
+ - spec/fixtures/fake_rails_app.rb
135
+ - spec/rails_integration_spec.rb
136
+ - spec/spec_helper.rb
137
+ - spec/sse_spec.rb
138
+ homepage: https://www.github.com/dparker1990/ansible-rails
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.0.3
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Ansible is a conveniant way to generate Server-Sent Events
162
+ test_files:
163
+ - spec/constant_resolver_spec.rb
164
+ - spec/fixtures/controllers.rb
165
+ - spec/fixtures/fake_rails_app.rb
166
+ - spec/rails_integration_spec.rb
167
+ - spec/spec_helper.rb
168
+ - spec/sse_spec.rb