hound 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/Gemfile +17 -0
  4. data/Gemfile.lock +98 -0
  5. data/LICENSE +20 -0
  6. data/README.md +19 -0
  7. data/Rakefile +35 -0
  8. data/hound.gemspec +22 -0
  9. data/lib/generators/hound/USAGE +2 -0
  10. data/lib/generators/hound/install_generator.rb +17 -0
  11. data/lib/generators/hound/templates/create_hound_actions.rb +16 -0
  12. data/lib/hound/action.rb +11 -0
  13. data/lib/hound/config.rb +15 -0
  14. data/lib/hound/controller.rb +36 -0
  15. data/lib/hound/model.rb +55 -0
  16. data/lib/hound/version.rb +3 -0
  17. data/lib/hound.rb +38 -0
  18. data/lib/tasks/hound_tasks.rake +4 -0
  19. data/test/dummy/README.rdoc +261 -0
  20. data/test/dummy/Rakefile +7 -0
  21. data/test/dummy/app/assets/javascripts/application.js +15 -0
  22. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  23. data/test/dummy/app/controllers/application_controller.rb +3 -0
  24. data/test/dummy/app/helpers/application_helper.rb +2 -0
  25. data/test/dummy/app/mailers/.gitkeep +0 -0
  26. data/test/dummy/app/models/.gitkeep +0 -0
  27. data/test/dummy/app/models/article.rb +4 -0
  28. data/test/dummy/app/models/post.rb +4 -0
  29. data/test/dummy/app/models/user.rb +3 -0
  30. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  31. data/test/dummy/config/application.rb +59 -0
  32. data/test/dummy/config/boot.rb +10 -0
  33. data/test/dummy/config/database.yml +25 -0
  34. data/test/dummy/config/environment.rb +5 -0
  35. data/test/dummy/config/environments/development.rb +37 -0
  36. data/test/dummy/config/environments/production.rb +67 -0
  37. data/test/dummy/config/environments/test.rb +37 -0
  38. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/test/dummy/config/initializers/inflections.rb +15 -0
  40. data/test/dummy/config/initializers/mime_types.rb +5 -0
  41. data/test/dummy/config/initializers/secret_token.rb +7 -0
  42. data/test/dummy/config/initializers/session_store.rb +8 -0
  43. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  44. data/test/dummy/config/locales/en.yml +5 -0
  45. data/test/dummy/config/routes.rb +58 -0
  46. data/test/dummy/config.ru +4 -0
  47. data/test/dummy/db/migrate/20130307165752_create_users.rb +9 -0
  48. data/test/dummy/db/migrate/20130307165837_create_articles.rb +10 -0
  49. data/test/dummy/db/migrate/20130307175522_create_persued_actions.rb +16 -0
  50. data/test/dummy/db/migrate/20130307183451_create_posts.rb +9 -0
  51. data/test/dummy/db/schema.rb +44 -0
  52. data/test/dummy/lib/assets/.gitkeep +0 -0
  53. data/test/dummy/log/.gitkeep +0 -0
  54. data/test/dummy/public/404.html +26 -0
  55. data/test/dummy/public/422.html +26 -0
  56. data/test/dummy/public/500.html +25 -0
  57. data/test/dummy/public/favicon.ico +0 -0
  58. data/test/dummy/script/rails +6 -0
  59. data/test/dummy/test/fixtures/articles.yml +9 -0
  60. data/test/dummy/test/fixtures/posts.yml +7 -0
  61. data/test/dummy/test/fixtures/users.yml +7 -0
  62. data/test/dummy/test/unit/article_test.rb +7 -0
  63. data/test/dummy/test/unit/post_test.rb +7 -0
  64. data/test/dummy/test/unit/user_test.rb +7 -0
  65. data/test/hound_test.rb +31 -0
  66. data/test/test_helper.rb +21 -0
  67. metadata +184 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5124b75e28297b2fcc833c9b785afaaf30ef1a6d
