yaps 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c108342a552899949709598e601308395f24c9f
4
+ data.tar.gz: 6436fc2b02b3f0fdaf4437b03fe30ee117f72d81
5
+ SHA512:
6
+ metadata.gz: 34250e9f0a809d56e81e5fed0ac5de59bda766c895beb87849f9a5acf091c0c0d30ea25d3927862aca8f71e4ee826965b1b813093990b4a405c63b38e1ba2b66
7
+ data.tar.gz: 3633f327da83e505661bf86b695b2bc28ba8a8d9a1058edfcbddf328f77394c9a962e3d189e9af9effd8dac4666a9cc6f5874378b606ff5ad043bb65cda93e9d
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .idea
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ - 2.1.0
5
+ - 2.0.0
6
+ - 1.9.3
7
+ - jruby-19mode
8
+ - ruby-head
9
+ - jruby-head
10
+
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: jruby-head
14
+ - rvm: ruby-head
15
+ fast_finish: true
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yaps.gemspec
4
+ gemspec
5
+
6
+ gem 'coveralls', :require => false
7
+ gem 'growl' if `uname` =~ /Darwin/
8
+ gem 'guard'
9
+ gem 'guard-bundler'
10
+ gem 'guard-rspec'
11
+ gem 'simplecov', '~> 0.7.1'
12
+
13
+ gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
14
+ gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
data/Guardfile ADDED
@@ -0,0 +1,13 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :bundler do
5
+ watch('Gemfile')
6
+ watch(/^.+\.gemspec/)
7
+ end
8
+
9
+ guard :rspec do
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
12
+ watch('spec/spec_helper.rb') { "spec" }
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Võ Anh Duy
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,34 @@
1
+ # Yaps
2
+
3
+ [![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)
6
+
7
+
8
+ TODO: Write a gem description
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'yaps'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install yaps
23
+
24
+ ## Usage
25
+
26
+ TODO: Write usage instructions here
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it ( https://github.com/[my-github-username]/yaps/fork )
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
data/lib/yaps.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'wisper'
2
+ require 'yaps/actions/creation'
3
+ require 'yaps/actions/destruction'
4
+ require 'yaps/actions/updation'
5
+ require 'yaps/publisher'
6
+ require 'yaps/subscriber'
7
+ require "yaps/version"
8
+
9
+ module Yaps
10
+ # Your code goes here...
11
+ end
@@ -0,0 +1,12 @@
1
+ module Yaps
2
+ # Handles creation of Activities upon destruction and update of tracked model.
3
+ module Creation
4
+ extend ActiveSupport::Concern
5
+ include Wisper::Publisher
6
+
7
+ included do
8
+ after_create { publish(:"#{ActiveSupport::Inflector.underscore(self.class.name)}_created", self) }
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module Yaps
2
+ # Handles creation of Activities upon destruction and update of tracked model.
3
+ module Destruction
4
+ extend ActiveSupport::Concern
5
+ include Wisper::Publisher
6
+
7
+ included do
8
+ before_destroy { publish(:"#{ActiveSupport::Inflector.underscore(self.class.name)}_deleted", self) }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Yaps
2
+ # Handles creation of Activities upon destruction and update of tracked model.
3
+ module Updation
4
+ extend ActiveSupport::Concern
5
+ include Wisper::Publisher
6
+
7
+ included do
8
+ after_update { publish(:"#{ActiveSupport::Inflector.underscore(self.class.name)}_updated", self) }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,36 @@
1
+ module Yaps
2
+ module Publisher
3
+ extend ActiveSupport::Concern
4
+ module ClassMethods
5
+ def published(opts = {})
6
+ options = opts.clone
7
+ include_default_actions(options)
8
+ nil
9
+ end
10
+
11
+ def include_default_actions(options)
12
+ defaults = {
13
+ create: Creation,
14
+ destroy: Destruction,
15
+ update: Updation
16
+ }
17
+
18
+ modules = if options[:except]
19
+ defaults.except(*options[:except])
20
+ elsif options[:only]
21
+ defaults.slice(*options[:only])
22
+ else
23
+ defaults
24
+ end
25
+
26
+ modules.each do |key, value|
27
+ include value
28
+ end
29
+ end
30
+
31
+ def available_options
32
+ [:only, :except].freeze
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ module Yaps
2
+ module Subscriber
3
+ extend ActiveSupport::Concern
4
+ module ClassMethods
5
+ def subscribe(event, opts)
6
+ options = opts.clone
7
+ puts subscribe_instance.object_id
8
+ Wisper.add_listener(subscribe_instance, on: event, with: options[:with])
9
+ nil
10
+ end
11
+
12
+ def subscribe_instance
13
+ @subscribe_instance ||= self.new
14
+ end
15
+
16
+ def available_options
17
+ [:on, :with].freeze
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Yaps
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
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
9
+ end
10
+
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
16
+ end
17
+
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
+ end
23
+ end
24
+ end
@@ -0,0 +1,40 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ if ENV['COV']
8
+ require 'simplecov'
9
+ SimpleCov.start do
10
+ add_filter "/test/"
11
+ end
12
+ elsif ENV["TRAVIS"] # in Travis-CI
13
+ require 'coveralls'
14
+ Coveralls.wear!
15
+ end
16
+
17
+ require 'active_record'
18
+ require 'yaps'
19
+
20
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
21
+ ActiveRecord::Schema.define do
22
+ self.verbose = false
23
+
24
+ create_table :users, :force => true do |t|
25
+ t.string :name
26
+ end
27
+ end
28
+ require 'supports/user'
29
+
30
+ RSpec.configure do |config|
31
+ config.treat_symbols_as_metadata_keys_with_true_values = true
32
+ config.run_all_when_everything_filtered = true
33
+ config.filter_run :focus
34
+
35
+ # Run specs in random order to surface order dependencies. If you find an
36
+ # order dependency and want to debug it, you can fix the order by providing
37
+ # the seed, which is printed after each run.
38
+ # --seed 1234
39
+ config.order = 'random'
40
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yaps::Subscriber do
4
+ it 'it should receive the message' do
5
+ user = User.new :name => 'John'
6
+ expect(User.subscribe_instance).to receive(:receiver).once
7
+ user.save
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class User < ActiveRecord::Base
2
+ self.table_name = 'users'
3
+ include Yaps::Publisher
4
+ include Yaps::Subscriber
5
+ subscribe :user_created, with: :receiver
6
+ published
7
+
8
+
9
+ def receiver user
10
+ end
11
+ end
data/yaps.gemspec ADDED
@@ -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 'yaps/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yaps"
8
+ spec.version = Yaps::VERSION
9
+ spec.authors = ["Võ Anh Duy"]
10
+ spec.email = ["voanhduy1512@live.com"]
11
+ spec.summary = %q{Yet another publish subscribe gem}
12
+ spec.description = %q{Yet another publish subscribe gem}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'pry'
25
+
26
+ spec.add_dependency 'wisper'
27
+ spec.add_dependency 'activerecord', '>= 3.0'
28
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yaps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Võ Anh Duy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-09 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: '0'
20
+ type: :development
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: 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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
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: wisper
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
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: activerecord
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: Yet another publish subscribe gem
98
+ email:
99
+ - voanhduy1512@live.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Guardfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - lib/yaps.rb
113
+ - lib/yaps/actions/creation.rb
114
+ - lib/yaps/actions/destruction.rb
115
+ - lib/yaps/actions/updation.rb
116
+ - lib/yaps/publisher.rb
117
+ - lib/yaps/subscriber.rb
118
+ - lib/yaps/version.rb
119
+ - spec/publisher_spec.rb
120
+ - spec/spec_helper.rb
121
+ - spec/subscriber_spec.rb
122
+ - spec/supports/user.rb
123
+ - yaps.gemspec
124
+ homepage: ''
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.2.2
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Yet another publish subscribe gem
148
+ test_files:
149
+ - spec/publisher_spec.rb
150
+ - spec/spec_helper.rb
151
+ - spec/subscriber_spec.rb
152
+ - spec/supports/user.rb