best_boy 0.0.2

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,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 cseydel
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,52 @@
1
+ best_boy
2
+ ========
3
+
4
+ A simple event driven logging for ActiveRecord models.
5
+ This gem is not tested for now. I add testing asap.
6
+ -----------------------------------------
7
+
8
+ What does this gem do?
9
+ ----------------------
10
+
11
+ best_boy logs create and delete events in its first iteration. It uses an own polimorphic database table to log each event.
12
+
13
+
14
+ Installation
15
+ ------------
16
+
17
+ Add it to your gemfile
18
+
19
+ gem 'best_boy'
20
+
21
+ Install it with Bundler
22
+
23
+ bundle install
24
+
25
+ Generate the BestBoyEvent table migration
26
+
27
+ rails g best_boy:install
28
+
29
+ Run the migration
30
+
31
+ rake db:migrate
32
+
33
+ BestBoyEvent table
34
+ ------------------
35
+
36
+ t.integer "owner_id" # owner model id
37
+ t.string "owner_type" # owner model class type
38
+ t.string "event" # event (create, delete)
39
+ t.datetime "updated_at" # last update timestamp
40
+ t.datetime "created_at" # creation timestamp
41
+
42
+ Getting BestBoyEvents
43
+ ---------------------
44
+
45
+ The table is namespaced, so you can access for statistics maybe with BestBoy::BestBoyEvent.where...
46
+
47
+
48
+ Famous last words
49
+ -----------------
50
+ It's my first gem, be gentle ;)
51
+
52
+ Copyright (c) 2012 Christoph Seydel. See LICENSE.txt for further details.
@@ -0,0 +1,16 @@
1
+ require 'bundler/setup'
2
+ require 'rspec/core/rake_task'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ RSpec::Core::RakeTask.new do |task|
7
+ task.rspec_opts = "-I ./test_app/spec"
8
+ task.pattern = "./test_app/spec/**/*_spec.rb"
9
+ end
10
+
11
+ task :test => :spec
12
+ task :default => :spec
13
+
14
+ namespace :best_boy do
15
+
16
+ end
@@ -0,0 +1,15 @@
1
+ module BestBoyController
2
+ module InstanceMethods
3
+ def best_boy_event(obj, event)
4
+ if obj.respond_to?("eventable?")
5
+ if event.present?
6
+ obj.trigger_custom_event(event)
7
+ else
8
+ raise "There is no event to trigger."
9
+ end
10
+ else
11
+ raise "#{obj.class.to_s} is not a best_boy eventable!"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module BestBoy
2
+ module Eventable
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+
7
+ end
8
+
9
+ def eventable?
10
+ true
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "best_boy/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "best_boy"
7
+ s.version = BestBoy::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.license = ['MIT']
10
+ s.authors = ["Christoph Seydel"]
11
+ s.email = ["christoph.seydel@me.com"]
12
+ s.homepage = "https://github.com/cseydel/best_boy"
13
+ s.summary = %q{a simple event driven logging for models}
14
+ s.description = %q{Hybrid action logging, consisting of standard and custom logging.}
15
+
16
+ s.rubyforge_project = "best_boy"
17
+ s.required_rubygems_version = ">= 1.3.6"
18
+
19
+ s.add_development_dependency("bundler", ">= 1.0.0")
20
+ s.add_development_dependency("rspec", "~> 2.0.1")
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,12 @@
1
+ require "best_boy/engine.rb"
2
+
3
+ module BestBoy
4
+ # Define ORM
5
+ mattr_accessor :orm
6
+ @@orm = :active_record
7
+
8
+ # Load configuration from initializer
9
+ def self.setup
10
+ yield self
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ require "best_boy"
2
+ require "rails"
3
+
4
+ module BestBoy
5
+ class Engine < Rails::Engine
6
+ initializer 'best_boy.model' do |app|
7
+ require "#{root}/app/models/best_boy/eventable.rb"
8
+ if BestBoy.orm == :active_record
9
+ require "best_boy/models/active_record/best_boy_event.rb"
10
+ require "best_boy/models/active_record/best_boy/eventable.rb"
11
+ ActiveRecord::Base.send(:include, BestBoy::Eventable)
12
+ else
13
+ raise "Sorry, best_boy actually only supports ActiveRecord ORM."
14
+ end
15
+ end
16
+
17
+ initializer 'best_boy.controller' do
18
+ ActiveSupport.on_load(:action_controller) do
19
+ include BestBoyController::InstanceMethods
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,45 @@
1
+ module BestBoy
2
+ module Eventable
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def has_a_best_boy
7
+ # meta programming
8
+ #
9
+ #
10
+ include InstanceMethods
11
+
12
+ # associations
13
+ #
14
+ #
15
+ has_many :best_boy_events, :as => :owner, :dependent => :nullify
16
+
17
+ # callbacks
18
+ #
19
+ #
20
+ after_create :trigger_create_event
21
+ before_destroy :trigger_destroy_event
22
+ end
23
+ end
24
+
25
+ module InstanceMethods
26
+ def trigger_create_event
27
+ create_best_boy_event_with_type "create"
28
+ end
29
+
30
+ def trigger_destroy_event
31
+ create_best_boy_event_with_type "destroy"
32
+ end
33
+
34
+ def trigger_custom_event type
35
+ create_best_boy_event_with_type(type) if type.present?
36
+ end
37
+
38
+ def create_best_boy_event_with_type type
39
+ best_boy_event = BestBoyEvent.new(:event => type)
40
+ best_boy_event.owner = self
41
+ best_boy_event.save
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ class BestBoyEvent < ActiveRecord::Base
2
+ # associations
3
+ #
4
+ #
5
+ belongs_to :owner, :polymorphic => true
6
+
7
+ # validations
8
+ #
9
+ #
10
+ validates :event, :presence => true
11
+
12
+ # attributes
13
+ #
14
+ #
15
+ attr_accessible :owner_id, :owner_type, :event
16
+
17
+ end
@@ -0,0 +1,3 @@
1
+ module BestBoy
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,21 @@
1
+ module ActiveRecord
2
+ module Generators
3
+ class BestBoyGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+ source_root File.join(File.dirname(__FILE__), 'templates')
6
+
7
+ def self.next_migration_number(dirname)
8
+ sleep 1
9
+ if ActiveRecord::Base.timestamped_migrations
10
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
11
+ else
12
+ "%.3d" % (current_migration_number(dirname) + 1)
13
+ end
14
+ end
15
+
16
+ def create_migration_file
17
+ migration_template 'create_best_boy_events_table.rb', 'db/migrate/create_best_boy_events_table.rb'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ class CreateBestBoyEventsTable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :best_boy_events, :force => true do |t|
4
+ t.integer :owner_id
5
+ t.string :owner_type
6
+ t.string :event
7
+ t.timestamps
8
+ end
9
+ add_index :best_boy_events, :owner_id
10
+ add_index :best_boy_events, :owner_type
11
+ add_index :best_boy_events, [:owner_id, :owner_type]
12
+ add_index :best_boy_events, :event
13
+ end
14
+
15
+ def self.down
16
+ drop_table :best_boy_events
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module BestBoy
2
+ module Generators
3
+ class BestBoyGenerator < Rails::Generators::Base
4
+ hook_for :orm
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def copy_config_file
8
+ template 'best_boy.rb', 'config/initializers/best_boy.rb'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ # Use this hook to configure impressionist parameters
2
+ BestBoy.setup do |config|
3
+ # Define ORM. Could be :active_record (default) and :mongo_mapper
4
+ # config.orm = :active_record
5
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: best_boy
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Christoph Seydel
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-06-12 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ - 0
31
+ version: 1.0.0
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 2
43
+ - 0
44
+ - 1
45
+ version: 2.0.1
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: Hybrid action logging, consisting of standard and custom logging.
49
+ email:
50
+ - christoph.seydel@me.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .gitignore
59
+ - Gemfile
60
+ - LICENSE.txt
61
+ - README.md
62
+ - Rakefile
63
+ - app/controllers/best_boy_controller.rb
64
+ - app/models/best_boy/eventable.rb
65
+ - best_boy.gemspec
66
+ - lib/best_boy.rb
67
+ - lib/best_boy/engine.rb
68
+ - lib/best_boy/models/active_record/best_boy/eventable.rb
69
+ - lib/best_boy/models/active_record/best_boy_event.rb
70
+ - lib/best_boy/version.rb
71
+ - lib/generators/active_record/best_boy_generator.rb
72
+ - lib/generators/active_record/templates/create_best_boy_events_table.rb
73
+ - lib/generators/best_boy_generator.rb
74
+ - lib/generators/templates/best_boy.rb
75
+ has_rdoc: true
76
+ homepage: https://github.com/cseydel/best_boy
77
+ licenses:
78
+ - - MIT
79
+ post_install_message:
80
+ rdoc_options: []
81
+
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 1
97
+ - 3
98
+ - 6
99
+ version: 1.3.6
100
+ requirements: []
101
+
102
+ rubyforge_project: best_boy
103
+ rubygems_version: 1.3.6
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: a simple event driven logging for models
107
+ test_files: []
108
+