labelized 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,24 +1,30 @@
1
1
  = labelized
2
- A simple Ruby library for labeling things. Similar to and inspired by acts_as_taggable_on.
2
+ A simple Ruby library for labeling things. Similar to and inspired by acts_as_taggable_on but more flexible. Labelized allows you to control every aspect of label items, including the label to labeled relation. Labels can be organized into label sets. Labelized takes the approach of mixing in functionality with configuration, so you include just what you need. While labelized depends on ActiveRecord, it doesn't provide you with any models. You mixin labeleized concerns to your own models and have complete control over everything including the labels and how they get linked to your models.
3
3
 
4
4
  == Usage
5
- Passing a term in the singular allows only a single label. Plural terms allow multiple labels.
6
- The optional scope allows for multiple instances of the same tag, isolated by the scope; i.e. different capitalizations
5
+ Passing a term in the singular allows only a single label. Plural terms allow multiple labels. The optional scope allows for multiple instances of the same tag, isolated by the scope; i.e. different capitalizations. Labelized doesn't assume much about your model space. You mix in the appropriate labelized module and configure a few options.
7
6
 
8
- class Label
9
- labelized :scope => :community_id
7
+ == A Simple Example
8
+
9
+ # Call labelized on a class you want to act as the label
10
+ class Label < ActiveRecord::Base
11
+ include Labelized::LabelConcern
12
+
13
+ labelized
10
14
  end
11
-
12
- class Thing
13
- labelized [:kind, :keywords, :tracks]
15
+
16
+ # Include the LabelizedConcern and call labelized on a class you want to label
17
+ class Thing < ActiveRecord::Base
18
+ include Labelized::LabelizedConcern
19
+
20
+ labelized :labels
14
21
  end
15
22
 
16
23
  thing = Thing.new
17
-
18
- thing.kind
19
- thing.kind = ['this', 'that'] # throws Exeption
20
- thing.kind = 'this' # OK!
21
-
24
+ thing.labels # []
25
+ thing.label 'label one'
26
+ thing.labels_for 'round', :shape #
27
+
22
28
  thing.kind # 'this'
23
29
  thing.kind_list # 'this'
24
30
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.1
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{labelized}
8
- s.version = "0.7.0"
7
+ s.name = "labelized"
8
+ s.version = "0.7.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Peter T. Brown"]
12
- s.date = %q{2011-11-15}
13
- s.description = %q{A better tag library}
14
- s.email = %q{peter@pathable.com}
12
+ s.date = "2012-07-27"
13
+ s.description = "A better tag library"
14
+ s.email = "peter@pathable.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.rdoc"
@@ -41,11 +41,11 @@ Gem::Specification.new do |s|
41
41
  "spec/labelized/labelized_concern_spec.rb",
42
42
  "spec/spec_helper.rb"
43
43
  ]
