honesty 0.0.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Tim Boisvert
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,65 @@
1
+ Honesty
2
+ =================
3
+
4
+ Honesty allows developers to store and track user activities and system events in
5
+ a human-readable, easily-searchable format.
6
+
7
+ == Resources
8
+
9
+ Install
10
+
11
+ * gem install honesty
12
+ * If using bundler:
13
+ ** Add "gem 'honesty'" to your Gemfile
14
+ ** "bundle install"
15
+
16
+
17
+ Generate the model:
18
+
19
+ ** Rails 3: rails g honesty
20
+ ** Rails 2: script/generate honesty
21
+
22
+ Migrate:
23
+ ** rake db:migrate
24
+
25
+ == Usage
26
+
27
+ * use Honesty in your ActiveRecord model.
28
+
29
+ class Shoe < ActiveRecord::Base
30
+ honesty
31
+ end
32
+
33
+ * Add a fact to a model instance
34
+
35
+ Parameters:
36
+ * Context - the object being acted on or the entity being tracked.
37
+ * Agent - the actor, so to speak.
38
+ * Action - the action taking place.
39
+
40
+ shoe = Shoe.create
41
+ shoe.fact("Shoe", "Tim Boisvert", "Created Adidas Superstar II")
42
+
43
+ * If you want to short-cut the fact and use the object's class name as the context:
44
+
45
+ shoe = Shoe.create
46
+ shoe.fact("Tim Boisvert", "Created Adidas Superstar II")
47
+
48
+ In this case the context would've been set to the class name of the object calling it -- in this case, Shoe
49
+
50
+ * Get facts:
51
+
52
+ shoe = Shoe.find(1)
53
+ facts = shoe.facts.all
54
+
55
+ == Credits
56
+
57
+ This plugin is heavily influenced by Acts As Taggable. Thanks to Jack Dempsey et al.
58
+
59
+ == Contributors
60
+
61
+ Tim Boisvert
62
+
63
+ == More
64
+
65
+ http://github.com/timboisvert/honesty
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'rails', 'init')
data/install.rb ADDED
@@ -0,0 +1,2 @@
1
+ puts "To create the honesty model please run:"
2
+ puts "rails g honesty
data/lib/fact.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Honesty
2
+ # TODO
3
+ # including this module into your Fact model will give you finders and named scopes
4
+ # useful for working with Facts.
5
+ module Fact
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ Description:
2
+ Copies fact.rb to app/models/.
3
+ Copies create_facts.rb to db/migrate
4
+
5
+ Examples:
6
+ `rails g honesty`
@@ -0,0 +1,18 @@
1
+ require 'rails/generators/migration'
2
+
3
+ class HonestyGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+
6
+ def self.source_root
7
+ @source_root ||= File.expand_path("../templates", __FILE__)
8
+ end
9
+
10
+ def self.next_migration_number(path)
11
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
12
+ end
13
+
14
+ def create_model_file
15
+ template "fact.rb", "app/models/fact.rb"
16
+ migration_template "create_facts.rb", "db/migrate/create_facts.rb"
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ class CreateFacts < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :facts do |t|
4
+ t.string :context, :limit => 40
5
+ t.string :agent
6
+ t.string :action
7
+ t.references :honest, :polymorphic => true
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :facts, :honest_type
12
+ add_index :facts, :honest_id
13
+ end
14
+
15
+ def self.down
16
+ drop_table :facts
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ class Fact < ActiveRecord::Base
2
+ #include Honesty::Fact
3
+ belongs_to :honest, :polymorphic => true
4
+ default_scope :order => 'created_at ASC'
5
+
6
+ # add the models this fact can belong to
7
+ # belongs_to :show
8
+ # belongs_to :user
9
+ # etc...
10
+ end
data/lib/honesty.rb CHANGED
@@ -1,51 +1,28 @@
1
- require "honesty/version"
2
1
  require 'active_record'
3
2
 
4
- #this is HEAVILY influenced by aprihodko's acts_as_reportable gem
5
- module ActiveRecord; module Acts; end; end
6
- module ActiveRecord::Acts::Honesty
3
+ # Honesty
4
+ module Honesty
7
5
 
8
6
  def self.included(base)
9
- base.extend ClassMethods
7
+ base.extend ClassMethods
10
8
  end
11
-
9
+
12
10
  module ClassMethods
13
11
  def honesty
14
- has_many :truths, :as => :honesty, :dependent => :destroy, :order => 'created_at ASC'
15
- include ActiveRecord::Acts::Honesty::InstanceMethods
12
+ has_many :facts, {:as => :honest, :dependent => :destroy}
13
+ include Honesty::InstanceMethods
16
14
  end
17
15
  end
