bookmarker 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.
@@ -0,0 +1,16 @@
1
+ == bookmarker
2
+ Add bookmarks to your models.
3
+
4
+ * Add gem "bookmarker" to your Gemfile
5
+
6
+ * Run generator: rails g bookmaker:install and rake db:migrate
7
+
8
+ * Add is_bookmarkable to your bookmarkable model (for example Company)
9
+
10
+ * Add is_bookmark_maker to your bookmark maker model (for example User)
11
+
12
+ * Use @user.add_bookmark(@company, 'My bookmark description') or @user.unbookmark @company
13
+
14
+ * Use @user.bookmarks for list of added bookmarks
15
+
16
+ * Available methods: remove_bookmarks - delete all model bookmarks, find_bookmarks(Your class here, for ex. Company) - find bookmarks linked with specific class, has_in_bookmarks?(bookmarkable_instance)
@@ -0,0 +1,38 @@
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 = 'Bookmarker'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,18 @@
1
+ require 'active_record'
2
+ require 'active_support/inflector'
3
+
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+
7
+ module Bookmarker
8
+ if defined?(ActiveRecord::Base)
9
+ require "bookmarker/engine"
10
+ require "bookmarker/version"
11
+ require "bookmarker/engine"
12
+ require 'bookmarker/extenders/bookmarkable'
13
+ require 'bookmarker/extenders/bookmark_maker'
14
+ require 'bookmarker/bookmark'
15
+ ActiveRecord::Base.extend Bookmarker::Extenders::Bookmarkable
16
+ ActiveRecord::Base.extend Bookmarker::Extenders::BookmarkMaker
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Bookmarker
2
+ class Bookmark < ::ActiveRecord::Base
3
+
4
+ attr_accessible :bookmarkable_id, :bookmarkable_type,
5
+ :bookmark_maker_id, :bookmark_maker_type,
6
+ :bookmarkable, :bookmark_maker, :description
7
+
8
+ belongs_to :bookmarkable, :polymorphic => true
9
+ belongs_to :bookmark_maker, :polymorphic => true
10
+
11
+ validates_presence_of :bookmarkable_id
12
+ validates_presence_of :bookmark_maker_id
13
+
14
+ validates_uniqueness_of :bookmarkable_id, :scope => [:bookmarkable_type, :bookmark_maker_id, :bookmarkable_type]
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,54 @@
1
+ module Bookmarker
2
+ module BookmarkMaker
3
+
4
+ def self.included(base)
5
+
6
+ aliases = {
7
+ :add_bookmark => [:new_bookmark],
8
+ :unbookmark => [:remove_bookmark]
9
+ }
10
+
11
+ base.class_eval do
12
+
13
+ belongs_to :bookmark_maker, :polymorphic => true
14
+
15
+ validates_uniqueness_of :bookmark
16
+
17
+ has_many :bookmarks, :class_name => "Bookmarker::Bookmark", :as => :bookmark_maker
18
+
19
+ aliases.each do |method, links|
20
+ links.each do |new_method|
21
+ alias_method(new_method, method)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ def add_bookmark bookmarkable, description = nil
28
+ bookmark = Bookmarker::Bookmark.new( :bookmarkable => bookmarkable, :bookmark_maker => self, :description => description)
29
+ bookmark.save ? true : false
30
+ end
31
+
32
+ def find_bookmarks bookmarkable_model
33
+ bookmarks.where(:bookmarkable_type => bookmarkable_model.base_class.name)
34
+ end
35
+
36
+ def remove_bookmarks
37
+ bookmarks.delete_all
38
+ end
39
+
40
+ def find_by_instance bookmarkable
41
+ bookmarks.where(:bookmarkable_id => bookmarkable.id, :bookmarkable_type => bookmarkable.class.name)
42
+ end
43
+
44
+ def unbookmark bookmarkable
45
+ bookmark = find_by_instance(bookmarkable).first
46
+ bookmark.destroy ? true : false
47
+ end
48
+
49
+ def has_in_bookmarks? bookmarkable_instance
50
+ find_by_instance(bookmarkable_instance)
51
+ bookmarks.size > 0
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,23 @@
1
+ module Bookmarker
2
+ module Bookmarkable
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ def self.included base
9
+ base.class_eval do
10
+ belongs_to :bookmarkable, :polymorphic => true
11
+ has_many :bookmarks, :class_name => "Bookmarker::Bookmark", :as => :bookmarkable
12
+ end
13
+ end
14
+
15
+ def default_conditions
16
+ {
17
+ :bookmarkable_id => self.id,
18
+ :bookmarkable_type => self.class.base_class.name.to_s
19
+ }
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ module Feedbackable
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,22 @@
1
+ module Bookmarker
2
+ module Extenders
3
+ module BookmarkMaker
4
+
5
+ def bookmark_maker?
6
+ false
7
+ end
8
+
9
+ def is_bookmark_maker(*args)
10
+ require 'bookmarker/bookmark_maker'
11
+ include Bookmarker::BookmarkMaker
12
+
13
+ class_eval do
14
+ def self.bookmark_maker?
15
+ true
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ module Bookmarker
2
+ module Extenders
3
+ module Bookmarkable
4
+
5
+ def bookmarkable?
6
+ false
7
+ end
8
+
9
+ def is_bookmarkable
10
+ require 'bookmarker/bookmarkable'
11
+ include Bookmarker::Bookmarkable
12
+ class_eval do
13
+ def self.bookmarkable?
14
+ true
15
+ end
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Bookmarker
2
+ VERSION = "0.0.6"
3
+ end
@@ -0,0 +1,39 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ module Bookmarker
5
+ module Generators
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+
9
+ source_root File.expand_path("../templates", __FILE__)
10
+
11
+ desc "Generates migration for Bookmarker"
12
+
13
+ def self.orm
14
+ Rails::Generators.options[:rails][:orm]
15
+ end
16
+
17
+ def self.source_root
18
+ File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.class.eql?(String)) )
19
+ end
20
+
21
+ def self.orm_has_migration?
22
+ [:active_record].include? orm
23
+ end
24
+
25
+ def self.next_migration_number(dirname)
26
+ if ActiveRecord::Base.timestamped_migrations
27
+ Time.new.utc.strftime("%Y%m%d%H%M%S")
28
+ else
29
+ "%.3d" % (current_migration_number(dirname) + 1)
30
+ end
31
+ end
32
+
33
+ def create_migration_file
34
+ migration_template 'migration.rb', 'db/migrate/create_bookmarks_table.rb'
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,35 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ module Bookmarker
5
+ module Generators
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+
9
+ source_root File.expand_path("../templates", __FILE__)
10
+
11
+ desc "Generates migration for Bookmarker"
12
+
13
+ def self.orm
14
+ Rails::Generators.options[:rails][:orm]
15
+ end
16
+
17
+ def self.orm_has_migration?
18
+ [:active_record].include? orm
19
+ end
20
+
21
+ def self.next_migration_number(dirname)
22
+ if ActiveRecord::Base.timestamped_migrations
23
+ Time.new.utc.strftime("%Y%m%d%H%M%S")
24
+ else
25
+ "%.3d" % (current_migration_number(dirname) + 1)
26
+ end
27
+ end
28
+
29
+ def copy_migration
30
+ migration_template 'migration.rb', 'db/migrate/create_bookmarks_table.rb'
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ class CreateBookmarksTable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :bookmarks do |t|
4
+ t.references :bookmarkable, :polymorphic => true
5
+ t.references :bookmark_maker, :polymorphic => true
6
+ t.text :description
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :bookmarks, :bookmarkable_type
11
+ add_index :bookmarks, :bookmarkable_id
12
+
13
+ add_index :bookmarks, :bookmark_maker_type
14
+ add_index :bookmarks, :bookmark_maker_id
15
+
16
+ end
17
+
18
+ def self.down
19
+ drop_table :bookmarks
20
+ end
21
+ end
@@ -0,0 +1 @@
1
+ require 'bookmarker'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :bookmarker do
3
+ # # Task goes here
4
+ # end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bookmarker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -66,6 +66,22 @@ executables: []
66
66
  extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
+ - lib/bookmarker/bookmark.rb
70
+ - lib/bookmarker/bookmark_maker.rb
71
+ - lib/bookmarker/bookmarkable.rb
72
+ - lib/bookmarker/engine.rb
73
+ - lib/bookmarker/extenders/bookmark_maker.rb
74
+ - lib/bookmarker/extenders/bookmarkable.rb
75
+ - lib/bookmarker/version.rb
76
+ - lib/bookmarker.rb
77
+ - lib/generators/bookmarker/bookmarker_generator.rb
78
+ - lib/generators/bookmarker/install_generator.rb
79
+ - lib/generators/bookmarker/templates/migration.rb
80
+ - lib/init.rb
81
+ - lib/tasks/bookmarker_tasks.rake
82
+ - MIT-LICENSE
83
+ - Rakefile
84
+ - README.rdoc
69
85
  - test/bookmarker_test.rb
70
86
  - test/dummy/app/assets/javascripts/application.js
71
87
  - test/dummy/app/assets/stylesheets/application.css