44
- s.homepage = %q{http://github.com/flippyhead/labelized}
44
+ s.homepage = "http://github.com/flippyhead/labelized"
45
45
  s.licenses = ["MIT"]
46
46
  s.require_paths = ["lib"]
47
- s.rubygems_version = %q{1.6.2}
48
- s.summary = %q{A better tag library}
47
+ s.rubygems_version = "1.8.11"
48
+ s.summary = "A better tag library"
49
49
 
50
50
  if s.respond_to? :specification_version then
51
51
  s.specification_version = 3
@@ -15,7 +15,7 @@ module Labelized
15
15
  def labelized(params = {})
16
16
  setup_labelized params
17
17
 
18
- def find_or_build_by_list(labels, labeled, label_set_name = nil)
18
+ def find_or_build_by_list(labels, labeled, label_set_name = nil)
19
19
  label_set_class = (labelized_options[:label_set_class_name] || 'LabelSet').constantize
20
20
 
21
21
  unless label_set_name.blank?
@@ -24,10 +24,13 @@ module Labelized
24
24
  end
25
25
 
26
26
  LabelList.from(labels).map do |label|
27
- self.label_scope(labeled).find_or_initialize_by_name(label.strip, :label_set => label_set)
27
+ self.label_scope(labeled).find_or_initialize_by_name_and_label_set_id(label.strip, label_set.id)
28
28
  end
29
- end
29
+ end
30
30
 
31
+ def to_s
32
+ name
33
+ end
31
34
  end
32
35
  end
33
36
  end
@@ -12,11 +12,12 @@ module Labelized
12
12
  end
13
13
 
14
14
  ##
15
- # Returns a new TagList using the given tag string.
15
+ # Returns a new LabelList using the given string.
16
+ #
17
+ # LabelList.delimiter can be used to customize how labels in the string are delimited
16
18
  #
17
19
  # Example:
18
- # tag_list = TagList.from("One , Two, Three")
19
- # tag_list # ["One", "Two", "Three"]
20
+ # LabelList.from("One , Two, Three") # ["One", "Two", "Three"]
20
21
  def self.from(string)
21
22
  glue = delimiter.ends_with?(" ") ? delimiter : "#{delimiter} "
22
23
  string = string.join(glue) if string.respond_to?(:join)
@@ -24,7 +25,7 @@ module Labelized
24
25
  new.tap do |tag_list|
25
26
  string = string.to_s.dup
26
27
 
27
- # Parse the quoted tags
28
+ # Parse the quoted labels
28
29
  string.gsub!(/(\A|#{delimiter})\s*"(.*?)"\s*(#{delimiter}\s*|\z)/) { tag_list << $2; $3 }
29
30
  string.gsub!(/(\A|#{delimiter})\s*'(.*?)'\s*(#{delimiter}\s*|\z)/) { tag_list << $2; $3 }
30
31
 
@@ -33,12 +34,12 @@ module Labelized
33
34
  end
34
35
 
35
36
  ##
36
- # Add tags to the tag_list. Duplicate or blank tags will be ignored.
37
- # Use the <tt>:parse</tt> option to add an unparsed tag string.
37
+ # Add labels to the list. Duplicate or blank labels will be ignored.
38
+ # Use the <tt>:parse</tt> option to add an unparsed label string.
38
39
  #
39
40
  # Example:
40
- # tag_list.add("Fun", "Happy")
41
- # tag_list.add("Fun, Happy", :parse => true)
41
+ # list.add("Fun", "Happy")
42
+ # list.add("Fun, Happy", :parse => true)
42
43
  def add(*names)
43
44
  extract_and_apply_options!(names)
44
45
  concat(names)
@@ -47,12 +48,12 @@ module Labelized
47
48
  end
48
49
 
49
50
  ##
50
- # Remove specific tags from the tag_list.
51
- # Use the <tt>:parse</tt> option to add an unparsed tag string.
51
+ # Remove specific labels from the list.
52
+ # Use the <tt>:parse</tt> option to add an unparsed label string.
52
53
  #
53
54
  # Example:
54
- # tag_list.remove("Sad", "Lonely")
55
- # tag_list.remove("Sad, Lonely", :parse => true)
55
+ # list.remove("Sad", "Lonely")
56
+ # list.remove("Sad, Lonely", :parse => true)
56
57
  def remove(*names)
57
58
  extract_and_apply_options!(names)
58
59
  delete_if { |name| names.include?(name) }
@@ -60,12 +61,12 @@ module Labelized
60
61
  end
61
62
 
62
63
  ##
63
- # Transform the tag_list into a tag string suitable for edting in a form.
64
- # The tags are joined with <tt>TagList.delimiter</tt> and quoted if necessary.
64
+ # Transform the list into a label string suitable for edting in a form.
65
+ # The labels are joined with <tt>LabelList.delimiter</tt> and quoted if necessary.
65
66
  #
66
67
  # Example:
67
- # tag_list = TagList.new("Round", "Square,Cube")
68
- # tag_list.to_s # 'Round, "Square,Cube"'
68
+ # list = LabelList.new("Round", "Square,Cube")
69
+ # list.to_s # 'Round, "Square,Cube"'
69
70
  def to_s
70
71
  tags = frozen? ? self.dup : self
71
72
  tags.send(:clean!)
@@ -54,6 +54,7 @@ module Labelized
54
54
  label_set = label_set_class.label_scope(self).find_or_initialize_by_name(label_set_name)
55
55
  cache_label_get(label_set_name) || self.labels.where(:label_set_id => label_set.id)
56
56
  end
57
+ alias_method :labels_for, :label_for
57
58
 
58
59
  # Convenience setter to the label_set name. Accepts a single item or an array.
59
60
  labelized_label_set_names.map(&:to_s).each do |label_set_name|
@@ -67,6 +68,10 @@ module Labelized
67
68
  labels = label_for label_set_name
68
69
  Labelized::Support.singular?(label_set_name) ? labels[0] : labels
69
70
  end
71
+
72
+ define_method "#{label_set_name.to_s.singularize}_list" do
73
+ label_for(label_set_name).map(&:to_s)
74
+ end
70
75
  end
71
76
  end
72
77
  end
@@ -22,6 +22,10 @@ module Labelized
22
22
  self.setup_label_scope(scopes)
23
23
  end
24
24
 
25
+ # Sets up scoping for labels and label sets
26
+ # Typically the labeled item is passed to the scope
27
+ # So label_set with a :community_id scope, will look for labels with a community_id
28
+ # that have the same value as the community_id on the thing being labled
25
29
  def setup_label_scope(scopes)
26
30
  return if scopes.blank?
27
31
  self.class_eval do
@@ -50,13 +50,16 @@ describe Labelized::LabelizedConcern do
50
50
  it{should_not be_nil}
51
51
  it{should respond_to(:tags)}
52
52
  it{should respond_to(:tags=)}
53
- it{should have(1).tag}
54
-
53
+ it{should respond_to(:tag_list)}
55
54
  it{should respond_to(:labels)}
56
55
  it{should respond_to(:labelings)}
57
56
 
58
- its(:tags){should be_present}
59
-
57
+ context 'with labels set' do
58
+ it{should have(1).tag}
59
+ its(:tags){should be_present}
60
+ its(:tag_list){should == ['tag one']}
61
+ end
62
+
60
63
  context 'the cached tags' do
61
64
  subject{thing.tags.first}
62
65
 
@@ -71,6 +74,7 @@ describe Labelized::LabelizedConcern do
71
74
 
72
75
  its(:tags){should be_present}
73
76
  specify{subject.label_for(:tags).should be_present}
77
+ specify{subject.labels_for(:tags).should be_present}
74
78
  end
75
79
 
76
80
  context 'the result of setting one label' do
@@ -110,7 +114,6 @@ describe Labelized::LabelizedConcern do
110
114
 
111
115
  context 'when invalid' do
112
116
  let(:invalid_thing){InvalidThing.new()}
113
-
114
- specify{expect{invalid_thing.label'tag', :tags}.to raise_exception}
117
+ specify{expect{invalid_thing.label'tag', :tags}.to raise_exception(/must be labelized/)}
115
118
  end
116
119
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: labelized
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-15 00:00:00.000000000 -08:00
13
- default_executable:
12
+ date: 2012-07-27 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activesupport
17
- requirement: &2167182500 !ruby/object:Gem::Requirement
16
+ requirement: &2153532400 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: '0'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2167182500
24
+ version_requirements: *2153532400
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: bundler
28
- requirement: &2167181900 !ruby/object:Gem::Requirement
27
+ requirement: &2153531820 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ! '>='
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: '0'
34
33
  type: :development
35
34
  prerelease: false
36
- version_requirements: *2167181900
35
+ version_requirements: *2153531820
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: jeweler
39
- requirement: &2167181300 !ruby/object:Gem::Requirement
38
+ requirement: &2153531220 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ! '>='
@@ -44,10 +43,10 @@ dependencies:
44
43
  version: '0'
45
44
  type: :development
46
45
  prerelease: false
47
- version_requirements: *2167181300
46
+ version_requirements: *2153531220
48
47
  - !ruby/object:Gem::Dependency
49
48
  name: guard
50
- requirement: &2167180700 !ruby/object:Gem::Requirement
49
+ requirement: &2153527040 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ! '>='
@@ -55,10 +54,10 @@ dependencies:
55
54
  version: '0'
56
55
  type: :development
57
56
  prerelease: false
58
- version_requirements: *2167180700
57
+ version_requirements: *2153527040
59
58
  - !ruby/object:Gem::Dependency
60
59
  name: growl
61
- requirement: &2167180100 !ruby/object:Gem::Requirement
60
+ requirement: &2153526540 !ruby/object:Gem::Requirement
62
61
  none: false
63
62
  requirements:
64
63
  - - ! '>='
@@ -66,10 +65,10 @@ dependencies:
66
65
  version: '0'
67
66
  type: :development
68
67
  prerelease: false
69
- version_requirements: *2167180100
68
+ version_requirements: *2153526540
70
69
  - !ruby/object:Gem::Dependency
71
70
  name: rcov
72
- requirement: &2167179500 !ruby/object:Gem::Requirement
71
+ requirement: &2153526040 !ruby/object:Gem::Requirement
73
72
  none: false
74
73
  requirements:
75
74
  - - ! '>='
@@ -77,10 +76,10 @@ dependencies:
77
76
  version: '0'
78
77
  type: :development
79
78
  prerelease: false
80
- version_requirements: *2167179500
79
+ version_requirements: *2153526040
81
80
  - !ruby/object:Gem::Dependency
82
81
  name: rspec
83
- requirement: &2167174100 !ruby/object:Gem::Requirement
82
+ requirement: &2153525540 !ruby/object:Gem::Requirement
84
83
  none: false
85
84
  requirements:
86
85
  - - ! '>='
@@ -88,10 +87,10 @@ dependencies:
88
87
  version: '0'
89
88
  type: :development
90
89
  prerelease: false
91
- version_requirements: *2167174100
90
+ version_requirements: *2153525540
92
91
  - !ruby/object:Gem::Dependency
93
92
  name: sqlite3
94
- requirement: &2167173620 !ruby/object:Gem::Requirement
93
+ requirement: &2153525020 !ruby/object:Gem::Requirement
95
94
  none: false
96
95
  requirements:
97
96
  - - ! '>='
@@ -99,7 +98,7 @@ dependencies:
99
98
  version: '0'
100
99
  type: :development
101
100
  prerelease: false
102
- version_requirements: *2167173620
101
+ version_requirements: *2153525020
103
102
  description: A better tag library
104
103
  email: peter@pathable.com
105
104
  executables: []
@@ -131,7 +130,6 @@ files:
131
130
  - spec/labelized/label_concern_spec.rb
132
131
  - spec/labelized/labelized_concern_spec.rb
133
132
  - spec/spec_helper.rb
134
- has_rdoc: true
135
133
  homepage: http://github.com/flippyhead/labelized
136
134
  licenses:
137
135
  - MIT
@@ -147,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
145
  version: '0'
148
146
  segments:
149
147
  - 0
150
- hash: -2535347908215351964
148
+ hash: -4492055040287312457
151
149
  required_rubygems_version: !ruby/object:Gem::Requirement
152
150
  none: false
153
151
  requirements:
@@ -156,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
154
  version: '0'
157
155
  requirements: []
158
156
  rubyforge_project:
159
- rubygems_version: 1.6.2
157
+ rubygems_version: 1.8.11
160
158
  signing_key:
161
159
  specification_version: 3
162
160
  summary: A better tag library