log_fu 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.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in log_fu.gemspec
4
+ gemspec
5
+
6
+ gem 'rails', "~> 3.0.6"
7
+ gem 'mongoid'
8
+ gem 'bson_ext'
data/README.markdown ADDED
@@ -0,0 +1,23 @@
1
+ Simple Log By MongoDB!
2
+
3
+ Usage:
4
+
5
+ example:
6
+
7
+ rails g mongoid:config
8
+
9
+ gem 'log_fu'
10
+
11
+ 1. rails g log_fu:install
12
+ 2. rails g log_fu:mongo_model subject_log
13
+
14
+ *Only support MongoDB with mongoid*
15
+
16
+
17
+
18
+ TODO:
19
+
20
+ logs columns customizable
21
+
22
+
23
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/TODO ADDED
@@ -0,0 +1 @@
1
+ 1. custom logs column
@@ -0,0 +1,67 @@
1
+ module LogFu
2
+ module LogGeneral
3
+ module MongoIdModels
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ include Mongoid::Document
8
+ field :resource_type, :type => String
9
+ field :resource_id, :type => Integer
10
+ field :client_id, :type => Integer
11
+ field :channel_id, :type => Integer
12
+ field :ip, :type => String
13
+ field :uniquely_code, :type => String
14
+ field :status, :type => String
15
+ field :created_at, :type => DateTime
16
+ end
17
+
18
+ module ClassMethods
19
+ # Usage:
20
+ # In Model:
21
+ # class SubjectLog
22
+ # include LogGeneral::MongoIdModels
23
+ # define_logged_it_methods :subject
24
+ # end
25
+ #
26
+ # In Controller:
27
+ # class SubjectsController < ApplicationController
28
+ # def show
29
+ # @subject = Subject.find params[:id]
30
+ # SubjectLog.subject_logged_it(request, params)
31
+ # end
32
+ # end
33
+ #
34
+ def define_logged_it_methods name
35
+ singleton_class.class_eval do
36
+ define_method("#{name}_logged_it") do |request, params|
37
+ client_key = params[:api_key] if !params[:api_key].blank?
38
+ client_id = params[:client_id] if !params[:client_id].blank?
39
+ resource_type = name.to_s.capitalize
40
+ resource_id = params[:id] if !params[:id].blank?
41
+ client_id_by_key = Client.find_by_api_key(client_key) if client_key
42
+ channel_id = params[:channel_id] if !params[:channel_id].blank?
43
+ ip = request.remote_ip
44
+ uniquely_code = params[:uniquely_code] if !params[:uniquely_code].blank?
45
+ created_at = Time.now
46
+
47
+ create(:resource_type => resource_type,
48
+ :resource_id => resource_id,
49
+ :client_id => (client_id || client_id_by_key),
50
+ :channel_id => channel_id,
51
+ :ip => ip,
52
+ :uniquely_code => uniquely_code,
53
+ :status => 1,
54
+ :created_at => created_at)
55
+ end
56
+ end
57
+ end
58
+ end#ClassMethods
59
+
60
+ module InstanceMethods
61
+ #TODO
62
+
63
+ end#module InstanceMethods
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,16 @@
1
+ require 'rails/generators'
2
+
3
+ module LogFu
4
+ module Generators
5
+
6
+ class InstallGenerator < Rails::Generators::Base
7
+
8
+ source_root File.expand_path('../templates', __FILE__)
9
+ desc "Copies mongoid yml files to main project"
10
+ def copy_mongoid_yml_files
11
+ copy_file "../templates/mongoid.yml", "config/mongoid.yml"
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ require 'rails/generators'
2
+
3
+ module LogFu
4
+ module Generators
5
+
6
+ class MongoModelGenerator < Rails::Generators::NamedBase
7
+ def create_mongoid_model_file
8
+ create_file "app/models/#{file_name}.rb", <<-FILE
9
+ class #{class_name}
10
+ include LogFu::LogGeneral::MongoIdModels
11
+ # you need add logged it method
12
+ # example:
13
+ # define_logged_it_methods :subject
14
+ # TODO
15
+ end
16
+ FILE
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ defaults: &defaults
2
+ host: localhost
3
+ # slaves:
4
+ # - host: slave1.local
5
+ # port: 27018
6
+ # - host: slave2.local
7
+ # port: 27019
8
+
9
+ development:
10
+ <<: *defaults
11
+ database: log_fu_development
12
+
13
+ test:
14
+ <<: *defaults
15
+ database: log_fu_test
16
+
17
+ # set these environment variables on your prod server
18
+ production:
19
+ host: <%= ENV['MONGOID_HOST'] %>
20
+ port: <%= ENV['MONGOID_PORT'] %>
21
+ username: <%= ENV['MONGOID_USERNAME'] %>
22
+ password: <%= ENV['MONGOID_PASSWORD'] %>
23
+ database: <%= ENV['MONGOID_DATABASE'] %>
data/lib/log_fu.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'rails'
2
+ require 'log_fu/engine'
3
+
4
+ module LogFu
5
+ #TODO
6
+ end
@@ -0,0 +1,8 @@
1
+ require 'rails'
2
+
3
+
4
+ module LogFu
5
+ class Engine < Rails::Engine
6
+
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module LogFu
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: log_fu
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - blackanger
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-27 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 11
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 6
34
+ version: 3.0.6
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Simple website hits log with MongoDB
38
+ email:
39
+ - blackanger.z@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - README.markdown
46
+ - TODO
47
+ files:
48
+ - Gemfile
49
+ - Rakefile
50
+ - README.markdown
51
+ - TODO
52
+ - app/models/log_fu/log_general.rb
53
+ - lib/generators/log_fu/install_generator.rb
54
+ - lib/generators/log_fu/mongo_model_generator.rb
55
+ - lib/generators/log_fu/templates/mongoid.yml
56
+ - lib/log_fu/engine.rb
57
+ - lib/log_fu/version.rb
58
+ - lib/log_fu.rb
59
+ has_rdoc: true
60
+ homepage: ""
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options: []
65
+
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project: log_fu
89
+ rubygems_version: 1.6.2
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Simple hits log with MongoDB
93
+ test_files: []
94
+