has_machine_tags 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +3 -0
- data/README.rdoc +4 -4
- data/lib/has_machine_tags/tag_console.rb +1 -1
- data/lib/has_machine_tags/tag_list.rb +3 -5
- data/lib/has_machine_tags/version.rb +1 -1
- data/lib/has_machine_tags.rb +4 -4
- metadata +4 -22
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -19,7 +19,7 @@ This gem should run on all major Ruby versions and work with Rails 2.3.x and up.
|
|
19
19
|
|
20
20
|
Install as a gem
|
21
21
|
|
22
|
-
|
22
|
+
$ gem install has_machine_tags
|
23
23
|
|
24
24
|
# with bundler: add in Gemfile
|
25
25
|
gem 'has_machine_tags'
|
@@ -29,13 +29,13 @@ Install as a gem
|
|
29
29
|
|
30
30
|
Or as a plugin
|
31
31
|
|
32
|
-
|
32
|
+
$ script/plugin install git://github.com/cldwalker/has_machine_tags.git
|
33
33
|
|
34
34
|
|
35
35
|
Migrate your database from Rails root:
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
$ script/generate has_machine_tags_migration
|
38
|
+
$ rake db:migrate
|
39
39
|
|
40
40
|
== Usage
|
41
41
|
|
@@ -6,7 +6,7 @@ module HasMachineTags
|
|
6
6
|
# end
|
7
7
|
module TagConsole
|
8
8
|
def self.included(base) #:nodoc:
|
9
|
-
scope =
|
9
|
+
scope = ActiveRecord::VERSION::STRING >= '3.0' ? 'scope' : 'named_scope'
|
10
10
|
base.class_eval %[
|
11
11
|
self.#{scope} :namespace_counts, :select=>'*, namespace as counter, count(namespace) as count', :group=>"namespace HAVING count(namespace)>=1"
|
12
12
|
self.#{scope} :predicate_counts, :select=>'*, predicate as counter, count(predicate) as count', :group=>"predicate HAVING count(predicate)>=1"
|
@@ -1,11 +1,8 @@
|
|
1
1
|
module HasMachineTags
|
2
2
|
class TagList < Array
|
3
|
-
cattr_accessor :delimiter
|
4
|
-
self.delimiter = ','
|
5
|
-
cattr_accessor :default_predicate
|
6
|
-
self.default_predicate = 'tags'
|
7
3
|
QUICK_MODE_DELIMITER = ';'
|
8
4
|
|
5
|
+
attr_accessor :delimiter, :default_predicate
|
9
6
|
# ==== Options:
|
10
7
|
# [:quick_mode]
|
11
8
|
# When true enables a quick mode for inputing multiple machine tags under the same namespace.
|
@@ -19,6 +16,7 @@ module HasMachineTags
|
|
19
16
|
# HasMachineTags::TagList.new("gem:name=grit;git, user:name=mojombo")
|
20
17
|
# => ["gem:name=grit", "gem:tags=git", "user:name=mojombo"]
|
21
18
|
def initialize(string_or_array, options={})
|
19
|
+
@delimiter, @default_predicate = ',', 'tags'
|
22
20
|
@options = options
|
23
21
|
array = string_or_array.is_a?(Array) ? string_or_array : string_or_array.split(/\s*#{delimiter}\s*/)
|
24
22
|
array = parse_quick_mode(array) if @options[:quick_mode]
|
@@ -70,4 +68,4 @@ module HasMachineTags
|
|
70
68
|
join("#{delimiter} ")
|
71
69
|
end
|
72
70
|
end
|
73
|
-
end
|
71
|
+
end
|
data/lib/has_machine_tags.rb
CHANGED
@@ -16,7 +16,7 @@ module HasMachineTags
|
|
16
16
|
# [:reverse_has_many] Defines a has_many :through from tags to the model using the plural of the model name.
|
17
17
|
# [:quick_mode] When true, enables a quick mode to input machine tags with HasMachineTags::InstanceMethods.tag_list=(). See examples at HasMachineTags::TagList.new().
|
18
18
|
def has_machine_tags(options={})
|
19
|
-
|
19
|
+
class << self; attr_accessor :quick_mode; end
|
20
20
|
self.quick_mode = options[:quick_mode] || false
|
21
21
|
self.class_eval do
|
22
22
|
has_many :taggings, :as=>:taggable, :dependent=>:destroy
|
@@ -27,7 +27,7 @@ module HasMachineTags
|
|
27
27
|
extend HasMachineTags::Finder
|
28
28
|
include HasMachineTags::Console::InstanceMethods if options[:console]
|
29
29
|
|
30
|
-
scope_word =
|
30
|
+
scope_word = ActiveRecord::VERSION::STRING >= '3.0' ? 'scope' : 'named_scope'
|
31
31
|
send scope_word, :tagged_with, lambda { |*args|
|
32
32
|
find_options_for_tagged_with(*args)
|
33
33
|
}
|
@@ -48,14 +48,14 @@ module HasMachineTags
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def current_tag_list(list) #:nodoc:
|
51
|
-
TagList.new(list, :quick_mode=>self.quick_mode)
|
51
|
+
TagList.new(list, :quick_mode=>self.class.quick_mode)
|
52
52
|
end
|
53
53
|
|
54
54
|
# Fetches latest tag list for an object
|
55
55
|
def tag_list
|
56
56
|
@tag_list ||= TagList.new(self.tags.map(&:name))
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def quick_mode_tag_list
|
60
60
|
tag_list.to_quick_mode_string
|
61
61
|
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_machine_tags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 8
|
10
|
-
version: 0.1.8
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.0
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Gabriel Horner
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date:
|
13
|
+
date: 2011-05-30 00:00:00 -04:00
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
@@ -26,11 +21,6 @@ dependencies:
|
|
26
21
|
requirements:
|
27
22
|
- - ">="
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 19
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 1
|
33
|
-
- 0
|
34
24
|
version: 1.1.0
|
35
25
|
type: :development
|
36
26
|
version_requirements: *id001
|
@@ -81,25 +71,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
71
|
requirements:
|
82
72
|
- - ">="
|
83
73
|
- !ruby/object:Gem::Version
|
84
|
-
hash: 3
|
85
|
-
segments:
|
86
|
-
- 0
|
87
74
|
version: "0"
|
88
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
76
|
none: false
|
90
77
|
requirements:
|
91
78
|
- - ">="
|
92
79
|
- !ruby/object:Gem::Version
|
93
|
-
hash: 23
|
94
|
-
segments:
|
95
|
-
- 1
|
96
|
-
- 3
|
97
|
-
- 6
|
98
80
|
version: 1.3.6
|
99
81
|
requirements: []
|
100
82
|
|
101
83
|
rubyforge_project: tagaholic
|
102
|
-
rubygems_version: 1.
|
84
|
+
rubygems_version: 1.6.2
|
103
85
|
signing_key:
|
104
86
|
specification_version: 3
|
105
87
|
summary: A rails tagging gem which implements flickr's machine tags and maybe more (semantic tags).
|