pushable-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/lib/pushable/.DS_Store +0 -0
- data/lib/pushable/version.rb +3 -0
- data/lib/pushable.rb +33 -0
- data/pushable-rails.gemspec +28 -0
- data/spec/pushable_spec.rb +37 -0
- data/spec/spec_helper.rb +29 -0
- data/test.db +0 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6ea422298a860eb66c8ccaa5b9816575ae57f482
|
4
|
+
data.tar.gz: 0dfaf728361e67fc1244fafd67035b55d7b9911d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: df8cdac35efad1b74f3bcd82dd0740746a4ed9d749578a1e7d3ee4a6d4b2a089d5ebdcf199714c37380c1ce89c219f2a7d7ae4762d02334e71bcc052efd2e4ab
|
7
|
+
data.tar.gz: 78ce8fd2150ec9ee4769098c660d2bf6d851e22d0c5b730d8d4ea5d4514cae2a2756e482b21471e6abdd30680a5b1b9ecdc523be5350f752a9b1808ae977c5cb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Matteo Depalo
|
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,52 @@
|
|
1
|
+
# Pushable::Rails
|
2
|
+
|
3
|
+
Send model updates to Pusher
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'pushable-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install pushable-rails
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Include the `Pushable` module in your activerecord models like this:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class DummyModel < ActiveRecord::Base
|
25
|
+
include Pushable
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
Now every time you create, update or destroy `DummyModel`s your app will send the corresponding notifications to pusher.
|
30
|
+
|
31
|
+
Channel: `pusher`
|
32
|
+
|
33
|
+
Events:
|
34
|
+
|
35
|
+
- Create
|
36
|
+
'dummy_model.destroy'
|
37
|
+
|
38
|
+
- Update
|
39
|
+
'dummy_model.update'
|
40
|
+
|
41
|
+
- Destroy
|
42
|
+
'dummy_model.destroy'
|
43
|
+
|
44
|
+
The payload will be the output of the model instance `to_json`. If defined, a serializer will be used (eg. `DummyModelSerializer`).
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it ( http://github.com/<my-github-username>/pushable-rails/fork )
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
Binary file
|
data/lib/pushable.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'pushable/version'
|
2
|
+
require 'active_support'
|
3
|
+
require 'pusher'
|
4
|
+
|
5
|
+
module Pushable
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
attr_accessor :client_id
|
10
|
+
|
11
|
+
after_commit :pushable_trigger_create, on: :create
|
12
|
+
after_commit :pushable_trigger_update, on: :update
|
13
|
+
after_commit :pushable_trigger_destroy, on: :destroy
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def pushable_class_name
|
18
|
+
self.class.name.underscore
|
19
|
+
end
|
20
|
+
|
21
|
+
def serialized_model
|
22
|
+
"#{self.class.name}Serializer".constantize.new(self).to_json
|
23
|
+
rescue NameError
|
24
|
+
to_json
|
25
|
+
end
|
26
|
+
|
27
|
+
%w(create update destroy).each do |action_name|
|
28
|
+
define_method("pushable_trigger_#{action_name}") do
|
29
|
+
Pusher.trigger('pusher', "#{pushable_class_name}.#{action_name}", serialized_model)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -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 'pushable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'pushable-rails'
|
8
|
+
spec.version = Pushable::VERSION
|
9
|
+
spec.authors = ['Matteo Depalo']
|
10
|
+
spec.email = ['matteodepalo@gmail.com']
|
11
|
+
spec.summary = 'Send model updates to Pusher'
|
12
|
+
spec.description = 'Send model updates to Pusher'
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'rails'
|
22
|
+
spec.add_dependency 'pusher'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'database_cleaner'
|
26
|
+
spec.add_development_dependency 'sqlite3'
|
27
|
+
spec.add_development_dependency 'rspec'
|
28
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class DummyModel < ActiveRecord::Base
|
4
|
+
include Pushable
|
5
|
+
|
6
|
+
def to_json
|
7
|
+
'{}'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Pushable do
|
12
|
+
describe 'after commit on create' do
|
13
|
+
it 'triggers the corresponding Pusher notification' do
|
14
|
+
dummy_model = DummyModel.new
|
15
|
+
Pusher.should_receive(:trigger).with('pusher', 'dummy_model.create', '{}')
|
16
|
+
dummy_model.save
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'after commit on update' do
|
21
|
+
it 'triggers the corresponding Pusher notification' do
|
22
|
+
dummy_model = DummyModel.new
|
23
|
+
dummy_model.save
|
24
|
+
Pusher.should_receive(:trigger).with('pusher', 'dummy_model.update', '{}')
|
25
|
+
dummy_model.update({})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'after commit on destroy' do
|
30
|
+
it 'triggers the corresponding Pusher notification' do
|
31
|
+
dummy_model = DummyModel.new
|
32
|
+
dummy_model.save
|
33
|
+
Pusher.should_receive(:trigger).with('pusher', 'dummy_model.destroy', '{}')
|
34
|
+
dummy_model.destroy
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'pushable'
|
2
|
+
require 'database_cleaner'
|
3
|
+
require 'sqlite3'
|
4
|
+
require 'active_record'
|
5
|
+
|
6
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
7
|
+
|
8
|
+
ActiveRecord::Schema.define do
|
9
|
+
self.verbose = false
|
10
|
+
create_table :dummy_models, force: true
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.order = 'random'
|
15
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
16
|
+
|
17
|
+
config.before(:suite) do
|
18
|
+
DatabaseCleaner.strategy = :truncation
|
19
|
+
DatabaseCleaner.clean_with(:truncation)
|
20
|
+
end
|
21
|
+
|
22
|
+
config.before(:each) do
|
23
|
+
DatabaseCleaner.start
|
24
|
+
end
|
25
|
+
|
26
|
+
config.after(:each) do
|
27
|
+
DatabaseCleaner.clean
|
28
|
+
end
|
29
|
+
end
|
data/test.db
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pushable-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matteo Depalo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pusher
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
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: database_cleaner
|
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: sqlite3
|
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: rspec
|
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: Send model updates to Pusher
|
112
|
+
email:
|
113
|
+
- matteodepalo@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- lib/pushable.rb
|
124
|
+
- lib/pushable/.DS_Store
|
125
|
+
- lib/pushable/version.rb
|
126
|
+
- pushable-rails.gemspec
|
127
|
+
- spec/pushable_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
- test.db
|
130
|
+
homepage: ''
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.2.2
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Send model updates to Pusher
|
154
|
+
test_files:
|
155
|
+
- spec/pushable_spec.rb
|
156
|
+
- spec/spec_helper.rb
|
157
|
+
has_rdoc:
|