katsudo 0.0.2 → 0.0.4
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.
- data/CHANGELOG +7 -0
- data/katsudo.gemspec +2 -0
- data/lib/katsudo/controller.rb +67 -0
- data/lib/katsudo/engine.rb +2 -0
- data/lib/katsudo/railtie.rb +2 -2
- data/lib/katsudo/version.rb +1 -1
- metadata +21 -7
- data/lib/katsudo/dispatch.rb +0 -8
- data/lib/katsudo/dispatch/controller_extension.rb +0 -70
- data/lib/katsudo/dispatch/flash_stack.rb +0 -57
data/CHANGELOG
CHANGED
data/katsudo.gemspec
CHANGED
@@ -12,6 +12,8 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.description = %q{User activity for Rails}
|
13
13
|
gem.summary = %q{Stores activity traces + Flashing subsystem}
|
14
14
|
|
15
|
+
gem.add_dependency "active_tools"
|
16
|
+
|
15
17
|
gem.files = `git ls-files`.split($/)
|
16
18
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
19
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Katsudo
|
2
|
+
class Collector < Array
|
3
|
+
def store!
|
4
|
+
each {|activity| activity.save}
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
module ControllerExtension
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
name = Katsudo.config.name
|
12
|
+
class_name = Katsudo.config.activity_class_name
|
13
|
+
activity_user = "#{name}_user"
|
14
|
+
filter_method_name = "track_#{name}"
|
15
|
+
|
16
|
+
module_eval <<-EOV
|
17
|
+
|
18
|
+
included do
|
19
|
+
helper_method :#{name}, :#{activity_user}
|
20
|
+
end
|
21
|
+
|
22
|
+
module ClassMethods
|
23
|
+
|
24
|
+
def #{filter_method_name}(*args)
|
25
|
+
options = args.extract_options!
|
26
|
+
class_eval do
|
27
|
+
before_filter options do
|
28
|
+
@katsudo_collector ||= Katsudo::Collector.new
|
29
|
+
end
|
30
|
+
after_filter options do
|
31
|
+
@katsudo_collector.store!
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def #{name}(name, resource=nil)
|
39
|
+
activity_class = name.to_s.classify.constantize
|
40
|
+
if activity_class <= #{class_name}
|
41
|
+
activity = activity_class.new(:user => #{activity_user}, :resource => resource)
|
42
|
+
else
|
43
|
+
raise(TypeError, "#{class_name} expected: \#{activity_class.class} passed")
|
44
|
+
end
|
45
|
+
if @katsudo_collector
|
46
|
+
activity.tap {|a| @katsudo_collector << a}
|
47
|
+
else
|
48
|
+
@last_activity = activity
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def #{name}_message(*args)
|
53
|
+
activity = #{name}(*args)
|
54
|
+
{activity.flash_key => render_to_string(activity)}
|
55
|
+
end
|
56
|
+
|
57
|
+
def last_#{name}
|
58
|
+
@last_#{name}||@katsudo_collector.try(:last)
|
59
|
+
end
|
60
|
+
|
61
|
+
def #{activity_user} # override
|
62
|
+
current_user
|
63
|
+
end
|
64
|
+
|
65
|
+
EOV
|
66
|
+
end
|
67
|
+
end
|
data/lib/katsudo/engine.rb
CHANGED
data/lib/katsudo/railtie.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rails'
|
2
2
|
require 'katsudo/models'
|
3
|
-
require 'katsudo/
|
3
|
+
require 'katsudo/controller'
|
4
4
|
|
5
5
|
module Katsudo
|
6
6
|
class Railtie < ::Rails::Railtie
|
@@ -9,7 +9,7 @@ module Katsudo
|
|
9
9
|
include ActiveRecordExtension
|
10
10
|
end
|
11
11
|
ActiveSupport.on_load(:action_controller) do
|
12
|
-
include
|
12
|
+
include ControllerExtension
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
data/lib/katsudo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katsudo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-01-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: active_tools
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
description: User activity for Rails
|
15
31
|
email:
|
16
32
|
- addagger@gmail.com
|
@@ -27,9 +43,7 @@ files:
|
|
27
43
|
- katsudo.gemspec
|
28
44
|
- lib/katsudo.rb
|
29
45
|
- lib/katsudo/configuration.rb
|
30
|
-
- lib/katsudo/
|
31
|
-
- lib/katsudo/dispatch/controller_extension.rb
|
32
|
-
- lib/katsudo/dispatch/flash_stack.rb
|
46
|
+
- lib/katsudo/controller.rb
|
33
47
|
- lib/katsudo/engine.rb
|
34
48
|
- lib/katsudo/models.rb
|
35
49
|
- lib/katsudo/models/activity.rb
|
@@ -58,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
72
|
version: '0'
|
59
73
|
requirements: []
|
60
74
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.8.
|
75
|
+
rubygems_version: 1.8.25
|
62
76
|
signing_key:
|
63
77
|
specification_version: 3
|
64
78
|
summary: Stores activity traces + Flashing subsystem
|
data/lib/katsudo/dispatch.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
module Katsudo
|
2
|
-
module Dispatch
|
3
|
-
|
4
|
-
class Collector < Array
|
5
|
-
def store!
|
6
|
-
each {|activity| activity.save}
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
module ControllerExtension
|
11
|
-
extend ActiveSupport::Concern
|
12
|
-
|
13
|
-
name = Katsudo.config.name
|
14
|
-
class_name = Katsudo.config.activity_class_name
|
15
|
-
activity_user = "#{name}_user"
|
16
|
-
filter_method_name = "track_#{name}"
|
17
|
-
|
18
|
-
module_eval <<-EOV
|
19
|
-
|
20
|
-
included do
|
21
|
-
helper_method :#{name}, :#{activity_user}
|
22
|
-
end
|
23
|
-
|
24
|
-
module ClassMethods
|
25
|
-
|
26
|
-
def #{filter_method_name}(*args)
|
27
|
-
options = args.extract_options!
|
28
|
-
class_eval do
|
29
|
-
before_filter options do
|
30
|
-
@katsudo_collector ||= Katsudo::Dispatch::Collector.new
|
31
|
-
end
|
32
|
-
after_filter options do
|
33
|
-
@katsudo_collector.store!
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
def #{name}(name, resource=nil)
|
41
|
-
activity_class = name.to_s.classify.constantize
|
42
|
-
if activity_class <= #{class_name}
|
43
|
-
activity = activity_class.new(:user => #{activity_user}, :resource => resource)
|
44
|
-
else
|
45
|
-
raise(TypeError, "#{class_name} expected: \#{activity_class.class} passed")
|
46
|
-
end
|
47
|
-
if @katsudo_collector
|
48
|
-
activity.tap {|a| @katsudo_collector << a}
|
49
|
-
else
|
50
|
-
@last_activity = activity
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def #{name}_message(*args)
|
55
|
-
activity = #{name}(*args)
|
56
|
-
{activity.flash_key => render_to_string(activity)}
|
57
|
-
end
|
58
|
-
|
59
|
-
def last_#{name}
|
60
|
-
@last_#{name}||@katsudo_collector.try(:last)
|
61
|
-
end
|
62
|
-
|
63
|
-
def #{activity_user} # override
|
64
|
-
current_user
|
65
|
-
end
|
66
|
-
|
67
|
-
EOV
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
module Katsudo
|
2
|
-
module Dispatch
|
3
|
-
|
4
|
-
class FlashStack
|
5
|
-
def initialize(flash)
|
6
|
-
@flash = flash
|
7
|
-
@stack = {}
|
8
|
-
end
|
9
|
-
|
10
|
-
def []=(k,v)
|
11
|
-
@stack[k] = Array(v)
|
12
|
-
end
|
13
|
-
|
14
|
-
def [](k)
|
15
|
-
@stack[k] ||= []
|
16
|
-
end
|
17
|
-
|
18
|
-
def method_missing(*args, &block)
|
19
|
-
@stack.send(*args, &block)
|
20
|
-
end
|
21
|
-
|
22
|
-
def use
|
23
|
-
@stack.dup.tap do
|
24
|
-
@stack.clear
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
module FlashHashExtension
|
31
|
-
extend ActiveSupport::Concern
|
32
|
-
|
33
|
-
included do
|
34
|
-
class_eval do
|
35
|
-
def empty?
|
36
|
-
@flashes.empty? && (@stack.nil? ? true : @stack.empty?)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def <<(*hashes)
|
42
|
-
hashes.each do |hash|
|
43
|
-
hash.each do |k,v|
|
44
|
-
Array(v).each do |value|
|
45
|
-
stack[k] << value
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def stack
|
52
|
-
@stack ||= FlashStack.new(self)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|