yaps 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c108342a552899949709598e601308395f24c9f
4
- data.tar.gz: 6436fc2b02b3f0fdaf4437b03fe30ee117f72d81
3
+ metadata.gz: 1f038f5a5b9462fc600d5162daa0b4306c1ae49e
4
+ data.tar.gz: 6a3e36e66fb80b577ba819d30f5d5d508d5efce2
5
5
  SHA512:
6
- metadata.gz: 34250e9f0a809d56e81e5fed0ac5de59bda766c895beb87849f9a5acf091c0c0d30ea25d3927862aca8f71e4ee826965b1b813093990b4a405c63b38e1ba2b66
7
- data.tar.gz: 3633f327da83e505661bf86b695b2bc28ba8a8d9a1058edfcbddf328f77394c9a962e3d189e9af9effd8dac4666a9cc6f5874378b606ff5ad043bb65cda93e9d
6
+ metadata.gz: 815993f74938609c045c9e12565feaf1fcc8748a9c187c09140f048ea5d40eb4c5fc2e296a68a3fdacccd2dd8cfb38d8a138944a719369a788dd50f16fbc2217
7
+ data.tar.gz: 7c1bde4ac94a08c291880d98ba51757c6b30ab6b188dd2c9cb19f25cb7305ffb4709e23b8b06d1df7747395f44f4565ac176d8a6f08107b00bd62485f7bf8e05
data/.travis.yml CHANGED
@@ -3,13 +3,9 @@ rvm:
3
3
  - 2.1.1
4
4
  - 2.1.0
5
5
  - 2.0.0
6
- - 1.9.3
7
- - jruby-19mode
8
6
  - ruby-head
9
- - jruby-head
10
7
 
11
8
  matrix:
12
9
  allow_failures:
13
- - rvm: jruby-head
14
10
  - rvm: ruby-head
15
11
  fast_finish: true
data/Gemfile CHANGED
@@ -9,6 +9,6 @@ gem 'guard'
9
9
  gem 'guard-bundler'
10
10
  gem 'guard-rspec'
11
11
  gem 'simplecov', '~> 0.7.1'
12
+ gem 'database_cleaner'
12
13
 
13
- gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
14
- gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
14
+ gem "sqlite3"
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](https://coveralls.io/repos/voanhduy1512/yaps/badge.png)](https://coveralls.io/r/voanhduy1512/yaps)
5
- [![Code Climate](https://codeclimate.com/github/voanhduy1512/yaps.png)](https://codeclimate.com/github/voanhduy1512/yaps)
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
- # Your code goes here...
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 { publish(:"#{ActiveSupport::Inflector.underscore(self.class.name)}_created", self) }
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 { publish(:"#{ActiveSupport::Inflector.underscore(self.class.name)}_deleted", self) }
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 { publish(:"#{ActiveSupport::Inflector.underscore(self.class.name)}_updated", self) }
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
@@ -0,0 +1,13 @@
1
+ module Yaps
2
+ class Configuration
3
+ attr_accessor :enable
4
+
5
+ def enable?
6
+ return enable
7
+ end
8
+
9
+ def initialize
10
+ @enable = true
11
+ end
12
+ end
13
+ end
@@ -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
@@ -4,7 +4,6 @@ module Yaps
4
4
  module ClassMethods
5
5
  def subscribe(event, opts)
6
6
  options = opts.clone
7
- puts subscribe_instance.object_id
8
7
  Wisper.add_listener(subscribe_instance, on: event, with: options[:with])
9
8
  nil
10
9
  end
data/lib/yaps/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yaps
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,24 +1,48 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Yaps::Publisher do
4
- describe 'messages' do
5
- it "it should fired a message after create" do
6
- user = User.new(:name => 'John')
7
- expect(user).to receive(:publish).once.with(:user_created, user)
8
- user.save
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
- it "it should fired a message after update" do
12
- user = User.create(:name => 'John')
13
- user.name = 'Jack'
14
- expect(user).to receive(:publish).once.with(:user_updated, user)
15
- user.save
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
- it "it should fired a message after update" do
19
- user = User.create(:name => 'John')
20
- expect(user).to receive(:publish).once.with(:user_deleted, user)
21
- user.destroy
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 'yaps'
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.1
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-09 00:00:00.000000000 Z
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