event_horizon 0.0.1

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jiri Zajpt
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.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = event_horizon
2
+
3
+ Simple plugin for logging events in Rails applications.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Jiri Zajpt. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "event_horizon"
8
+ gem.summary = %Q{Simple plugin for logging events in Rails applications.}
9
+ gem.description = %Q{Simple plugin for logging events in Rails applications using Mongoid ODM.}
10
+ gem.email = "jzajpt@blueberryapps.com"
11
+ gem.homepage = "http://github.com/jzajpt/event_horizon"
12
+ gem.authors = ["Jiri Zajpt"]
13
+ gem.add_development_dependency "rspec", "~> 2.0.0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rspec/core'
22
+ require 'rspec/core/rake_task'
23
+
24
+ Rspec::Core::RakeTask.new(:spec) do |spec|
25
+ spec.pattern = "./spec/**/*_spec.rb"
26
+ end
27
+
28
+ Rspec::Core::RakeTask.new(:rcov) do |spec|
29
+ spec.pattern = "./spec/**/*_spec.rb"
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "event_horizon #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ require 'event_horizon/orm_support'
4
+
5
+ EventHorizon::OrmSupport.load_event_class
6
+
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{event_horizon}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jiri Zajpt"]
12
+ s.date = %q{2010-10-17}
13
+ s.description = %q{Simple plugin for logging events in Rails applications using Mongoid ODM.}
14
+ s.email = %q{jzajpt@blueberryapps.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "app/models/event.rb",
27
+ "event_horizon.gemspec",
28
+ "lib/event_horizon.rb",
29
+ "lib/event_horizon/events.rb",
30
+ "lib/event_horizon/helpers.rb",
31
+ "lib/event_horizon/helpers/event_horizon_helper.rb",
32
+ "lib/event_horizon/mongoid_support/document.rb",
33
+ "lib/event_horizon/mongoid_support/event.rb",
34
+ "lib/event_horizon/orm_support.rb",
35
+ "spec/event_horizon_spec.rb",
36
+ "spec/spec_helper.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/jzajpt/event_horizon}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.7}
42
+ s.summary = %q{Simple plugin for logging events in Rails applications.}
43
+ s.test_files = [
44
+ "spec/event_horizon_spec.rb",
45
+ "spec/spec_helper.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ s.add_development_dependency(%q<rspec>, ["~> 2.0.0"])
54
+ else
55
+ s.add_dependency(%q<rspec>, ["~> 2.0.0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<rspec>, ["~> 2.0.0"])
59
+ end
60
+ end
61
+
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+
3
+ require 'active_support/concern'
4
+
5
+ module EventHorizon
6
+
7
+ module Events
8
+
9
+ extend ActiveSupport::Concern
10
+
11
+ module ClassMethods
12
+
13
+ def on_event(*params)
14
+ if params.first.is_a?(Hash)
15
+ params = params.first
16
+ event, callback = params.keys.first, params.values.first
17
+ else
18
+ event, callback = params.first, params.last
19
+ end
20
+ @event_callbacks ||= {}
21
+ @event_callbacks[event] ||= []
22
+ @event_callbacks[event] << callback
23
+ end
24
+
25
+ def event_callbacks_for(event)
26
+ @event_callbacks[event]
27
+ end
28
+
29
+ end
30
+
31
+ module InstanceMethods
32
+
33
+ def fire(event, options = {})
34
+ self.call_event_callbacks_for(event)
35
+ self.create_event(event, options)
36
+ end
37
+
38
+ protected
39
+
40
+ def create_event(event, options = {})
41
+ params = options.except(:by, :user, :parent)
42
+ params.reverse_merge! :name => self.to_s
43
+
44
+ class_name = self._type || self.class.name
45
+ user = options[:by] || options[:user]
46
+
47
+ Event.create(:event_type => event.to_s,
48
+ :user_id => user && user.id,
49
+ :document_id => self.id,
50
+ :document_type => class_name,
51
+ :params => params)
52
+ end
53
+
54
+ def call_event_callbacks_for(event)
55
+ if callbacks = self.class.event_callbacks_for(event)
56
+ callbacks.each { |method| self.send method }
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ module EventHorizonHelper
4
+
5
+ def relativize_date(date)
6
+ ago = 7.days.ago.to_date
7
+ key = case date
8
+ when Date.today; :today
9
+ when Date.yesterday; :yesterday
10
+ when ago..Date.today; [:days, date.wday]
11
+ end
12
+ if key.is_a? Array
13
+ day = t("date.day_names")[key.last]
14
+ "#{day}, #{l date, :format => :short}"
15
+ elsif key
16
+ key && t("helpers.dashboards.relativize_date.#{key}")
17
+ else
18
+ l date, :format => :short
19
+ end
20
+ end
21
+
22
+ def event_description(event)
23
+ scope = "#{event.document_type.tableize.singularize}.#{event.event_type}"
24
+ interpolations = event_interpolations(event)
25
+ t("helpers.dashboards.event_description.#{scope}", interpolations).html_safe
26
+ end
27
+
28
+ def event_interpolations(event)
29
+ interpolations = event.params.inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
30
+ if interpolations[:name] && event.document.present?
31
+ method = :"link_to_#{event.document_type.downcase}"
32
+ interpolations[:name] = send(method, event.document) if respond_to?(method)
33
+ end
34
+ interpolations
35
+ rescue Mongoid::Errors::DocumentNotFound
36
+ interpolations
37
+ end
38
+
39
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ require 'event_horizon/helpers/event_horizon_helper'
4
+
5
+ if defined?(ActionController)
6
+ # In order to Rails recognize our helper (EventHorizonHelper), we
7
+ # have to use separate path for it and then tell Rails about it.
8
+ path = File.join(File.dirname(__FILE__), 'event_horizon/helpers')
9
+ $LOAD_PATH << path
10
+ ActionController::Base.helpers_path << path
11
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'active_support/concern'
4
+
5
+ module EventHorizon
6
+
7
+ module MongoidSupport
8
+
9
+ module Document
10
+
11
+ extend ActiveSupport::Concern
12
+
13
+ included do
14
+ references_many :events, :as => :document, :class_name => "::Event"
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'active_support/concern'
4
+ require 'mongoid'
5
+ require 'mongoid/timestamps'
6
+
7
+
8
+ class Event
9
+
10
+ include ::Mongoid::Document
11
+ include ::Mongoid::Timestamps
12
+
13
+
14
+ store_in :events
15
+
16
+ # Document keys
17
+
18
+ field :event_type
19
+ field :params, :type => Hash
20
+ field :document_id#, :type => ObjectID
21
+ field :document_type
22
+
23
+ index :created_at
24
+
25
+ # Associations
26
+
27
+ referenced_in :user
28
+
29
+
30
+ # Public methods
31
+
32
+ def document
33
+ self.document_type.constantize.find(self.document_id)
34
+ rescue ::Mongoid::Errors::DocumentNotFound
35
+ nil
36
+ end
37
+
38
+ def day
39
+ created_at.to_date
40
+ end
41
+
42
+ def same?(other)
43
+ return unless other
44
+ self.event_type == other.event_type &&
45
+ self.user_id == other.user_id &&
46
+ self.document_id == other.document_id
47
+ end
48
+
49
+ end
50
+
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ require 'active_support/concern'
4
+
5
+
6
+ module EventHorizon
7
+
8
+ module OrmSupport
9
+
10
+ def self.load_event_class
11
+ require 'event_horizon/mongoid_support/event' if defined?(::Mongoid)
12
+ end
13
+
14
+ def self.document_class
15
+ if defined?(::Mongoid)
16
+ require 'event_horizon/mongoid_support/document'
17
+ EventHorizon::MongoidSupport::Document
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ require 'active_support/concern'
4
+ require 'event_horizon/events'
5
+ require 'event_horizon/orm_support'
6
+ require 'event_horizon/helpers'
7
+
8
+
9
+ module EventHorizon
10
+
11
+ extend ActiveSupport::Concern
12
+
13
+ include Events
14
+ include EventHorizon::MongoidSupport::Document if defined?(::Mongoid)
15
+
16
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "EventHorizon" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'event_horizon'
4
+
5
+ require 'rspec'
6
+ require 'rspec/core'
7
+
8
+ RSpec.configure do |config|
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: event_horizon
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Jiri Zajpt
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-17 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 0
32
+ version: 2.0.0
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: Simple plugin for logging events in Rails applications using Mongoid ODM.
36
+ email: jzajpt@blueberryapps.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - app/models/event.rb
52
+ - event_horizon.gemspec
53
+ - lib/event_horizon.rb
54
+ - lib/event_horizon/events.rb
55
+ - lib/event_horizon/helpers.rb
56
+ - lib/event_horizon/helpers/event_horizon_helper.rb
57
+ - lib/event_horizon/mongoid_support/document.rb
58
+ - lib/event_horizon/mongoid_support/event.rb
59
+ - lib/event_horizon/orm_support.rb
60
+ - spec/event_horizon_spec.rb
61
+ - spec/spec_helper.rb
62
+ has_rdoc: true
63
+ homepage: http://github.com/jzajpt/event_horizon
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ requirements: []
88
+
89
+ rubyforge_project:
90
+ rubygems_version: 1.3.7
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Simple plugin for logging events in Rails applications.
94
+ test_files:
95
+ - spec/event_horizon_spec.rb
96
+ - spec/spec_helper.rb