jackdempsey-sequel_taggable 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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Jack Dempsey
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/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rubygems/specification'
4
+ require 'date'
5
+ require 'spec/rake/spectask'
6
+
7
+ GEM = "sequel_taggable"
8
+ GEM_VERSION = "0.0.1"
9
+ AUTHOR = "Jack Dempsey"
10
+ EMAIL = "jack.dempsey@gmail.com"
11
+ HOMEPAGE = "http://jackndempsey.blogspot.com"
12
+ SUMMARY = "A gem that provides Sequel::Models with tagging capabilities"
13
+
14
+ spec = Gem::Specification.new do |s|
15
+ s.name = GEM
16
+ s.version = GEM_VERSION
17
+ s.platform = Gem::Platform::RUBY
18
+ s.has_rdoc = false
19
+ s.extra_rdoc_files = ["README.markdown", "LICENSE", 'TODO']
20
+ s.summary = SUMMARY
21
+ s.description = s.summary
22
+ s.author = AUTHOR
23
+ s.email = EMAIL
24
+ s.homepage = HOMEPAGE
25
+
26
+ # Uncomment this to add a dependency
27
+ s.add_dependency "sequel_polymorphic"
28
+
29
+ s.require_path = 'lib'
30
+ s.autorequire = GEM
31
+ s.files = %w(LICENSE README.markdown Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
32
+ end
33
+
34
+ task :default => :spec
35
+
36
+ desc "Run specs"
37
+ Spec::Rake::SpecTask.new do |t|
38
+ t.spec_files = FileList['spec/**/*_spec.rb']
39
+ t.spec_opts = %w(-fs --color)
40
+ end
41
+
42
+
43
+ Rake::GemPackageTask.new(spec) do |pkg|
44
+ pkg.gem_spec = spec
45
+ end
46
+
47
+ desc "install the gem locally"
48
+ task :install => [:package] do
49
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
50
+ end
51
+
52
+ desc "create a gemspec file"
53
+ task :make_spec do
54
+ File.open("#{GEM}.gemspec", "w") do |file|
55
+ file.puts spec.to_ruby
56
+ end
57
+ end
data/TODO ADDED
@@ -0,0 +1,4 @@
1
+ Add in more advanced capabilities
2
+ - add/remove multiple tags at once
3
+
4
+ Look into adding something like dm-tags context so you have a list of tags as well as skills and other things
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'sequel_taggable/tag'
5
+ require 'sequel_taggable/tagging'
6
+ require 'sequel_taggable/sequel_taggable'
@@ -0,0 +1,24 @@
1
+ class CreateTags < Sequel::Migration
2
+ def up
3
+ create_table :tags do
4
+ primary_key :id, :integer, :auto_increment => true
5
+ varchar :name, :null => false
6
+ end
7
+
8
+ create_table :taggings do
9
+ primary_key :id, :integer, :auto_increment => true
10
+ integer :tag_id, :null => false
11
+ integer :taggable_id, :null => false
12
+ varchar :taggable_type, :null => false
13
+ #varchar :tag_context, :null => false
14
+
15
+ #datetime :created_at #TODO decide on using is_timestamped plugin to autofill this
16
+ index [:tag_id, :taggable_id, :taggable_type]
17
+ end
18
+ end
19
+
20
+ def down
21
+ drop_table :tags
22
+ drop_table :taggings
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ module Sequel
2
+ module Plugins
3
+ module Taggable
4
+ # Apply the plugin to the model.
5
+ def self.apply(model, options = {})
6
+ model.class_eval %{
7
+ is :polymorphic
8
+ has_many :taggings, :as => :taggable
9
+ many_to_many :tags, :through => :taggings, :as => :taggable
10
+ }
11
+ end
12
+
13
+ module InstanceMethods
14
+ end
15
+
16
+ module ClassMethods
17
+ end # ClassMethods
18
+ end # Taggable
19
+ end # Plugins
20
+ end # Sequel
21
+
@@ -0,0 +1,6 @@
1
+ class Tag < Sequel::Model
2
+ one_to_many :taggings
3
+
4
+ validates_presence_of :name
5
+
6
+ end
@@ -0,0 +1,11 @@
1
+ class Tagging < Sequel::Model
2
+ is :polymorphic
3
+ many_to_one :tag
4
+ many_to_one :taggable, :polymorphic => true
5
+
6
+ validates_presence_of :tag_id, :taggable_id, :taggable_type#, :tag_context
7
+
8
+ # def taggable
9
+ # eval("#{taggable_type}.get!(#{taggable_id})") if taggable_type and taggable_id
10
+ # end
11
+ end
@@ -0,0 +1,18 @@
1
+ DB = Sequel.sqlite
2
+
3
+ require File.dirname(__FILE__) + '/../lib/sequel_taggable/migration'
4
+ CreateTags.apply(DB, :up)
5
+
6
+ #DB["select * from sqlite_master"].print
7
+
8
+
9
+ class TaggedModel < Sequel::Model
10
+ set_schema do
11
+ primary_key :id
12
+ varchar :name
13
+ end
14
+
15
+ is :taggable
16
+ end
17
+
18
+ TaggedModel.create_table!
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Sequel::Plugins::Taggable do
4
+ before do
5
+ @tagged_model = TaggedModel.new
6
+ end
7
+
8
+ it "should add a .has_tags method to models which include DataMapper::Resource" do
9
+ TaggedModel.should respond_to(:has_tags)
10
+ # AnotherTaggedModel.should respond_to(:has_tags)
11
+ # DefaultTaggedModel.should respond_to(:has_tags)
12
+ # UntaggedModel.should respond_to(:has_tags)
13
+ end
14
+
15
+ it "should add a .has_tags_on method to models which include DataMapper::Resource" do
16
+ TaggedModel.should respond_to(:has_tags_on)
17
+ # AnotherTaggedModel.should respond_to(:has_tags_on)
18
+ # DefaultTaggedModel.should respond_to(:has_tags_on)
19
+ # UntaggedModel.should respond_to(:has_tags_on)
20
+ end
21
+
22
+ describe ".has_tags_on" do
23
+ it "should accept an array of context names" do
24
+ class HasTagsOnTestModel < Sequel::Model
25
+ is :taggable
26
+ end
27
+ lambda{HasTagsOnTestModel.has_tags_on(:should, 'not', :raise)}.should_not raise_error(ArgumentError)
28
+ end
29
+
30
+ it "should create taggable functionality for each of the context names passed" do
31
+ class TestModel < Sequel::Model
32
+ is :taggable
33
+ has_tags_on :pets, 'skills', :tags
34
+ end
35
+ TestModel.should be_taggable
36
+ a = TestModel.new
37
+ a.should be_taggable
38
+ a.should respond_to(:pet_list)
39
+ a.should respond_to(:skill_list)
40
+ a.should respond_to(:tag_list)
41
+ a.should respond_to(:pet_list=)
42
+ a.should respond_to(:skill_list=)
43
+ a.should respond_to(:tag_list=)
44
+ end
45
+ end
46
+
47
+ describe ".has_tags" do
48
+ it "should raise an error message if someone uses has_tags with an argument list" do
49
+ lambda do
50
+ class TagsOnly < Sequel::Model
51
+ is :taggable
52
+ has_tags :pets, :skills
53
+ end
54
+ end.should raise_error(RuntimeError)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe Tag do
4
+ before(:each) do
5
+ @tag = Tag.new
6
+ end
7
+
8
+ it "should have id and name properties" do
9
+ @tag.should respond_to(:id)
10
+ @tag.should respond_to(:name)
11
+ end
12
+
13
+ it "should have many Taggings" do
14
+ Tag.associations.should include(:taggings)
15
+ end
16
+
17
+ it "should validate the presence of name" do
18
+ @tag.should_not be_valid
19
+ @tag.name = "Meme"
20
+ @tag.should be_valid
21
+ end
22
+ end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe Tagging do
4
+ before(:each) do
5
+ @tagging = Tagging.new
6
+ end
7
+
8
+ it "should have properties: id, tag_id, taggable_id, taggable_type, tagger_id, tagger_type, and tag_context" do
9
+ @tagging.should respond_to(:id)
10
+ @tagging.should respond_to(:tag_id)
11
+ @tagging.should respond_to(:taggable_id)
12
+ @tagging.should respond_to(:taggable_type)
13
+ @tagging.should respond_to(:tag_context)
14
+ end
15
+
16
+ it "should validate the presence of tag_id, taggable_id, taggable_type and tag_context" do
17
+ @tagging.should_not be_valid
18
+ @tagging.tag_id = 1
19
+ @tagging.should_not be_valid
20
+ @tagging.taggable_id = 1
21
+ @tagging.should_not be_valid
22
+ @tagging.taggable_type = "TaggedModel"
23
+ @tagging.should_not be_valid
24
+ @tagging.tag_context = "skills"
25
+ @tagging.should be_valid
26
+ end
27
+
28
+ it "should many_to_one :tag" do
29
+ Tagging.associations.should include(:tag)
30
+ Tagging.association_reflection(:tag)[:class_name].should == "Tag"
31
+ end
32
+
33
+ it "should have a method Tagging#taggable which returns the associated taggable instance" do
34
+ @tagging.should respond_to(:taggable)
35
+ @tagging.taggable.should_not be
36
+ @tagging.taggable_id = 11111
37
+ @tagging.taggable_type = "TaggedModel"
38
+ TaggedModel.should_receive(:get!).with(11111)
39
+ @tagging.taggable
40
+ end
41
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,12 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
+
4
+ require 'rubygems'
5
+ require 'spec'
6
+ require 'sequel'
7
+
8
+ require File.dirname(__FILE__) + '/sequel-setup'
9
+ require File.dirname(__FILE__) + '/../lib/sequel_taggable'
10
+
11
+
12
+
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jackdempsey-sequel_taggable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jack Dempsey
8
+ autorequire: sequel_taggable
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-08 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sequel_polymorphic
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description: A gem that provides Sequel::Models with tagging capabilities
25
+ email: jack.dempsey@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README.markdown
32
+ - LICENSE
33
+ - TODO
34
+ files:
35
+ - LICENSE
36
+ - README.markdown
37
+ - Rakefile
38
+ - TODO
39
+ - lib/sequel_taggable
40
+ - lib/sequel_taggable/migration.rb
41
+ - lib/sequel_taggable/sequel_taggable.rb
42
+ - lib/sequel_taggable/tag.rb
43
+ - lib/sequel_taggable/tagging.rb
44
+ - lib/sequel_taggable.rb
45
+ - spec/sequel-setup.rb
46
+ - spec/sequel_taggable
47
+ - spec/sequel_taggable/sequel_taggable_spec.rb
48
+ - spec/sequel_taggable/tag_spec.rb
49
+ - spec/sequel_taggable/tagging_spec.rb
50
+ - spec/spec.opts
51
+ - spec/spec_helper.rb
52
+ has_rdoc: true
53
+ homepage: http://jackndempsey.blogspot.com
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.2.0
75
+ signing_key:
76
+ specification_version: 2
77
+ summary: A gem that provides Sequel::Models with tagging capabilities
78
+ test_files: []
79
+