tagtools 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/README +40 -0
- data/install.rb +30 -0
- data/lib/tagtools.rb +1026 -0
- data/rakefile +112 -0
- data/test/global_tags_test.rb +103 -0
- data/test/user_tags_test.rb +116 -0
- metadata +58 -0
data/rakefile
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/contrib/rubyforgepublisher'
|
8
|
+
|
9
|
+
PKG_NAME = 'tagtools'
|
10
|
+
PKG_VERSION = '0.0.1'
|
11
|
+
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
12
|
+
|
13
|
+
RELEASE_NAME = "REL #{PKG_VERSION}"
|
14
|
+
|
15
|
+
RUBY_FORGE_PROJECT = "tagtools"
|
16
|
+
RUBY_FORGE_USER = "vacindak"
|
17
|
+
|
18
|
+
PKG_FILES = FileList[
|
19
|
+
"lib/**/*", "test/**/*", "examples/**/*", "doc/**/*", "[A-Z]*", "install.rb", "rakefile"
|
20
|
+
].exclude(/\bCVS\b|~$/).exclude(/database\.yml/)
|
21
|
+
|
22
|
+
desc "Default Task"
|
23
|
+
task :default => [ :test_all ]
|
24
|
+
|
25
|
+
# Run the unit tests
|
26
|
+
|
27
|
+
Rake::TestTask.new("test_all") { |t|
|
28
|
+
t.libs << "test"
|
29
|
+
t.pattern = 'test/*_test.rb'
|
30
|
+
t.verbose = true
|
31
|
+
}
|
32
|
+
|
33
|
+
# Generate the RDoc documentation
|
34
|
+
|
35
|
+
Rake::RDocTask.new { |rdoc|
|
36
|
+
rdoc.rdoc_dir = 'doc'
|
37
|
+
rdoc.title = "Tag Tools -- folksonomy system for Rails"
|
38
|
+
rdoc.options << '--line-numbers --inline-source --accessor cattr_accessor=object'
|
39
|
+
rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
40
|
+
rdoc.rdoc_files.include('README', 'CHANGELOG')
|
41
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
42
|
+
}
|
43
|
+
|
44
|
+
# Create compressed packages
|
45
|
+
|
46
|
+
dist_dirs = [ "lib", "test" ]
|
47
|
+
|
48
|
+
spec = Gem::Specification.new do |s|
|
49
|
+
s.name = PKG_NAME
|
50
|
+
s.version = PKG_VERSION
|
51
|
+
s.summary = "Folksonomy system for Rails."
|
52
|
+
s.description = "Implements a simple system for handling tagging of items in a database."
|
53
|
+
|
54
|
+
s.files = [ "rakefile", "install.rb", "README", "CHANGELOG" ]
|
55
|
+
dist_dirs.each do |dir|
|
56
|
+
s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if do |item|
|
57
|
+
item.include?( "\.svn" ) || item.include?( "database\.yml" )
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
s.add_dependency('activerecord', '>= 1.11.1')
|
62
|
+
|
63
|
+
s.require_path = 'lib'
|
64
|
+
s.autorequire = 'tagtools'
|
65
|
+
|
66
|
+
s.has_rdoc = true
|
67
|
+
s.extra_rdoc_files = %w( README )
|
68
|
+
s.rdoc_options.concat ['--main', 'README']
|
69
|
+
|
70
|
+
s.author = "Bob Aman"
|
71
|
+
s.email = "bob@sporkmonger.com"
|
72
|
+
s.homepage = "http://sporkmonger.com/projects/tagtools"
|
73
|
+
s.rubyforge_project = RUBY_FORGE_PROJECT
|
74
|
+
end
|
75
|
+
|
76
|
+
Rake::GemPackageTask.new(spec) do |p|
|
77
|
+
p.gem_spec = spec
|
78
|
+
p.need_tar = true
|
79
|
+
p.need_zip = true
|
80
|
+
end
|
81
|
+
|
82
|
+
task :lines do
|
83
|
+
lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
|
84
|
+
|
85
|
+
for file_name in FileList["lib/**/*.rb"]
|
86
|
+
f = File.open(file_name)
|
87
|
+
|
88
|
+
while line = f.gets
|
89
|
+
lines += 1
|
90
|
+
next if line =~ /^\s*$/
|
91
|
+
next if line =~ /^\s*#/
|
92
|
+
codelines += 1
|
93
|
+
end
|
94
|
+
puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
|
95
|
+
|
96
|
+
total_lines += lines
|
97
|
+
total_codelines += codelines
|
98
|
+
|
99
|
+
lines, codelines = 0, 0
|
100
|
+
end
|
101
|
+
|
102
|
+
puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
# Publishing ------------------------------------------------------
|
107
|
+
|
108
|
+
desc "Publish the API documentation"
|
109
|
+
task :pdoc => [:rdoc] do
|
110
|
+
Rake::SshDirPublisher.new("vacindak@sporkmonger.com",
|
111
|
+
"public_html/projects/tagtools/api", "doc").upload
|
112
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'tagtools'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
begin
|
6
|
+
ActiveRecord::Base.connection
|
7
|
+
rescue
|
8
|
+
possible_config_files = [
|
9
|
+
"./database.yml",
|
10
|
+
"./config/database.yml",
|
11
|
+
"../database.yml",
|
12
|
+
"../config/database.yml"
|
13
|
+
]
|
14
|
+
database_config_file = nil
|
15
|
+
for file in possible_config_files
|
16
|
+
if File.exists? file
|
17
|
+
database_config_file = file
|
18
|
+
break
|
19
|
+
end
|
20
|
+
end
|
21
|
+
database_config_hash = File.open(database_config_file) do |file|
|
22
|
+
config_hash = YAML::load(file)
|
23
|
+
unless config_hash['test'].nil?
|
24
|
+
config_hash = config_hash['test']
|
25
|
+
end
|
26
|
+
config_hash
|
27
|
+
end
|
28
|
+
ActiveRecord::Base.configurations = database_config_hash
|
29
|
+
ActiveRecord::Base.establish_connection(database_config_hash)
|
30
|
+
ActiveRecord::Base.connection
|
31
|
+
end
|
32
|
+
|
33
|
+
class Tag < ActiveRecord::Base
|
34
|
+
end
|
35
|
+
|
36
|
+
class Image < ActiveRecord::Base
|
37
|
+
acts_as_taggable(:scope => :global, :tag_class_name => "Tag")
|
38
|
+
end
|
39
|
+
|
40
|
+
class GlobalTagsTest < Test::Unit::TestCase
|
41
|
+
def setup
|
42
|
+
ActiveRecord::Base.connection.execute("DELETE FROM images_tags")
|
43
|
+
ActiveRecord::Base.connection.execute("DELETE FROM images")
|
44
|
+
ActiveRecord::Base.connection.execute("DELETE FROM tags")
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_add_tags_existing_record
|
48
|
+
ruby_on_rails = Image.new
|
49
|
+
ruby_on_rails.url = "http://www.rubyonrails.com/logo.gif"
|
50
|
+
ruby_on_rails.save
|
51
|
+
ruby_on_rails.tags.concat(["ruby", "rails", "framework"])
|
52
|
+
assert_equal(Tag.find_by_name("framework"),
|
53
|
+
ruby_on_rails.tags(true)[0])
|
54
|
+
assert_equal(Tag.find_by_name("rails"),
|
55
|
+
ruby_on_rails.tags(true)[1])
|
56
|
+
assert_equal(Tag.find_by_name("ruby"),
|
57
|
+
ruby_on_rails.tags(true)[2])
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_add_tags_new_record
|
61
|
+
some_guy = User.new
|
62
|
+
some_guy.name = "Joe Normal"
|
63
|
+
some_guy.save
|
64
|
+
ruby_on_rails = Image.new
|
65
|
+
ruby_on_rails.url = "http://www.rubyonrails.com/logo.gif"
|
66
|
+
assert_equal(true, ruby_on_rails.new_record?)
|
67
|
+
ruby_on_rails.tags.concat(["ruby", "rails", "framework"])
|
68
|
+
assert_equal(true, ruby_on_rails.new_record?)
|
69
|
+
ruby_on_rails.save
|
70
|
+
assert_equal(false, ruby_on_rails.new_record?)
|
71
|
+
assert_equal(Tag.find_by_name("framework"),
|
72
|
+
ruby_on_rails.tags(true)[0])
|
73
|
+
assert_equal(Tag.find_by_name("rails"),
|
74
|
+
ruby_on_rails.tags(true)[1])
|
75
|
+
assert_equal(Tag.find_by_name("ruby"),
|
76
|
+
ruby_on_rails.tags(true)[2])
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_tag_query
|
80
|
+
ruby_on_rails = Image.new
|
81
|
+
ruby_on_rails.url = "http://www.rubyonrails.com/logo.gif"
|
82
|
+
ruby_on_rails.save
|
83
|
+
ruby_on_rails.tags << "ruby"
|
84
|
+
ruby_on_rails.tags << "rails"
|
85
|
+
ruby_on_rails.tags << "framework"
|
86
|
+
red_handed = Image.new
|
87
|
+
red_handed.url = "http://redhanded.hobix.com/logo.gif"
|
88
|
+
red_handed.save
|
89
|
+
red_handed.tags << "ruby"
|
90
|
+
red_handed.tags << "cult"
|
91
|
+
results = Image.tag_query(:with_all_tags => ["ruby", "cult"])
|
92
|
+
assert_equal(red_handed, results.first)
|
93
|
+
results = Image.tag_query(:with_all_tags => ["ruby", "framework"])
|
94
|
+
assert_equal(ruby_on_rails, results.first)
|
95
|
+
results = Image.tag_query(:with_any_tags => ["cult", "framework"])
|
96
|
+
assert(results.include?(ruby_on_rails))
|
97
|
+
assert(results.include?(red_handed))
|
98
|
+
results = Image.tag_query(:with_all_tags => ["ruby", "framework"],
|
99
|
+
:without_tags => ["cult"])
|
100
|
+
assert_equal(ruby_on_rails, results.first)
|
101
|
+
assert(!results.include?(red_handed))
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'tagtools'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
begin
|
6
|
+
ActiveRecord::Base.connection
|
7
|
+
rescue
|
8
|
+
possible_config_files = [
|
9
|
+
"./database.yml",
|
10
|
+
"./config/database.yml",
|
11
|
+
"../database.yml",
|
12
|
+
"../config/database.yml"
|
13
|
+
]
|
14
|
+
database_config_file = nil
|
15
|
+
for file in possible_config_files
|
16
|
+
if File.exists? file
|
17
|
+
database_config_file = file
|
18
|
+
break
|
19
|
+
end
|
20
|
+
end
|
21
|
+
database_config_hash = File.open(database_config_file) do |file|
|
22
|
+
config_hash = YAML::load(file)
|
23
|
+
unless config_hash['test'].nil?
|
24
|
+
config_hash = config_hash['test']
|
25
|
+
end
|
26
|
+
config_hash
|
27
|
+
end
|
28
|
+
ActiveRecord::Base.configurations = database_config_hash
|
29
|
+
ActiveRecord::Base.establish_connection(database_config_hash)
|
30
|
+
ActiveRecord::Base.connection
|
31
|
+
end
|
32
|
+
|
33
|
+
class User < ActiveRecord::Base
|
34
|
+
end
|
35
|
+
|
36
|
+
class Tag < ActiveRecord::Base
|
37
|
+
end
|
38
|
+
|
39
|
+
class Bookmark < ActiveRecord::Base
|
40
|
+
acts_as_taggable(:scope => :user,
|
41
|
+
:user_class_name => "User", :tag_class_name => "Tag")
|
42
|
+
end
|
43
|
+
|
44
|
+
class UserTagsTest < Test::Unit::TestCase
|
45
|
+
def setup
|
46
|
+
ActiveRecord::Base.connection.execute("DELETE FROM bookmarks_tags_users")
|
47
|
+
ActiveRecord::Base.connection.execute("DELETE FROM bookmarks")
|
48
|
+
ActiveRecord::Base.connection.execute("DELETE FROM users")
|
49
|
+
ActiveRecord::Base.connection.execute("DELETE FROM tags")
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_add_tags_existing_record
|
53
|
+
some_guy = User.new
|
54
|
+
some_guy.name = "Joe Normal"
|
55
|
+
some_guy.save
|
56
|
+
ruby_on_rails = Bookmark.new
|
57
|
+
ruby_on_rails.url = "http://www.rubyonrails.com"
|
58
|
+
ruby_on_rails.save
|
59
|
+
ruby_on_rails.user_tags(some_guy.id).concat(
|
60
|
+
["ruby", "rails", "framework"])
|
61
|
+
assert_equal(Tag.find_by_name("framework"),
|
62
|
+
ruby_on_rails.user_tags(some_guy.id, true)[0])
|
63
|
+
assert_equal(Tag.find_by_name("rails"),
|
64
|
+
ruby_on_rails.user_tags(some_guy.id, true)[1])
|
65
|
+
assert_equal(Tag.find_by_name("ruby"),
|
66
|
+
ruby_on_rails.user_tags(some_guy.id, true)[2])
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_add_tags_new_record
|
70
|
+
some_guy = User.new
|
71
|
+
some_guy.name = "Joe Normal"
|
72
|
+
some_guy.save
|
73
|
+
ruby_on_rails = Bookmark.new
|
74
|
+
ruby_on_rails.url = "http://www.rubyonrails.com"
|
75
|
+
assert_equal(true, ruby_on_rails.new_record?)
|
76
|
+
ruby_on_rails.user_tags(some_guy.id).concat(
|
77
|
+
["ruby", "rails", "framework"])
|
78
|
+
assert_equal(true, ruby_on_rails.new_record?)
|
79
|
+
ruby_on_rails.save
|
80
|
+
assert_equal(false, ruby_on_rails.new_record?)
|
81
|
+
assert_equal(Tag.find_by_name("framework"),
|
82
|
+
ruby_on_rails.user_tags(some_guy.id, true)[0])
|
83
|
+
assert_equal(Tag.find_by_name("rails"),
|
84
|
+
ruby_on_rails.user_tags(some_guy.id, true)[1])
|
85
|
+
assert_equal(Tag.find_by_name("ruby"),
|
86
|
+
ruby_on_rails.user_tags(some_guy.id, true)[2])
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_tag_query
|
90
|
+
some_guy = User.new
|
91
|
+
some_guy.name = "Joe Normal"
|
92
|
+
some_guy.save
|
93
|
+
ruby_on_rails = Bookmark.new
|
94
|
+
ruby_on_rails.url = "http://www.rubyonrails.com"
|
95
|
+
ruby_on_rails.save
|
96
|
+
ruby_on_rails.user_tags(some_guy.id) << "ruby"
|
97
|
+
ruby_on_rails.user_tags(some_guy.id) << "rails"
|
98
|
+
ruby_on_rails.user_tags(some_guy.id) << "framework"
|
99
|
+
red_handed = Bookmark.new
|
100
|
+
red_handed.url = "http://redhanded.hobix.com"
|
101
|
+
red_handed.save
|
102
|
+
red_handed.user_tags(some_guy.id) << "ruby"
|
103
|
+
red_handed.user_tags(some_guy.id) << "cult"
|
104
|
+
results = Bookmark.tag_query(:with_all_tags => ["ruby", "cult"])
|
105
|
+
assert_equal(red_handed, results.first)
|
106
|
+
results = Bookmark.tag_query(:with_all_tags => ["ruby", "framework"])
|
107
|
+
assert_equal(ruby_on_rails, results.first)
|
108
|
+
results = Bookmark.tag_query(:with_any_tags => ["cult", "framework"])
|
109
|
+
assert(results.include?(ruby_on_rails))
|
110
|
+
assert(results.include?(red_handed))
|
111
|
+
results = Bookmark.tag_query(:with_all_tags => ["ruby", "framework"],
|
112
|
+
:without_tags => ["cult"])
|
113
|
+
assert_equal(ruby_on_rails, results.first)
|
114
|
+
assert(!results.include?(red_handed))
|
115
|
+
end
|
116
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: tagtools
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2005-08-28 00:00:00 -04:00
|
8
|
+
summary: Folksonomy system for Rails.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: bob@sporkmonger.com
|
12
|
+
homepage: http://sporkmonger.com/projects/tagtools
|
13
|
+
rubyforge_project: tagtools
|
14
|
+
description: Implements a simple system for handling tagging of items in a database.
|
15
|
+
autorequire: tagtools
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
-
|
22
|
+
- ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
signing_key:
|
28
|
+
cert_chain:
|
29
|
+
authors:
|
30
|
+
- Bob Aman
|
31
|
+
files:
|
32
|
+
- rakefile
|
33
|
+
- install.rb
|
34
|
+
- README
|
35
|
+
- CHANGELOG
|
36
|
+
- lib/tagtools.rb
|
37
|
+
- test/global_tags_test.rb
|
38
|
+
- test/user_tags_test.rb
|
39
|
+
test_files: []
|
40
|
+
rdoc_options:
|
41
|
+
- "--main"
|
42
|
+
- README
|
43
|
+
extra_rdoc_files:
|
44
|
+
- README
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
requirements: []
|
48
|
+
dependencies:
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: activerecord
|
51
|
+
version_requirement:
|
52
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
53
|
+
requirements:
|
54
|
+
-
|
55
|
+
- ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 1.11.1
|
58
|
+
version:
|