activity_log 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 activity_log.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mike Slaven
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.
@@ -0,0 +1,62 @@
1
+ # ActivityLog
2
+
3
+ A very simple activity logging facility, used to record a log of events attached to a unique ID.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'activity_log'
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install activity_log
18
+
19
+ Once you have the gem installed, execute:
20
+ $ rails g activity_log:install
21
+
22
+ followed by
23
+
24
+ $ rake db:migrate
25
+
26
+ This will create the activity_log_entry model and migration as well as creating the new table in the database.
27
+
28
+ ## Usage
29
+
30
+ Once installed you can then add new activity log entries with by first including the actvity_log library via:
31
+
32
+ class MyController < ApplicationController
33
+ include ActivityLog
34
+
35
+ and use the following methods to add and retrieve activity log entries:
36
+ Create a new entry:
37
+ ```ruby
38
+ ActivityLog.log(owner_id, "user logged in")
39
+ ```
40
+
41
+ Retrieve a single entry
42
+ ```ruby
43
+ @entry = ActivityLog.get_by_id(activity_log_entry_id)
44
+ ```
45
+
46
+ Retrieve all entries for a unique id
47
+ ```ruby
48
+ @entries = ActivityLog.get_by_owner(owner_id)
49
+ ```
50
+
51
+ Retrieve all entries for a unique id within a specific timeframe
52
+ ```ruby
53
+ @entries = ActivityLog.get_by_owner_and_range(owner_id, start_date, end_date)
54
+ ```
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
60
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
61
+ 4. Push to the branch (`git push origin my-new-feature`)
62
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'activity_log/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "activity_log"
8
+ gem.version = ActivityLog::VERSION
9
+ gem.authors = ["Mike"]
10
+ gem.email = ["mslaven@gmail.com"]
11
+ gem.description = %q{Provides a simple activity logging and retrieval facility}
12
+ gem.summary = %q{Simple Activity Logging Facility}
13
+ gem.homepage = ""
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
+
20
+
21
+ gem.add_runtime_dependency(%q<rails>, [">= 3.2.0"])
22
+ end
@@ -0,0 +1,26 @@
1
+ require "activity_log/version"
2
+
3
+ module ActivityLog
4
+
5
+ def self.log(owner_id, data)
6
+ log_entry = ActivityLogEntry.new
7
+ log_entry.uid = owner_id unless owner_id.nil?
8
+ log_entry.data = data unless data.nil?
9
+
10
+ return log_entry.save
11
+ end
12
+
13
+ def self.get_by_owner(owner_id)
14
+ ActivityLogEntry.all(:conditions => {:uid => owner_id})
15
+ end
16
+
17
+ def self.get_by_owner_and_range(owner_id, start_date = nil, end_date = nil)
18
+ start_date = Time.now - 50.years if start_date.nil?
19
+ end_date = Time.now + 1.years if end_date.nil?
20
+ ActivityLogEntry.all(:conditions => {:uid => owner_id, :created_at => start_date..end_date})
21
+ end
22
+
23
+ def self.get_by_id(id)
24
+ ActivityLogEntry.find_by_id(id)
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module ActivityLog
2
+ VERSION = "0.0.5"
3
+ end
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ # Copyright (c) 2012 Mike Slaven
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.
23
+
24
+ require 'rails/generators/migration'
25
+
26
+ module ActivityLog
27
+ module Generators
28
+ class InstallGenerator < ::Rails::Generators::Base
29
+ include Rails::Generators::Migration
30
+ source_root File.expand_path('../templates', __FILE__)
31
+ desc "This generator creates an ActivityLog model, and generates migrations for the activity_log gem."
32
+
33
+ def self.next_migration_number(path)
34
+ unless @prev_migration_nr
35
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
36
+ else
37
+ @prev_migration_nr += 1
38
+ end
39
+ @prev_migration_nr.to_s
40
+ end
41
+
42
+ def copy_migrations
43
+ migration_template "create_activity_log_entry.rb", "db/migrate/create_activity_log_entry.rb"
44
+ end
45
+
46
+ def copy_the_activity_log_model
47
+ copy_file "activity_log_entry.rb", "app/models/activity_log_entry.rb"
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,15 @@
1
+ class ActivityLogEntry < ActiveRecord::Base
2
+
3
+ validates :uid, :presence => true
4
+ validates :data, :presence => true
5
+
6
+ attr_accessible :uid, :data
7
+
8
+ before_save :set_defaults
9
+
10
+ def set_defaults
11
+ self.uid = 0 unless self.uid
12
+ self.data = "" unless self.data
13
+ end
14
+
15
+ end
@@ -0,0 +1,9 @@
1
+ class CreateActivityLogEntry < ActiveRecord::Migration
2
+ def change
3
+ create_table :activity_log_entries do |t|
4
+ t.integer :uid
5
+ t.string :data
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
metadata CHANGED
@@ -1,61 +1,74 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activity_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mike
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-14 00:00:00.000000000 Z
12
+ date: 2013-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
16
+ version_requirements: !ruby/object:Gem::Requirement
18
17
  requirements:
19
- - - ! '>='
18
+ - - ">="
20
19
  - !ruby/object:Gem::Version
21
20
  version: 3.2.0
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
21
  none: false
22
+ requirement: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.2.0
27
+ none: false
28
+ prerelease: false
29
+ type: :runtime
30
30
  description: Provides a simple activity logging and retrieval facility
31
31
  email:
32
32
  - mslaven@gmail.com
33
33
  executables: []
34
34
  extensions: []
35
35
  extra_rdoc_files: []
36
- files: []
36
+ files:
37
+ - ".gitignore"
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - activity_log.gemspec
43
+ - lib/activity_log.rb
44
+ - lib/activity_log/version.rb
45
+ - lib/generators/activity_log/install/install_generator.rb
46
+ - lib/generators/activity_log/install/templates/activity_log_entry.rb
47
+ - lib/generators/activity_log/install/templates/create_activity_log_entry.rb
37
48
  homepage: ''
38
49
  licenses: []
39
- post_install_message:
50
+ post_install_message:
40
51
  rdoc_options: []
41
52
  require_paths:
42
53
  - lib
43
54
  required_ruby_version: !ruby/object:Gem::Requirement
44
- none: false
45
55
  requirements:
46
- - - ! '>='
56
+ - - ">="
47
57
  - !ruby/object:Gem::Version
48
- version: '0'
49
- required_rubygems_version: !ruby/object:Gem::Requirement
58
+ version: !binary |-
59
+ MA==
50
60
  none: false
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
62
  requirements:
52
- - - ! '>='
63
+ - - ">="
53
64
  - !ruby/object:Gem::Version
54
- version: '0'
65
+ version: !binary |-
66
+ MA==
67
+ none: false
55
68
  requirements: []
56
- rubyforge_project:
69
+ rubyforge_project:
57
70
  rubygems_version: 1.8.24
58
- signing_key:
71
+ signing_key:
59
72
  specification_version: 3
60
73
  summary: Simple Activity Logging Facility
61
74
  test_files: []