activity-log 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: febe0dc7536072f6c6cffa1d0ee12f186a7b3622
4
+ data.tar.gz: 1ddec33fe7b0868f8f335a1c6731090a02966e4c
5
+ SHA512:
6
+ metadata.gz: af438b2426cdb738fe24e2e60d3494bce5d501d0ce7bdea9685fe144c4513af7ea5527d5e833d4c9b5b57ff684d269b6506231d7cc631087c094ce3d19ef06d6
7
+ data.tar.gz: d8f01964e65a4996fd65e6cf5849534d5dc2e473be1fb7fcef6438bf9141a2cc9cd73ec85994577c5072cb61cfc6e56086ebb41f6bf07d0a9acc53ee96dc493a
@@ -0,0 +1,20 @@
1
+ Copyright 2018 James Kropp
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,45 @@
1
+ # Activity-Log
2
+
3
+ Short description and motivation.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'activity-log'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install activity-log
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activity-log. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
+
43
+ ## Code of Conduct
44
+
45
+ Everyone interacting in the Activity::Log project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/activity-log/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Activity'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1,5 @@
1
+ module Activity
2
+ class ApplicationController < ActionController::API
3
+ # protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require_dependency "activity/application_controller"
2
+
3
+ module Activity
4
+ class EventLogsController < ApplicationController
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Activity
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,37 @@
1
+ module Activity
2
+ class EventLog < ApplicationRecord
3
+ self.table_name = "activity_logs"
4
+
5
+ # Supported field names and scopes for each field
6
+ SUPPORTED_FILTERS = [:user_id, :attached_id, :model, :event, :created_at, :updated_at]
7
+ scope :user_id, -> (value) { where(user_id: value) }
8
+ scope :attached_id, -> (value) { where(attached_id: value) }
9
+ scope :model, -> (value) { where(model: value) }
10
+ scope :event, -> (value) { where(event: value) }
11
+
12
+ # Filter that finds all records that match a given request
13
+ # Example Request: attributes = {:attached_id: 1, event: "created_user"}
14
+ # - Will return any records where attached_id = 1 and event = "created_user"
15
+ # - Allows for simple searching with many unique cases
16
+ def self.filter(page, per_page, order_by, attributes)
17
+ logs = attributes.slice(*SUPPORTED_FILTERS).reduce(all) do |scope, (key, value)|
18
+ value.present? ? scope.send(key, value) : scope
19
+ end
20
+
21
+ {
22
+ current_page: page,
23
+ total_pages: logs.page(page).per(per_page).total_pages,
24
+ logs: logs.order(order_by).page(page).per(per_page),
25
+ }
26
+ end
27
+
28
+ def self.create_log(log)
29
+ self.create!(
30
+ user_id: log[:user_id],
31
+ attached_id: log[:attached_id],
32
+ model: log[:model],
33
+ event: log[:event],
34
+ )
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ Activity::Engine.routes.draw do
2
+ # Routes here
3
+ end
@@ -0,0 +1,12 @@
1
+ class CreateActivityLogs < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :activity_logs do |t|
4
+ t.integer :user_id, null: false, index: true
5
+ t.integer :attached_id, index: true
6
+ t.string :model, index: true
7
+ t.string :event, index: true
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ require "activity/engine"
2
+
3
+ module Activity
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,5 @@
1
+ module Activity
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Activity
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Activity
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :activity do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activity-log
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Kropp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: kaminari
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mysql2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - james-kropp@hotmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - app/controllers/activity/application_controller.rb
66
+ - app/controllers/activity/event_logs_controller.rb
67
+ - app/models/activity/application_record.rb
68
+ - app/models/activity/event_log.rb
69
+ - config/routes.rb
70
+ - db/migrate/20180625234553_create_activity_logs.rb
71
+ - lib/activity.rb
72
+ - lib/activity/engine.rb
73
+ - lib/activity/version.rb
74
+ - lib/tasks/activity_tasks.rake
75
+ homepage: https://github.com/jameskropp/activity-log
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.6.14
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Rails Activity Logger
99
+ test_files: []