acts_as_protocolable 0.1.0
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/Manifest.txt +7 -0
- data/README.textile +0 -0
- data/Rakefile.rb +18 -0
- data/VERSION +1 -0
- data/generators/acts_as_protocolable_migration/acts_as_protocolable_migration_generator.rb +7 -0
- data/generators/acts_as_protocolable_migration/templates/migration.rb +25 -0
- data/lib/acts_as_protocolable/base.rb +37 -0
- data/lib/acts_as_protocolable/for_model.rb +3 -0
- data/lib/acts_as_protocolable.rb +57 -0
- data/test/test_acts_as_protocolable.rb +8 -0
- metadata +107 -0
data/Manifest.txt
ADDED
data/README.textile
ADDED
File without changes
|
data/Rakefile.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "acts_as_protocolable"
|
5
|
+
gemspec.authors = ["Igor Alexandrov"]
|
6
|
+
gemspec.email = "igor.alexandrov@gmail.com"
|
7
|
+
gemspec.homepage = "http://github.com/igor-alexandrov/acts_as_protocolable"
|
8
|
+
|
9
|
+
gemspec.summary = "Guard of activity in your rails application."
|
10
|
+
gemspec.description = "ActsAsProtocolable is the easiest way to protocol user activity inside your Rails admin interface."
|
11
|
+
gemspec.files = FileList["[A-Z]*", "{generators,lib}/**/*"] - FileList["**/*.log"]
|
12
|
+
gemspec.add_dependency("sys-admin", ">= 1.5.2")
|
13
|
+
gemspec.add_dependency("activerecord", ">= 2.3.0")
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
18
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class ActsAsProtocolableMigration < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :protocol do |t|
|
4
|
+
t.datetime :created_at
|
5
|
+
t.string :affected_object_type
|
6
|
+
t.integer :affected_object_id
|
7
|
+
t.string :action_type
|
8
|
+
t.integer :internal_user_id
|
9
|
+
t.string :system_user_login
|
10
|
+
t.boolean :is_console_action
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
add_index :protocol, :affected_object_type
|
15
|
+
add_index :protocol, :affected_object_id
|
16
|
+
add_index :protocol, :action_type
|
17
|
+
add_index :protocol, :internal_user_id
|
18
|
+
add_index :protocol, :system_user_login
|
19
|
+
add_index :protocol, :is_console_action
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.down
|
23
|
+
drop_table :protocol
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_record'
|
3
|
+
require 'sys/admin'
|
4
|
+
|
5
|
+
class ActsAsProtocolable::Base < ActiveRecord::Base
|
6
|
+
set_table_name 'protocol'
|
7
|
+
|
8
|
+
#All attributes of Protocol should be read-only
|
9
|
+
attr_readonly :created_at,
|
10
|
+
:affected_object_type,
|
11
|
+
:affected_object_id,
|
12
|
+
:action_type,
|
13
|
+
:internal_user_id,
|
14
|
+
:system_user_login,
|
15
|
+
:is_console_action
|
16
|
+
|
17
|
+
attr_accessible :affected_object_type,
|
18
|
+
:affected_object_id,
|
19
|
+
:action_type,
|
20
|
+
:internal_user_id
|
21
|
+
|
22
|
+
|
23
|
+
def after_initialize
|
24
|
+
return unless new_record?
|
25
|
+
self.is_console_action = self.called_from_console?
|
26
|
+
self.system_user_login = self.get_system_user_login
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
def called_from_console?
|
31
|
+
(defined? IRB) ? true : false
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_system_user_login
|
35
|
+
Sys::Admin.get_login
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module ActsAsProtocolable
|
2
|
+
mattr_accessor :internal_user_id
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
def acts_as_protocoled(options = {})
|
6
|
+
self.acts_as_protocoled_model(options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def acts_as_protocoled_model(options = {})
|
10
|
+
puts "!!!!!!"
|
11
|
+
puts options
|
12
|
+
puts "!!!!!!"
|
13
|
+
include ActsAsProtocoled::InstanceMethods
|
14
|
+
|
15
|
+
unless options.has_key?(:only)
|
16
|
+
after_create :protocol_on_create
|
17
|
+
after_update :protocol_on_update
|
18
|
+
after_destroy :protocol_on_destroy
|
19
|
+
else
|
20
|
+
options[:only].each do |action|
|
21
|
+
class_eval("after_#{action.to_s} :protocol_on_#{action.to_s}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module InstanceMethods
|
28
|
+
protected
|
29
|
+
def protocol_on_create
|
30
|
+
ActsAsProtocoled::Base.create(
|
31
|
+
:affected_object_type => self.class.to_s,
|
32
|
+
:affected_object_id => self.id,
|
33
|
+
:action_type => "CREATE",
|
34
|
+
:internal_user_id => ActsAsProtocoled.internal_user_id
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def protocol_on_update
|
39
|
+
ActsAsProtocoled::Base.create(
|
40
|
+
:affected_object_type => self.class.to_s,
|
41
|
+
:affected_object_id => self.id,
|
42
|
+
:action_type => "UPDATE",
|
43
|
+
:internal_user_id => ActsAsProtocoled.internal_user_id
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def protocol_on_destroy
|
48
|
+
ActsAsProtocoled::Base.create(
|
49
|
+
:affected_object_type => self.class.to_s,
|
50
|
+
:affected_object_id => self.id,
|
51
|
+
:action_type => "DESTROY",
|
52
|
+
:internal_user_id => ActsAsProtocoled.internal_user_id
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_protocolable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Igor Alexandrov
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-21 00:00:00 +04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: sys-admin
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 5
|
33
|
+
- 2
|
34
|
+
version: 1.5.2
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: activerecord
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 3
|
49
|
+
- 0
|
50
|
+
version: 2.3.0
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
description: ActsAsProtocolable is the easiest way to protocol user activity inside your Rails admin interface.
|
54
|
+
email: igor.alexandrov@gmail.com
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files:
|
60
|
+
- README.textile
|
61
|
+
files:
|
62
|
+
- Manifest.txt
|
63
|
+
- README.textile
|
64
|
+
- Rakefile.rb
|
65
|
+
- VERSION
|
66
|
+
- generators/acts_as_protocolable_migration/acts_as_protocolable_migration_generator.rb
|
67
|
+
- generators/acts_as_protocolable_migration/templates/migration.rb
|
68
|
+
- lib/acts_as_protocolable.rb
|
69
|
+
- lib/acts_as_protocolable/base.rb
|
70
|
+
- lib/acts_as_protocolable/for_model.rb
|
71
|
+
- test/test_acts_as_protocolable.rb
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: http://github.com/igor-alexandrov/acts_as_protocolable
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options:
|
78
|
+
- --charset=UTF-8
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
requirements: []
|
100
|
+
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.3.7
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Guard of activity in your rails application.
|
106
|
+
test_files:
|
107
|
+
- test/test_acts_as_protocolable.rb
|