the_audit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in the_audit.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ilya N. Zykin
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,8 @@
1
+ # TheAudit
2
+
3
+ bundle gem the_audit
4
+ # create => gem
5
+
6
+ add engine init file lib/NAME/engine.rb and requires
7
+ # => bundle exec rake the_audit_engine:install:migrations
8
+ # => bundle exec rake db:migrate
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ class Audit < ActiveRecord::Base
2
+ belongs_to :user
3
+ belongs_to :obj, polymorphic: true
4
+
5
+ def init controller, object = nil, data = {}
6
+ self.obj = object
7
+ self.action_name = controller.action_name
8
+ self.controller_name = controller.controller_name
9
+
10
+ self.data = data.to_json unless data.blank?
11
+
12
+ if r = controller.request
13
+ self.ip = r.ip
14
+ self.user_agent = r.user_agent
15
+ self.remote_ip = r.remote_ip
16
+ self.remote_addr = r.remote_addr
17
+ self.remote_host = r.remote_host
18
+ self.fullpath = CGI::unescape(r.fullpath || '')
19
+ self.referer = CGI::unescape(r.referer || 'direct_visit')
20
+ end
21
+
22
+ self
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ class CreateAudits < ActiveRecord::Migration
2
+ def change
3
+ create_table :audits do |t|
4
+ t.integer :user_id
5
+
6
+ t.string :obj_id
7
+ t.string :obj_type
8
+
9
+ t.string :controller_name
10
+ t.string :action_name
11
+
12
+ t.string :ip
13
+ t.string :remote_ip
14
+ t.string :fullpath
15
+ t.string :referer
16
+ t.string :user_agent
17
+ t.string :remote_addr
18
+ t.string :remote_host
19
+
20
+ t.text :data
21
+
22
+ # add_index :the_audits, :referer
23
+ # add_index :the_audits, :user_agent
24
+ # add_index :the_audits, [:controller_name, :action_name]
25
+
26
+ t.timestamps
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ require 'the_audit'
2
+ require 'rails'
3
+
4
+ module TheAudit
5
+ class Engine < Rails::Engine
6
+ # initializer "Assets precompile hook", :group => :all do |app|
7
+ # app.config.assets.precompile += %w( file.js file.css )
8
+ # end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module TheAudit
2
+ VERSION = "0.0.1"
3
+ end
data/lib/the_audit.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "the_audit/engine"
2
+ require "the_audit/version"
3
+
4
+ module TheAudit; end
data/the_audit.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'the_audit/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "the_audit"
8
+ gem.version = TheAudit::VERSION
9
+ gem.authors = ["Ilya N. Zykin"]
10
+ gem.email = ["zykin-ilya@ya.ru"]
11
+ gem.description = %q{Collect basic request info in Rails app}
12
+ gem.summary = %q{Collect basic request info in Rails app}
13
+ gem.homepage = "https://github.com/the-teacher"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_audit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ilya N. Zykin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Collect basic request info in Rails app
15
+ email:
16
+ - zykin-ilya@ya.ru
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - app/models/audit.rb
27
+ - db/migrate/20130130163149_create_audits.rb
28
+ - lib/the_audit.rb
29
+ - lib/the_audit/engine.rb
30
+ - lib/the_audit/version.rb
31
+ - the_audit.gemspec
32
+ homepage: https://github.com/the-teacher
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.15
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Collect basic request info in Rails app
56
+ test_files: []