18
-
16
+
19
17
  module InstanceMethods
20
- def truth(context, agent, action)
21
- truth = self.truths.new
22
- truth.context = context
23
- truth.agent = agent
24
- truth.action = action
25
- truth.save!
26
- end
27
-
28
- # Helper methods
29
- def truths_by_context
30
- Truth.find(:all,
31
- :conditions => ["context = ?", self.class.context],
32
- :order => "created_at DESC"
33
- )
34
- end
35
- def truths_by_agent
36
- Truth.find(:all,
37
- :conditions => ["agent = ?", self.class.agent],
38
- :order => "created_at DESC"
39
- )
40
- end
41
- def truths_by_action
42
- Truth.find(:all,
43
- :conditions => ["action = ?", self.class.action],
44
- :order => "created_at DESC"
45
- )
46
- end
18
+ def fact(*params)
19
+ if params.length == 3
20
+ self.facts.create(:context => params[0], :agent => params[1], :action => params[2])
21
+ elsif params.length == 2
22
+ self.facts.create(:context => self.class.name, :agent => params[0], :action => params[1])
23
+ end
24
+ end
47
25
  end
48
-
49
26
  end
50
27
 
51
- ActiveRecord::Base.send(:include, ActiveRecord::Acts::Honesty)
28
+ ActiveRecord::Base.send(:include, Honesty)
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Honesty
2
+ VERSION = "0.3.0"
3
+ end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: honesty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tim Boisvert
9
- autorequire:
9
+ autorequire: honesty
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-24 00:00:00.000000000 Z
12
+ date: 2012-01-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70196832908400 !ruby/object:Gem::Requirement
16
+ requirement: &14777840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70196832908400
24
+ version_requirements: *14777840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &70196832906820 !ruby/object:Gem::Requirement
27
+ requirement: &14777140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,33 +32,39 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70196832906820
35
+ version_requirements: *14777140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rails
38
- requirement: &70196832906180 !ruby/object:Gem::Requirement
38
+ requirement: &14776420 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ~>
41
+ - - ! '>='
42
42
  - !ruby/object:Gem::Version
43
- version: '3.0'
43
+ version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70196832906180
46
+ version_requirements: *14776420
47
47
  description: Store and track user activities and system events in a human-readable,
48
- easily-searchable format.
49
- email:
50
- - boisvert@gmail.com
48
+ easily-searchable format
49
+ email: boisvert@gmail.com
51
50
  executables: []
52
51
  extensions: []
53
- extra_rdoc_files: []
52
+ extra_rdoc_files:
53
+ - README.rdoc
54
+ - MIT-LICENSE
54
55
  files:
55
- - .gitignore
56
- - Gemfile
57
- - Rakefile
58
- - honesty.gemspec
56
+ - MIT-LICENSE
57
+ - README.rdoc
59
58
  - lib/honesty.rb
60
- - lib/honesty/version.rb
61
- homepage: ''
59
+ - lib/fact.rb
60
+ - lib/version.rb
61
+ - lib/generators/honesty/honesty_generator.rb
62
+ - lib/generators/honesty/templates/fact.rb
63
+ - lib/generators/honesty/templates/create_facts.rb
64
+ - lib/generators/honesty/USAGE
65
+ - init.rb
66
+ - install.rb
67
+ homepage: http://github.com/timboisvert/honesty
62
68
  licenses: []
63
69
  post_install_message:
64
70
  rdoc_options: []
@@ -77,9 +83,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
83
  - !ruby/object:Gem::Version
78
84
  version: '0'
79
85
  requirements: []
80
- rubyforge_project: honesty
81
- rubygems_version: 1.8.12
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.10
82
88
  signing_key:
83
89
  specification_version: 3
84
- summary: Store and track human-readable user activities and system events
90
+ summary: Store and track user activities and system events in a human-readable, easily-searchable
91
+ format
85
92
  test_files: []
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in honesty.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"
data/honesty.gemspec DELETED
@@ -1,25 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "honesty/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "honesty"
7
- s.version = Honesty::VERSION
8
- s.authors = ["Tim Boisvert"]
9
- s.email = ["boisvert@gmail.com"]
10
- s.homepage = ""
11
- s.summary = %q{Store and track human-readable user activities and system events}
12
- s.description = %q{Store and track user activities and system events in a human-readable, easily-searchable format.}
13
-
14
- s.rubyforge_project = "honesty"
15
-
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
20
-
21
- # specify any dependencies here; for example:
22
- s.add_development_dependency 'rspec'
23
- s.add_development_dependency 'sqlite3'
24
- s.add_dependency 'rails', '~> 3.0'
25
- end
@@ -1,3 +0,0 @@
1
- module Honesty
2
- VERSION = "0.0.7"
3
- end