narrator 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.7"
4
+ - "1.9.2"
5
+ - "1.9.3"
6
+ #- jruby-18mode # JRuby in 1.8 mode
7
+ #- jruby-19mode # JRuby in 1.9 mode
8
+ #- rbx-18mode
9
+ #- rbx-19mode
10
+ # uncomment this line if your project needs to run something other than `rake`:
11
+ # script: bundle exec rspec spec
12
+
13
+ # whitelist
14
+ branches:
15
+ only:
16
+ - master
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.0.1alpha
2
+
3
+ * pre-release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in narrator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Joe Weakley
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,32 @@
1
+ = Narrator {<img src="https://secure.travis-ci.org/jweakley/narrator.png?branch=master" />}[http://travis-ci.org/jweakley/narrator]
2
+
3
+ Narrator is an activity library for Ruby on Rails that allow you to track what is happening on models and later use to build an activity or news stream. Tracking is done at the controller level with a simple narrate_resource command (which was inspired by the simplicity of Ryan Bates' CanCan gem).
4
+
5
+ == Installation
6
+
7
+ In <b> Rails 3 </b> add this line to your application's Gemfile and run the +bundle+ command.
8
+
9
+ gem "narrator"
10
+
11
+ == Getting Started
12
+
13
+ * Coming Soon
14
+
15
+ == Wiki Docs
16
+
17
+ * Coming Soon
18
+
19
+ == Questions or Problems?
20
+
21
+ If you have any issues with Narrator which you cannot find the answer in the documentation[https://github.com/jweakley/narrator/wiki], please add an {issue on GitHub}[https://github.com/jweakley/narrator/issues]. Alternatively you can fork the project and send a pull request (limit one high five and/or fist bump per contribution).
22
+
23
+ Please ensure the tests are passing by running `bundle` and `rake`.
24
+
25
+ == Special Thanks
26
+
27
+ Narrator was inspired in part by Ryan Bates railcasts and CanCan[https://github.com/ryanb/cancan].
28
+
29
+ Internet high fives and/or fist bumps to the Narrator contributors[https://github.com/jweakley/narrator/contributors].
30
+
31
+
32
+ This gem is created by Joe Weakley and is under the MIT License.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
@@ -0,0 +1,4 @@
1
+ Description:
2
+ The narrator:activity generator creates an Activity class in the models
3
+ directory. You can move this file anywhere you want as long as it
4
+ is in the load path.
@@ -0,0 +1,11 @@
1
+ module Narrator
2
+ module Generators
3
+ class ActivityGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ def generate_ability
7
+ copy_file "activity.rb", "app/models/activity.rb"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ class Activity
2
+ include Narrator::Activity
3
+ ###
4
+ # Attribute accessible
5
+ ###
6
+ attr_accessible :owner, :subject, :actor, :target, :target_id, :target_type, :verb, :context, :has_seen
7
+
8
+ ###
9
+ # Associations
10
+ ###
11
+ belongs_to :owner, class_name: 'UserProfile'
12
+ belongs_to :actor, class_name: 'UserProfile'
13
+ belongs_to :subject, polymorphic: true
14
+ belongs_to :target, polymorphic: true
15
+
16
+ ###
17
+ # Validate
18
+ ###
19
+ validates :owner, presence: true
20
+ validates :subject, presence: true
21
+ validates :verb, presence: true
22
+
23
+ ###
24
+ # Scopes
25
+ ###
26
+ scope :unseen, where{has_seen.eq false}
27
+ scope :seen, where{has_seen.eq true}
28
+ scope :recent, order('created_at DESC')
29
+
30
+ end
@@ -0,0 +1,4 @@
1
+ module Narrator
2
+ module Activity
3
+ end
4
+ end
@@ -0,0 +1,31 @@
1
+ module Narrator
2
+ module ControllerAdditions
3
+ module ClassMethods
4
+
5
+ def narrate_resource(*args)
6
+ narrator_resource_class.add_before_filter(self, :narrate_resource, *args)
7
+ end
8
+
9
+ def narrate(subject, target = nil, verb = params[:action], actor_id = current_user.user_profile_id)
10
+ if user_signed_in?
11
+ subject.class.delay.track_user_activity(subject.id, actor_id, target.class.to_s, (target.blank? ? nil : target.id), verb.to_s)
12
+ end
13
+ end
14
+
15
+ def narrator_resource_class
16
+ ControllerResource
17
+ end
18
+
19
+ def self.included(base)
20
+ base.extend ClassMethods
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+
27
+ if defined? ActionController::Base
28
+ ActionController::Base.class_eval do
29
+ include Narrator::ControllerAdditions
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ module Narrator
2
+ class ControllerResource
3
+
4
+ def initialize(controller, *args)
5
+ @controller = controller
6
+ @params = controller.params
7
+ @options = args.extract_options!
8
+ @name = args.first
9
+ end
10
+
11
+ def narrate_resource
12
+ # TODO Add skipper for this method
13
+ @controller.narrate(subject, nil, params[:action], current_user)
14
+ end
15
+
16
+ protected
17
+
18
+ def current_user
19
+ @controller.send(:current_user)
20
+ end
21
+
22
+ def resource_class
23
+ case @options[:class]
24
+ when String then @options[:class].constantize
25
+ else @options[:class]
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Narrator
2
+ VERSION = "0.0.1.alpha"
3
+ end
data/lib/narrator.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'narrator/ability'
2
+ require 'narrator/controller_resource'
3
+ require 'narrator/controller_additions'
4
+
5
+ require "narrator/version"
6
+
7
+ module Narrator
8
+ # Your code goes here...
9
+ end
data/narrator.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'narrator/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "narrator"
8
+ gem.version = Narrator::VERSION
9
+ gem.authors = ["Joe Weakley"]
10
+ gem.email = ["joe.weakley@digitalaugment.com"]
11
+ gem.description = %q{Straightforward and flexable activity tracking for rails that is designed to be fast and scalable.}
12
+ gem.summary = %q{Straightforward and flexable activity tracking for rails.}
13
+ gem.homepage = "https://github.com/jweakley/narrator"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency "rspec"
21
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Narrator do
4
+ pending "Add moar tests!"
5
+ end
@@ -0,0 +1 @@
1
+ require "narrator"
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: narrator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Joe Weakley
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Straightforward and flexable activity tracking for rails that is designed
31
+ to be fast and scalable.
32
+ email:
33
+ - joe.weakley@digitalaugment.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - .rspec
40
+ - .travis.yml
41
+ - CHANGELOG.md
42
+ - Gemfile
43
+ - LICENSE.txt
44
+ - README.rdoc
45
+ - Rakefile
46
+ - lib/generators/narrator/activity/USAGE
47
+ - lib/generators/narrator/activity/activity_generator.rb
48
+ - lib/generators/narrator/activity/templates/activity.rb
49
+ - lib/narrator.rb
50
+ - lib/narrator/activity.rb
51
+ - lib/narrator/controller_additions.rb
52
+ - lib/narrator/controller_resource.rb
53
+ - lib/narrator/version.rb
54
+ - narrator.gemspec
55
+ - spec/narrator/narrator_spec.rb
56
+ - spec/spec_helper.rb
57
+ homepage: https://github.com/jweakley/narrator
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>'
73
+ - !ruby/object:Gem::Version
74
+ version: 1.3.1
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.24
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Straightforward and flexable activity tracking for rails.
81
+ test_files:
82
+ - spec/narrator/narrator_spec.rb
83
+ - spec/spec_helper.rb