rails_acclog2db 0.0.1

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.
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
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.
@@ -0,0 +1,29 @@
1
+ = RailsAcclog2db
2
+
3
+ * https://github.com/vivahiraj/rails_acclog2db
4
+
5
+ == DESCRIPTION:
6
+
7
+ rails access logs save to database.
8
+
9
+ == QUICK START
10
+
11
+ To get started with a new Rails project
12
+
13
+ Added to Gemfile
14
+
15
+ gem 'rails_acclog2db'
16
+
17
+ Run the following commands
18
+
19
+ bundle install
20
+ rails g rails_acclog2db:install
21
+ bundle exec rake db:migrate
22
+
23
+ Add the following line to controller. ex app/controllers/application_controller.rb
24
+
25
+ access_logging
26
+
27
+ == LICENSE:
28
+
29
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'RailsAcclog2db'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,33 @@
1
+ require 'rails/generators'
2
+
3
+ module RailsAcclog2db
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+
7
+ include Rails::Generators::Migration
8
+
9
+ desc <<DESC
10
+ Description:
11
+ Copies log.rb to app/models/.
12
+ Copies create_logs.rb to db/migrate
13
+
14
+ Examples:
15
+ `rails generate rails_acclog2db:install`
16
+ DESC
17
+
18
+ def self.source_root
19
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
20
+ end
21
+
22
+ def self.next_migration_number(path)
23
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
24
+ end
25
+
26
+ def create_model_file
27
+ template "log.rb", "app/models/log.rb"
28
+ migration_template "create_logs.rb", "db/migrate/create_logs.rb"
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ class CreateLogs < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :logs do |t|
4
+ t.string :login
5
+ t.string :ip
6
+ t.string :url
7
+ t.text :param
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :logs
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ class Log < ActiveRecord::Base
2
+ attr_accessible :login, :ip, :url, :param
3
+ end
@@ -0,0 +1,4 @@
1
+ require "rails_acclog2db/logging"
2
+
3
+ module RailsAcclog2db
4
+ end
@@ -0,0 +1,46 @@
1
+ module RailsAcclog2db
2
+ module Logging
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ end
7
+
8
+ module ClassMethods
9
+ def access_logging
10
+ after_filter :write_log
11
+ end
12
+ end
13
+
14
+ def write_log
15
+ log = Log.new
16
+ user = nil
17
+ if session[:user]
18
+ if session[:user].class == String
19
+ user = session[:user]
20
+ else
21
+ ["code","name","login","login_name"].each do |d|
22
+ begin
23
+ unless session[:user][d].blank?
24
+ user = session[:user][d]
25
+ break
26
+ end
27
+ unless session[:user][d.to_sym].blank?
28
+ user = session[:user][d.to_sym]
29
+ break
30
+ end
31
+ rescue => e
32
+ end
33
+ end
34
+ end
35
+ end
36
+ log.login = user
37
+ log.ip = request.remote_ip
38
+ log.url = request.url.slice(0,254)
39
+ log.param = params.inspect
40
+ log.save
41
+ end
42
+
43
+ end
44
+ end
45
+
46
+ ActionController::Base.send :include,RailsAcclog2db::Logging
@@ -0,0 +1,3 @@
1
+ module RailsAcclog2db
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :rails_acclog2db do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_acclog2db
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - vivahiraj
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &10674820 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *10674820
25
+ - !ruby/object:Gem::Dependency
26
+ name: sqlite3
27
+ requirement: &10674400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *10674400
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec-rails
38
+ requirement: &10673900 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *10673900
47
+ - !ruby/object:Gem::Dependency
48
+ name: ammeter
49
+ requirement: &10673240 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *10673240
58
+ description: rails access log save to database.
59
+ email:
60
+ - vivahiraj@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - lib/rails_acclog2db.rb
66
+ - lib/tasks/rails_acclog2db_tasks.rake
67
+ - lib/generators/rails_acclog2db/install/templates/create_logs.rb
68
+ - lib/generators/rails_acclog2db/install/templates/log.rb
69
+ - lib/generators/rails_acclog2db/install/install_generator.rb
70
+ - lib/rails_acclog2db/version.rb
71
+ - lib/rails_acclog2db/logging.rb
72
+ - MIT-LICENSE
73
+ - Rakefile
74
+ - README.rdoc
75
+ homepage: https://github.com/vivahiraj/rails_acclog2db
76
+ licenses: []
77
+ post_install_message:
78
+ rdoc_options: []
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
+ version: '0'
87
+ segments:
88
+ - 0
89
+ hash: -2254436363117046574
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ segments:
97
+ - 0
98
+ hash: -2254436363117046574
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.16
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: rails access log save to database.
105
+ test_files: []