moorage-moorage-enlightened_observers 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.textile +49 -0
- data/Rakefile +73 -0
- data/lib/enlightened_observers.rb +37 -0
- metadata +57 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 ThriveSmart, LLC
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
h1. EnlightenedObservers
|
2
|
+
|
3
|
+
This plugin makes it quick and easy to share the controller information with observers, including session information. This is useful when observers need to report the current_user that made a certain action happen.
|
4
|
+
|
5
|
+
The code and idea for this plugin comes from:
|
6
|
+
"Garry Dolley's Let ActiveRecord Observers see controller context":http://scie.nti.st/2007/2/1/let-activerecord-observers-see-controller-context
|
7
|
+
|
8
|
+
|
9
|
+
h2. Usage
|
10
|
+
|
11
|
+
<pre>
|
12
|
+
class MyController < ActionController::Base
|
13
|
+
include EnlightenedObservers
|
14
|
+
|
15
|
+
observer :my_observer
|
16
|
+
end
|
17
|
+
</pre>
|
18
|
+
|
19
|
+
Now my_observer has access to a controller instance variable, which can be used to access the session.
|
20
|
+
e.g.
|
21
|
+
|
22
|
+
|
23
|
+
h2. Installation
|
24
|
+
|
25
|
+
To enable the library your Rails 2.1 (or greater) project, use the gem configuration method in "<code>config/environment.rb</code>"
|
26
|
+
|
27
|
+
<pre>
|
28
|
+
Rails::Initializer.run do |config|
|
29
|
+
config.gem 'moorage-enlightened_observers', :source => 'http://gems.github.com'
|
30
|
+
end
|
31
|
+
</pre>
|
32
|
+
|
33
|
+
And of course, run
|
34
|
+
|
35
|
+
<pre>
|
36
|
+
rake gems:install
|
37
|
+
</pre>
|
38
|
+
|
39
|
+
To get them installed on your system.
|
40
|
+
|
41
|
+
Optionally, to unpack it into your application, just run:
|
42
|
+
|
43
|
+
<pre>
|
44
|
+
rake gems:unpack GEM=moorage-enlightened_observers
|
45
|
+
</pre>
|
46
|
+
|
47
|
+
|
48
|
+
=======
|
49
|
+
Copyright (c) 2008 ThriveSmart, LLC, based on code by Garry Dolley, released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rubygems/specification'
|
5
|
+
# require 'spec/rake/spectask'
|
6
|
+
require 'date'
|
7
|
+
|
8
|
+
GEM = "enlightened_observers"
|
9
|
+
HUMANIZED_GEM = "EnlightenedObservers"
|
10
|
+
GEM_VERSION = "1.0.20080915"
|
11
|
+
AUTHOR = "ThriveSmart, LLC"
|
12
|
+
EMAIL = "developers@thrivesmart.com"
|
13
|
+
HOMEPAGE = "http://www.github.com/moorage/enlightened_observers"
|
14
|
+
SUMMARY = "Quick and easily share the controller information with observers, including session information."
|
15
|
+
|
16
|
+
spec = Gem::Specification.new do |s|
|
17
|
+
s.name = GEM
|
18
|
+
s.version = GEM_VERSION
|
19
|
+
s.platform = Gem::Platform::RUBY
|
20
|
+
s.rubyforge_project = GEM
|
21
|
+
s.has_rdoc = true
|
22
|
+
s.extra_rdoc_files = ['README.textile', 'LICENSE']
|
23
|
+
s.summary = SUMMARY
|
24
|
+
s.description = s.summary
|
25
|
+
s.author = AUTHOR
|
26
|
+
s.email = EMAIL
|
27
|
+
s.homepage = HOMEPAGE
|
28
|
+
|
29
|
+
# Uncomment this to add a dependency
|
30
|
+
# s.add_dependency "foo"
|
31
|
+
|
32
|
+
s.require_path = 'lib'
|
33
|
+
s.files = %w(LICENSE README.textile Rakefile) + Dir.glob("{lib,spec}/**/*")
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Run Specs"
|
37
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
38
|
+
pkg.gem_spec = spec
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Generate Documentation"
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
rdoc.rdoc_dir = 'doc'
|
44
|
+
rdoc.title = HUMANIZED_GEM
|
45
|
+
rdoc.options << '--line-numbers' << '--inline-source' << '--main' << HUMANIZED_GEM
|
46
|
+
rdoc.rdoc_files.include(FileList[ 'lib/**/*.rb', 'README.textile', 'LICENSE'])
|
47
|
+
end
|
48
|
+
|
49
|
+
task :default => :spec
|
50
|
+
task :specs => :spec
|
51
|
+
|
52
|
+
# desc "Run all examples"
|
53
|
+
# Spec::Rake::SpecTask.new('spec') do |t|
|
54
|
+
# t.spec_opts = ['--options','spec/spec.opts']
|
55
|
+
# t.spec_files = FileList['spec/**/*.rb']
|
56
|
+
# t.rcov = true
|
57
|
+
# end
|
58
|
+
|
59
|
+
desc "install the gem locally"
|
60
|
+
task :install => [:package] do
|
61
|
+
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "create a gemspec file"
|
65
|
+
task :make_spec do
|
66
|
+
File.open("#{GEM}.gemspec", "w") do |file|
|
67
|
+
file.puts spec.to_ruby
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
task :bugs do
|
72
|
+
sh %{ditz html ; open html/index.html}
|
73
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module EnlightenedObservers
|
2
|
+
def self.included(base)
|
3
|
+
base.extend(ClassMethods)
|
4
|
+
end
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def observer(*observers)
|
8
|
+
super
|
9
|
+
|
10
|
+
configuration = observers.last.is_a?(Hash) ? observers.pop : {}
|
11
|
+
observers.each do |observer|
|
12
|
+
observer_instance = Object.const_get(Inflector.classify(observer)).instance
|
13
|
+
class <<observer_instance
|
14
|
+
include Enlightenment
|
15
|
+
end
|
16
|
+
|
17
|
+
around_filter(observer_instance, :only => configuration[:only])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module Enlightenment
|
23
|
+
def self.included(base)
|
24
|
+
base.module_eval do
|
25
|
+
attr_accessor :controller
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def before(controller)
|
30
|
+
self.controller = controller
|
31
|
+
end
|
32
|
+
|
33
|
+
def after(controller)
|
34
|
+
self.controller = nil # Clean up for GC
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: moorage-moorage-enlightened_observers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "1.0"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ThriveSmart, LLC
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-09-05 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Quick and easily share the controller information with observers, including session information.
|
17
|
+
email: developers@thrivesmart.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.textile
|
24
|
+
- LICENSE
|
25
|
+
files:
|
26
|
+
- LICENSE
|
27
|
+
- README.textile
|
28
|
+
- Rakefile
|
29
|
+
- lib/enlightened_observers.rb
|
30
|
+
has_rdoc: false
|
31
|
+
homepage: http://www.github.com/moorage/enlightened_observers
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "0"
|
42
|
+
version:
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.2.0
|
53
|
+
signing_key:
|
54
|
+
specification_version: 2
|
55
|
+
summary: Quick and easily share the controller information with observers, including session information.
|
56
|
+
test_files: []
|
57
|
+
|