yaps 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -4
- data/Gemfile +2 -2
- data/README.md +4 -2
- data/lib/yaps.rb +28 -1
- data/lib/yaps/actions/creation.rb +3 -3
- data/lib/yaps/actions/destruction.rb +3 -2
- data/lib/yaps/actions/updation.rb +3 -2
- data/lib/yaps/configuration.rb +13 -0
- data/lib/yaps/publisher.rb +9 -0
- data/lib/yaps/subscriber.rb +0 -1
- data/lib/yaps/version.rb +1 -1
- data/spec/publisher_spec.rb +38 -14
- data/spec/spec_helper.rb +18 -2
- data/spec/yaps_spec.rb +27 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f038f5a5b9462fc600d5162daa0b4306c1ae49e
|
4
|
+
data.tar.gz: 6a3e36e66fb80b577ba819d30f5d5d508d5efce2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 815993f74938609c045c9e12565feaf1fcc8748a9c187c09140f048ea5d40eb4c5fc2e296a68a3fdacccd2dd8cfb38d8a138944a719369a788dd50f16fbc2217
|
7
|
+
data.tar.gz: 7c1bde4ac94a08c291880d98ba51757c6b30ab6b188dd2c9cb19f25cb7305ffb4709e23b8b06d1df7747395f44f4565ac176d8a6f08107b00bd62485f7bf8e05
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Yaps
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/yaps.svg)](http://badge.fury.io/rb/yaps)
|
3
4
|
[![Build Status](https://travis-ci.org/voanhduy1512/yaps.svg)](https://travis-ci.org/voanhduy1512/yaps)
|
4
|
-
[![Coverage Status](
|
5
|
-
[![Code Climate](
|
5
|
+
[![Coverage Status](http://img.shields.io/coveralls/voanhduy1512/yaps.svg)](https://coveralls.io/r/voanhduy1512/yaps)
|
6
|
+
[![Code Climate](http://img.shields.io/codeclimate/github/voanhduy1512/yaps.svg)](https://codeclimate.com/github/voanhduy1512/yaps)
|
7
|
+
[![Dependency Status](https://gemnasium.com/voanhduy1512/yaps.svg)](https://gemnasium.com/voanhduy1512/yaps)
|
6
8
|
|
7
9
|
|
8
10
|
TODO: Write a gem description
|
data/lib/yaps.rb
CHANGED
@@ -2,10 +2,37 @@ require 'wisper'
|
|
2
2
|
require 'yaps/actions/creation'
|
3
3
|
require 'yaps/actions/destruction'
|
4
4
|
require 'yaps/actions/updation'
|
5
|
+
require 'yaps/configuration'
|
5
6
|
require 'yaps/publisher'
|
6
7
|
require 'yaps/subscriber'
|
7
8
|
require "yaps/version"
|
8
9
|
|
10
|
+
begin
|
11
|
+
require "pry"
|
12
|
+
rescue LoadError
|
13
|
+
end
|
14
|
+
|
9
15
|
module Yaps
|
10
|
-
|
16
|
+
class << self
|
17
|
+
attr_writer :configuration
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configuration
|
21
|
+
@configuration ||= Configuration.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.reset
|
25
|
+
@configuration = Configuration.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configure
|
29
|
+
yield(configuration)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.with_pushlisher_enable &block
|
33
|
+
previous = configuration.enable
|
34
|
+
configuration.enable = true
|
35
|
+
block.call
|
36
|
+
configuration.enable = previous
|
37
|
+
end
|
11
38
|
end
|
@@ -2,11 +2,11 @@ module Yaps
|
|
2
2
|
# Handles creation of Activities upon destruction and update of tracked model.
|
3
3
|
module Creation
|
4
4
|
extend ActiveSupport::Concern
|
5
|
-
include Wisper::Publisher
|
6
5
|
|
7
6
|
included do
|
8
|
-
after_create
|
7
|
+
after_create do
|
8
|
+
publish(:"#{ActiveSupport::Inflector.underscore(self.class.name)}_created", self)
|
9
|
+
end
|
9
10
|
end
|
10
|
-
|
11
11
|
end
|
12
12
|
end
|
@@ -2,10 +2,11 @@ module Yaps
|
|
2
2
|
# Handles creation of Activities upon destruction and update of tracked model.
|
3
3
|
module Destruction
|
4
4
|
extend ActiveSupport::Concern
|
5
|
-
include Wisper::Publisher
|
6
5
|
|
7
6
|
included do
|
8
|
-
before_destroy
|
7
|
+
before_destroy do
|
8
|
+
publish(:"#{ActiveSupport::Inflector.underscore(self.class.name)}_deleted", self)
|
9
|
+
end
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
@@ -2,10 +2,11 @@ module Yaps
|
|
2
2
|
# Handles creation of Activities upon destruction and update of tracked model.
|
3
3
|
module Updation
|
4
4
|
extend ActiveSupport::Concern
|
5
|
-
include Wisper::Publisher
|
6
5
|
|
7
6
|
included do
|
8
|
-
after_update
|
7
|
+
after_update do
|
8
|
+
publish(:"#{ActiveSupport::Inflector.underscore(self.class.name)}_updated", self)
|
9
|
+
end
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
data/lib/yaps/publisher.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
module Yaps
|
2
|
+
module ExtendPublisher
|
3
|
+
def publish(*args)
|
4
|
+
Yaps.configuration.enable? && super
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
2
8
|
module Publisher
|
3
9
|
extend ActiveSupport::Concern
|
10
|
+
include Wisper::Publisher
|
11
|
+
prepend ExtendPublisher
|
12
|
+
|
4
13
|
module ClassMethods
|
5
14
|
def published(opts = {})
|
6
15
|
options = opts.clone
|
data/lib/yaps/subscriber.rb
CHANGED
data/lib/yaps/version.rb
CHANGED
data/spec/publisher_spec.rb
CHANGED
@@ -1,24 +1,48 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Yaps::Publisher do
|
4
|
-
describe '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
describe 'active record' do
|
5
|
+
describe 'when a model was created ' do
|
6
|
+
it "it should call publish" do
|
7
|
+
user = User.new(:name => 'John')
|
8
|
+
expect(user).to receive(:publish).once.with(:user_created, user)
|
9
|
+
user.save
|
10
|
+
end
|
9
11
|
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
describe 'when a model was updated ' do
|
14
|
+
it "it should call publish" do
|
15
|
+
user = User.create(:name => 'John')
|
16
|
+
user.name = 'Jack'
|
17
|
+
expect(user).to receive(:publish).once.with(:user_updated, user)
|
18
|
+
user.save
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
describe 'when a model was deleted ' do
|
23
|
+
it "it should call publish" do
|
24
|
+
user = User.create(:name => 'John')
|
25
|
+
expect(user).to receive(:publish).once.with(:user_deleted, user)
|
26
|
+
user.destroy
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '.publish' do
|
32
|
+
context 'Yaps is disable' do
|
33
|
+
it "should not publish message" do
|
34
|
+
Yaps.configuration.enable = false
|
35
|
+
user = User.create(:name => 'John')
|
36
|
+
expect(user.send(:publish, :user_created, user)).to eq(false)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'Yaps is enable' do
|
41
|
+
it "should publish message" do
|
42
|
+
Yaps.configuration.enable = true
|
43
|
+
user = User.create(:name => 'John')
|
44
|
+
expect(user.send(:publish, :user_created, user)).not_to eq(false)
|
45
|
+
end
|
22
46
|
end
|
23
47
|
end
|
24
48
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -15,18 +15,20 @@ elsif ENV["TRAVIS"] # in Travis-CI
|
|
15
15
|
end
|
16
16
|
|
17
17
|
require 'active_record'
|
18
|
-
require '
|
18
|
+
require 'database_cleaner'
|
19
19
|
|
20
20
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
21
21
|
ActiveRecord::Schema.define do
|
22
22
|
self.verbose = false
|
23
|
-
|
24
23
|
create_table :users, :force => true do |t|
|
25
24
|
t.string :name
|
26
25
|
end
|
27
26
|
end
|
27
|
+
|
28
|
+
require 'yaps'
|
28
29
|
require 'supports/user'
|
29
30
|
|
31
|
+
|
30
32
|
RSpec.configure do |config|
|
31
33
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
32
34
|
config.run_all_when_everything_filtered = true
|
@@ -37,4 +39,18 @@ RSpec.configure do |config|
|
|
37
39
|
# the seed, which is printed after each run.
|
38
40
|
# --seed 1234
|
39
41
|
config.order = 'random'
|
42
|
+
|
43
|
+
config.before(:suite) do
|
44
|
+
DatabaseCleaner.strategy = :transaction
|
45
|
+
DatabaseCleaner.clean_with(:truncation)
|
46
|
+
end
|
47
|
+
|
48
|
+
config.before(:each) do
|
49
|
+
DatabaseCleaner.start
|
50
|
+
end
|
51
|
+
|
52
|
+
config.after(:each) do
|
53
|
+
DatabaseCleaner.clean
|
54
|
+
Yaps.reset
|
55
|
+
end
|
40
56
|
end
|
data/spec/yaps_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yaps do
|
4
|
+
describe '#with_pushlisher_enable' do
|
5
|
+
it 'should enable Yaps for block in its scope' do
|
6
|
+
Yaps.configuration.enable = false
|
7
|
+
Yaps.with_pushlisher_enable do
|
8
|
+
expect(Yaps.configuration.enable).to eq(true)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should not change configuration state outside of its scope' do
|
13
|
+
Yaps.configuration.enable = false
|
14
|
+
Yaps.with_pushlisher_enable do
|
15
|
+
end
|
16
|
+
expect(Yaps.configuration.enable).to eq(false)
|
17
|
+
end
|
18
|
+
|
19
|
+
it ' should execute the block pass to it' do
|
20
|
+
a = 5
|
21
|
+
Yaps.with_pushlisher_enable do
|
22
|
+
a = 10
|
23
|
+
end
|
24
|
+
expect(a).to eq(10)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Võ Anh Duy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/yaps/actions/creation.rb
|
114
114
|
- lib/yaps/actions/destruction.rb
|
115
115
|
- lib/yaps/actions/updation.rb
|
116
|
+
- lib/yaps/configuration.rb
|
116
117
|
- lib/yaps/publisher.rb
|
117
118
|
- lib/yaps/subscriber.rb
|
118
119
|
- lib/yaps/version.rb
|
@@ -120,6 +121,7 @@ files:
|
|
120
121
|
- spec/spec_helper.rb
|
121
122
|
- spec/subscriber_spec.rb
|
122
123
|
- spec/supports/user.rb
|
124
|
+
- spec/yaps_spec.rb
|
123
125
|
- yaps.gemspec
|
124
126
|
homepage: ''
|
125
127
|
licenses:
|
@@ -150,3 +152,4 @@ test_files:
|
|
150
152
|
- spec/spec_helper.rb
|
151
153
|
- spec/subscriber_spec.rb
|
152
154
|
- spec/supports/user.rb
|
155
|
+
- spec/yaps_spec.rb
|