active_model_listener 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ .idea
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "active_model_listener"
8
+ gem.summary = %Q{Simple, global ActiveRecord event observers, using a middleware architecture, that can easily be turned on and off. Designed for audit trails, activity feeds and other app-level event handlers}
9
+ gem.email = "jeff@zilkey.com"
10
+ gem.homepage = "http://github.com/zilkey/active_model_listener"
11
+ gem.authors = ["Jeff Dean"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'spec/rake/spectask'
20
+ Spec::Rake::SpecTask.new(:spec) do |spec|
21
+ spec.libs << 'lib' << 'spec'
22
+ spec.spec_files = FileList['spec/**/*_spec.rb']
23
+ end
24
+
25
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.pattern = 'spec/**/*_spec.rb'
28
+ spec.rcov = true
29
+ end
30
+
31
+
32
+ task :default => :spec
33
+
34
+ require 'rake/rdoctask'
35
+ Rake::RDocTask.new do |rdoc|
36
+ if File.exist?('VERSION.yml')
37
+ config = YAML.load(File.read('VERSION.yml'))
38
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
39
+ else
40
+ version = ""
41
+ end
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "active_model_listener #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
48
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.1
@@ -0,0 +1,47 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{active_model_listener}
5
+ s.version = "0.2.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Jeff Dean"]
9
+ s.date = %q{2009-10-03}
10
+ s.email = %q{jeff@zilkey.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.md"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.md",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "active_model_listener.gemspec",
23
+ "lib/active_model_listener.rb",
24
+ "lib/active_model_listener/active_model_listener.rb",
25
+ "spec/active_model_listener_spec.rb",
26
+ "spec/spec_helper.rb"
27
+ ]
28
+ s.homepage = %q{http://github.com/zilkey/active_model_listener}
29
+ s.rdoc_options = ["--charset=UTF-8"]
30
+ s.require_paths = ["lib"]
31
+ s.rubygems_version = %q{1.3.3}
32
+ s.summary = %q{Simple, global ActiveRecord event observers, using a middleware architecture, that can easily be turned on and off. Designed for audit trails, activity feeds and other app-level event handlers}
33
+ s.test_files = [
34
+ "spec/active_model_listener_spec.rb",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
43
+ else
44
+ end
45
+ else
46
+ end
47
+ end
@@ -0,0 +1,33 @@
1
+ class ActiveModelListener
2
+
3
+ class << self
4
+ def listeners
5
+ @listeners ||= []
6
+ end
7
+
8
+ def listeners=(listeners)
9
+ @listeners = listeners
10
+ end
11
+
12
+ def dispatch(object, action)
13
+ self.listeners.each do |listener|
14
+ listener.send "after_#{action}", object
15
+ end
16
+ end
17
+
18
+ def without_listeners
19
+ with_listeners([]) do
20
+ yield
21
+ end
22
+ end
23
+
24
+ def with_listeners(*listeners)
25
+ original_listeners = self.listeners
26
+ self.listeners = listeners.flatten
27
+ yield
28
+ ensure
29
+ self.listeners = original_listeners
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,30 @@
1
+ require 'activerecord'
2
+ require 'active_model_listener/active_model_listener'
3
+
4
+ module WireUpModels
5
+
6
+ def self.included(base)
7
+ base.send(:extend, ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ def inherited(child)
12
+ super
13
+
14
+ child.after_create do |record|
15
+ ActiveModelListener.dispatch record, :create
16
+ end
17
+
18
+ child.after_update do |record|
19
+ ActiveModelListener.dispatch record, :update
20
+ end
21
+
22
+ child.after_destroy do |record|
23
+ ActiveModelListener.dispatch record, :destroy
24
+ end
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ ActiveRecord::Base.send(:include, WireUpModels)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_listener
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dean
@@ -23,8 +23,17 @@ extra_rdoc_files:
23
23
  - LICENSE
24
24
  - README.md
25
25
  files:
26
+ - .document
27
+ - .gitignore
26
28
  - LICENSE
27
29
  - README.md
30
+ - Rakefile
31
+ - VERSION
32
+ - active_model_listener.gemspec
33
+ - lib/active_model_listener.rb
34
+ - lib/active_model_listener/active_model_listener.rb
35
+ - spec/active_model_listener_spec.rb
36
+ - spec/spec_helper.rb
28
37
  has_rdoc: true
29
38
  homepage: http://github.com/zilkey/active_model_listener
30
39
  licenses: []