activeadmin-simpletrail 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27696570a5ee60a0dbb5171556ec5c4c5dbb417f
4
+ data.tar.gz: 235d1b8d117d4df4a91d21f23bf99c219dba597b
5
+ SHA512:
6
+ metadata.gz: f3becd28643c66cac384c4101768b95861c1e220f5d8295fd3039b8def3c3d67607b2c1f55454627abbc458efd374a9d8268e79fb207e3c6a8a321619eab44f4
7
+ data.tar.gz: 8452a18ffa5a4a8ec10c6d391334e45bb98b0acdce644f3ebf267f70263c00d000f602a7d542bb62bc57cd10bd43bc5774beda2f6eae6e816e10d99c278573c2
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activeadmin-simpletrail.gemspec
4
+ gemspec
5
+ gem 'activeadmin', github: 'activeadmin'
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # ActiveAdmin::SimpleTrail
2
+ Track model's changes(by activeadmin), without database migration.
3
+
4
+ ## Installation
5
+
6
+ Add this line to your rails application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'activeadmin-simpletrail'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install activeadmin-simpletrail
19
+
20
+ ## Usage
21
+
22
+ In your admin file:
23
+
24
+ ```ruby
25
+ ActiveAdmin.register User do
26
+ simple_trail action: [:update]
27
+ :
28
+ :
29
+ ```
30
+
31
+ and you can log changes into file(default: `log/active_admin.log`).
32
+
33
+ You can log children changes(typically `has_many` relationship changes), by using `children` attribute.
34
+
35
+ ```ruby
36
+ ActiveAdmin.register User do
37
+ simple_trail action: [:update], children: [:contact, :posts]
38
+ :
39
+ :
40
+ ```
41
+
42
+ ## Configuration
43
+
44
+ You can configure log's path, log's format, etc if you need.
45
+ In `config/initializers/active_admin.rb`
46
+
47
+ - `config.simple_trail_log_path`
48
+ - `config.simple_trail_log_format`
49
+ - `config.simple_trail_log_level`
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( https://github.com/spacemarket/activeadmin-simpletrail/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_admin/simple_trail/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "activeadmin-simpletrail"
8
+ spec.version = ActiveAdmin::SimpleTrail::VERSION
9
+ spec.authors = ["Hiroaki Ninomiya"]
10
+ spec.email = ["ninomiya@spacemarket.co.jp"]
11
+
12
+ spec.summary = %q{Simple paper trail for activeadmin.}
13
+ spec.description = %q{Track model's changes(by activeadmin), without database migration.}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "sass-rails"
25
+ spec.add_development_dependency "rspec"
26
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "activeadmin/simpletrail"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ module ActiveAdmin
2
+ class Application
3
+ inheritable_setting :simple_trail_log_path, 'log/simple_trail.log'
4
+ inheritable_setting :simple_trail_log_format, "#<action> #<model>(ID:#<model_id>) by #<user>\t#<changes>"
5
+ inheritable_setting :simple_trail_log_level, :info
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ module ActiveAdmin
2
+ class ResourceDSL
3
+ def simple_trail(options = {}, &block)
4
+ actions = options[:actions] || [:update]
5
+ children = options[:children] || []
6
+
7
+ actions.each do |act|
8
+ hook_name = "before_#{act.to_s}".to_sym
9
+ next unless self.respond_to? hook_name
10
+ self.send(hook_name, -> target do
11
+ ActiveAdmin::SimpleTrail.write_log(act, target, current_admin_user.email) if target.changed?
12
+ children.each do |child|
13
+ next unless target.respond_to? child
14
+ next unless target.send(child)
15
+ child_targets = target.send(child)
16
+ child_targets = [child_targets] unless child_targets.respond_to? :each
17
+ child_targets.each do |child_target|
18
+ ActiveAdmin::SimpleTrail.write_log(act, child_target, current_admin_user.email) if child_target.changed?
19
+ end
20
+ end
21
+ end)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveAdmin
2
+ module SimpleTrail
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ require "active_admin"
2
+ require "active_admin/simple_trail/version"
3
+ require "active_admin/simple_trail/core_ext/resource_dsl"
4
+ require "active_admin/simple_trail/core_ext/application"
5
+
6
+ module ActiveAdmin
7
+ module SimpleTrail
8
+ def self.write_log(action, target, user)
9
+ logger.send(config.simple_trail_log_level,
10
+ config.simple_trail_log_format.gsub('#<action>', action.to_s).
11
+ gsub('#<model>', target.class.name.downcase).
12
+ gsub('#<model_id>', target.id.to_s).
13
+ gsub('#<user>', user.to_s).
14
+ gsub('#<changes>', target.changes.to_s))
15
+ end
16
+
17
+ private
18
+ def self.logger
19
+ @@logger ||= Logger.new(config.simple_trail_log_path)
20
+ end
21
+
22
+ def self.config
23
+ ActiveAdmin.application
24
+ end
25
+ end
26
+ end
@@ -0,0 +1 @@
1
+ require 'active_admin/simple_trail'
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeadmin-simpletrail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hiroaki Ninomiya
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sass-rails
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
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Track model's changes(by activeadmin), without database migration.
70
+ email:
71
+ - ninomiya@spacemarket.co.jp
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - activeadmin-simpletrail.gemspec
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/active_admin/simple_trail.rb
86
+ - lib/active_admin/simple_trail/core_ext/application.rb
87
+ - lib/active_admin/simple_trail/core_ext/resource_dsl.rb
88
+ - lib/active_admin/simple_trail/version.rb
89
+ - lib/activeadmin/simpletrail.rb
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.5.0
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Simple paper trail for activeadmin.
114
+ test_files: []