4
+ data.tar.gz: 243191f171a35b3d0434e19ba8a8c0b2a98d7fae
5
+ SHA512:
6
+ metadata.gz: 35a19f7e49986a4a5e9e5114de97f9416535f0fc53497f50e17c504f4522593f9d23e16cc860cc1a3a7b66f19a87cb32e1c8aed97030a831b568c29f4ca42002
7
+ data.tar.gz: e0ce3c16219b152035deaf16e1c748f2e0dc9ff3fc72a23d891d1e51ae6c005279b2c1e7fe52f8bf333997686d14949110376c7a3def5697109c9ac5f89d7b31
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/log/*.log
6
+ test/dummy/tmp/
7
+ test/dummy/.sass-cache
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in hound.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # jquery-rails is used by the dummy application
9
+ gem "jquery-rails"
10
+
11
+ # Declare any dependencies that are still in development here instead of in
12
+ # your gemspec. These might include edge Rails or gems from your path or
13
+ # Git. Remember to move these dependencies to your gemspec before releasing
14
+ # your gem to rubygems.org.
15
+
16
+ # To use debugger
17
+ # gem 'debugger'
data/Gemfile.lock ADDED
@@ -0,0 +1,98 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hound (0.0.1)
5
+ rails (>= 3.2.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionmailer (3.2.13.rc2)
11
+ actionpack (= 3.2.13.rc2)
12
+ mail (~> 2.5.3)
13
+ actionpack (3.2.13.rc2)
14
+ activemodel (= 3.2.13.rc2)
15
+ activesupport (= 3.2.13.rc2)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ journey (~> 1.0.4)
19
+ rack (~> 1.4.5)
20
+ rack-cache (~> 1.2)
21
+ rack-test (~> 0.6.1)
22
+ sprockets (~> 2.2.1)
23
+ activemodel (3.2.13.rc2)
24
+ activesupport (= 3.2.13.rc2)
25
+ builder (~> 3.0.0)
26
+ activerecord (3.2.13.rc2)
27
+ activemodel (= 3.2.13.rc2)
28
+ activesupport (= 3.2.13.rc2)
29
+ arel (~> 3.0.2)
30
+ tzinfo (~> 0.3.29)
31
+ activeresource (3.2.13.rc2)
32
+ activemodel (= 3.2.13.rc2)
33
+ activesupport (= 3.2.13.rc2)
34
+ activesupport (3.2.13.rc2)
35
+ i18n (= 0.6.1)
36
+ multi_json (~> 1.0)
37
+ arel (3.0.2)
38
+ builder (3.0.4)
39
+ erubis (2.7.0)
40
+ hike (1.2.1)
41
+ i18n (0.6.1)
42
+ journey (1.0.4)
43
+ jquery-rails (2.2.1)
44
+ railties (>= 3.0, < 5.0)
45
+ thor (>= 0.14, < 2.0)
46
+ json (1.7.7)
47
+ mail (2.5.3)
48
+ i18n (>= 0.4.0)
49
+ mime-types (~> 1.16)
50
+ treetop (~> 1.4.8)
51
+ mime-types (1.21)
52
+ multi_json (1.6.1)
53
+ polyglot (0.3.3)
54
+ rack (1.4.5)
55
+ rack-cache (1.2)
56
+ rack (>= 0.4)
57
+ rack-ssl (1.3.3)
58
+ rack
59
+ rack-test (0.6.2)
60
+ rack (>= 1.0)
61
+ rails (3.2.13.rc2)
62
+ actionmailer (= 3.2.13.rc2)
63
+ actionpack (= 3.2.13.rc2)
64
+ activerecord (= 3.2.13.rc2)
65
+ activeresource (= 3.2.13.rc2)
66
+ activesupport (= 3.2.13.rc2)
67
+ bundler (~> 1.0)
68
+ railties (= 3.2.13.rc2)
69
+ railties (3.2.13.rc2)
70
+ actionpack (= 3.2.13.rc2)
71
+ activesupport (= 3.2.13.rc2)
72
+ rack-ssl (~> 1.3.2)
73
+ rake (>= 0.8.7)
74
+ rdoc (~> 3.4)
75
+ thor (>= 0.14.6, < 2.0)
76
+ rake (10.0.3)
77
+ rdoc (3.12.2)
78
+ json (~> 1.4)
79
+ sprockets (2.2.2)
80
+ hike (~> 1.2)
81
+ multi_json (~> 1.0)
82
+ rack (~> 1.0)
83
+ tilt (~> 1.1, != 1.3.0)
84
+ sqlite3 (1.3.7)
85
+ thor (0.17.0)
86
+ tilt (1.3.4)
87
+ treetop (1.4.12)
88
+ polyglot
89
+ polyglot (>= 0.3.1)
90
+ tzinfo (0.3.36)
91
+
92
+ PLATFORMS
93
+ ruby
94
+
95
+ DEPENDENCIES
96
+ hound!
97
+ jquery-rails
98
+ sqlite3
data/LICENSE ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Hound
2
+
3
+ ## Installation
4
+
5
+ Add Hound to your `Gemfile` and run `bundle install`:
6
+
7
+ ```ruby
8
+ gem 'hound'
9
+ ```
10
+
11
+ Hound expects a `hound_actions` table to exist in your schema, go ahead
12
+ and run the generator provided:
13
+
14
+ ```
15
+ rails generate hound:install
16
+ ```
17
+
18
+ This will create a new migration file. Run `rake db:migrate` to add
19
+ this table.
data/Rakefile ADDED
@@ -0,0 +1,35 @@
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 = 'Hound'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ require 'rake/testtask'
26
+
27
+ Rake::TestTask.new(:test) do |t|
28
+ t.libs << 'lib'
29
+ t.libs << 'test'
30
+ t.pattern = 'test/**/*_test.rb'
31
+ t.verbose = false
32
+ end
33
+
34
+
35
+ task :default => :test
data/hound.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require 'hound/version'
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = 'hound'
9
+ s.version = Hound::VERSION
10
+ s.authors = ['Lee Jarvis']
11
+ s.email = ['ljjarvis@gmail.com']
12
+ s.homepage = 'https://github.com/injekt/hound'
13
+ s.summary = 'Trace changes to your models'
14
+ s.description = 'Trace your model actions and create activity lists'
15
+
16
+ s.files = `git ls-files`.split($/)
17
+ s.test_files = s.files.grep(%r{^test/})
18
+
19
+ s.add_dependency 'rails', '>= 3.2.0'
20
+
21
+ s.add_development_dependency 'sqlite3'
22
+ end
@@ -0,0 +1,2 @@
1
+ Description:
2
+ Generates a migration to add a hound_actions table.
@@ -0,0 +1,17 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+ require 'rails/generators/active_record/migration'
4
+
5
+ module Hound
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+ extend ActiveRecord::Generators::Migration
9
+
10
+ source_root File.expand_path('../templates', __FILE__)
11
+
12
+ desc 'Generates a migration to add a hound_actions table.'
13
+ def create_migration_file
14
+ migration_template 'create_hound_actions.rb', 'db/migrate/create_hound_actions.rb'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ class CreateHoundActions < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :hound_actions do |t|
4
+ t.string :action, null: false
5
+ t.string :actionable_type, null: false
6
+ t.integer :actionable_id, null: false
7
+ t.datetime :created_at
8
+ end
9
+ add_index :hound_actions, [:actionable_type, :actionable_id]
10
+ end
11
+
12
+ def self.down
13
+ remove_index :hound_actions, [:actionable_type, :actionable_id]
14
+ drop_table :hound_actions
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Hound
2
+ class Action < ActiveRecord::Base
3
+ self.table_name = 'hound_actions'
4
+ attr_accessible :action, :actionable_id, :actionable_type
5
+ belongs_to :actionable, polymorphic: true
6
+
7
+ scope :created, -> { where(action: 'create') }
8
+ scope :updated, -> { where(action: 'update') }
9
+ scope :destroyed, -> { where(action: 'destroy') }
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ require 'singleton'
2
+
3
+ module Hound
4
+ class Config
5
+ include Singleton
6
+
7
+ # An Array of actions Hound should track.
8
+ attr_accessor :actions
9
+
10
+ def initialize
11
+ @actions = %w'create update destroy'
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,36 @@
1
+ module Hound
2
+ module Controller
3
+
4
+ def self.included(base)
5
+ base.before_filter :set_hound_user
6
+ end
7
+
8
+ protected
9
+
10
+ # Attempt to fetch the current_user object. Return nil otherwise.
11
+ # This method should be overridden for providing custom behavour.
12
+ def hound_user
13
+ @hound_user ||= current_user
14
+ rescue NoMethodError
15
+ nil
16
+ end
17
+
18
+ def hound_user_type
19
+ if hound_user
20
+ hound_user.class.base_class.name
21
+ end
22
+ end
23
+
24
+ def hound_user_id
25
+ hound_user.try(:id)
26
+ end
27
+
28
+ private
29
+
30
+ def set_hound_user
31
+ Hound.store[:hound_user_type] = hound_user_type
32
+ Hound.store[:hound_user_id] = hound_user_id
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,55 @@
1
+ module Hound
2
+ module Model
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ # Tell Hound to track this models actions.
11
+ #
12
+ # options - a Hash of configuration options.
13
+ def hound(options = {})
14
+ send :include, InstanceMethods
15
+
16
+ has_many :actions,
17
+ as: 'actionable',
18
+ class_name: 'Hound::Action'
19
+
20
+ options[:actions] ||= Hound.config.actions
21
+ options[:actions] = Array(options[:actions]).map(&:to_s)
22
+
23
+ class_attribute :hound_options
24
+ self.hound_options = options.dup
25
+
26
+ after_create :hound_create if options[:actions].include?('create')
27
+ before_update :hound_update if options[:actions].include?('update')
28
+ after_destroy :hound_destroy if options[:actions].include?('destroy')
29
+ end
30
+ end
31
+
32
+ module InstanceMethods
33
+
34
+ private
35
+
36
+ def hound_create
37
+ actions.create! action: 'create'
38
+ end
39
+
40
+ def hound_update
41
+ actions.create! action: 'update'
42
+ end
43
+
44
+ def hound_destroy
45
+ Hound::Action.create(
46
+ actionable_id: self.id,
47
+ actionable_type: self.class.base_class.name,
48
+ action: 'destroy'
49
+ )
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module Hound
2
+ VERSION = "0.0.1"
3
+ end
data/lib/hound.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'hound/model'
2
+ require 'hound/controller'
3
+ require 'hound/action'
4
+ require 'hound/config'
5
+ require 'hound/version'
6
+
7
+ module Hound
8
+
9
+ # The configuration storage for Hound.
10
+ #
11
+ # Returns the Hound::Config instance.
12
+ def self.config
13
+ @config ||= Hound::Config.instance
14
+ end
15
+
16
+ def self.configure
17
+ yield config
18
+ end
19
+
20
+ # Returns the Hash for storing hound properties on the current thread.
21
+ def self.store
22
+ Thread.current[:hound] ||= {}
23
+ end
24
+
25
+ # Returns an ActionRecord::Relation for the Hound::Action model.
26
+ def self.actions
27
+ Action.scoped
28
+ end
29
+
30
+ end
31
+
32
+ ActiveSupport.on_load :action_controller do
33
+ include Hound::Controller
34
+ end
35
+
36
+ ActiveSupport.on_load :active_record do
37
+ include Hound::Model
38
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :hound do
3
+ # # Task goes here
4
+ # end