acts_as_label 1.1.0 → 1.1.3

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/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/README.rdoc CHANGED
@@ -70,6 +70,19 @@ method +default+. This yields more expressive code.
70
70
  User.create!({ :name => "Anonymous Dude", :role => Role.default })
71
71
 
72
72
 
73
+ To help avoid excessive querying, the extension overrides the equality operator.
74
+ This allows record comparisons in a couple of formats:
75
+
76
+ u.role == Role.superuser # as you would expect
77
+ u.role == :superuser # to spare a superfluous query (same as u.role.to_sym == :superuser)
78
+
79
+
80
+ Other useful utility methods:
81
+
82
+ +to_s+:: Returns the friendly label value
83
+ +to_sym+:: Returns the downcased, symbolized system label value
84
+
85
+
73
86
 
74
87
  == Helpful Links
75
88
 
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require "rake"
2
2
  require "rake/testtask"
3
- require "rake/rdoctask"
3
+ require "rdoc/task"
4
4
  require "jeweler"
5
5
 
6
6
 
@@ -35,8 +35,8 @@ begin
35
35
  gemspec.name = "acts_as_label"
36
36
  gemspec.summary = "Gem version of acts_as_label Rails plugin."
37
37
 
38
- gemspec.add_dependency("activerecord", ">=2.3.4")
39
- gemspec.add_development_dependency("activesupport", ">=2.3.4")
38
+ gemspec.add_dependency("activerecord", ">=3.0.0")
39
+ gemspec.add_development_dependency("activesupport", ">=3.0.0")
40
40
  gemspec.files.include("lib/**/*.rb")
41
41
  end
42
42
  Jeweler::GemcutterTasks.new
@@ -1,52 +1,25 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "acts_as_label/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{acts_as_label}
8
- s.version = "1.1.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Coroutine}, %q{John Dugan}, %q{Rick Branson}]
12
- s.date = %q{2011-05-12}
6
+ s.name = "acts_as_label"
7
+ s.version = Coroutine::ActsAsLabel::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Coroutine", "John Dugan"]
10
+ s.email = ["gems@coroutine.com"]
11
+ s.homepage = "http://github.com/coroutine/acts_as_label"
12
+ s.summary = %q{This acts_as extension simplifies the process of assigning mutable user-friendly labels to immutable system labels.}
13
13
  s.description = %q{This acts_as extension implements a system label and a friendly label on a class and centralizes the logic for performing validations and accessing items by system label.}
14
- s.email = %q{jdugan@coroutine.com}
15
- s.extra_rdoc_files = [
16
- "README.rdoc"
17
- ]
18
- s.files = [
19
- ".specification",
20
- "MIT-LICENSE",
21
- "README.rdoc",
22
- "Rakefile",
23
- "VERSION",
24
- "acts_as_label.gemspec",
25
- "init.rb",
26
- "lib/acts_as_label.rb",
27
- "lib/acts_as_label/base.rb",
28
- "rails/init.rb",
29
- "test/acts_as_label_test.rb",
30
- "test/test_helper.rb"
31
- ]
32
- s.homepage = %q{http://github.com/coroutine/acts_as_label}
33
- s.require_paths = [%q{lib}]
34
- s.rubygems_version = %q{1.8.2}
35
- s.summary = %q{Gem version of acts_as_label Rails plugin.}
36
14
 
37
- if s.respond_to? :specification_version then
38
- s.specification_version = 3
15
+ s.add_dependency "rails", ">= 3.0.0"
16
+
17
+ s.add_development_dependency "rspec", ">= 2.0.0"
18
+
19
+ s.rubyforge_project = "acts_as_label"
39
20
 
40
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
- s.add_runtime_dependency(%q<activerecord>, [">= 2.3.4"])
42
- s.add_development_dependency(%q<activesupport>, [">= 2.3.4"])
43
- else
44
- s.add_dependency(%q<activerecord>, [">= 2.3.4"])
45
- s.add_dependency(%q<activesupport>, [">= 2.3.4"])
46
- end
47
- else
48
- s.add_dependency(%q<activerecord>, [">= 2.3.4"])
49
- s.add_dependency(%q<activesupport>, [">= 2.3.4"])
50
- end
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
51
25
  end
52
-
data/init.rb CHANGED
@@ -1 +1 @@
1
- require File.dirname(__FILE__) + "/rails/init.rb"
1
+ require "acts_as_label"
@@ -78,20 +78,19 @@ module Coroutine #:nodoc:
78
78
  class_eval do
79
79
 
80
80
  # inheritable accessors
81
- write_inheritable_attribute :acts_as_label_system_label_column, system_label
82
- class_inheritable_reader :acts_as_label_system_label_column
83
- write_inheritable_attribute :acts_as_label_label_column, label
84
- class_inheritable_reader :acts_as_label_label_column
85
- write_inheritable_attribute :acts_as_label_scope, scope
86
- class_inheritable_reader :acts_as_label_scope
87
- write_inheritable_attribute :acts_as_label_default_system_label, default
88
- class_inheritable_reader :acts_as_label_default_system_label
89
-
90
-
81
+ class_attribute :acts_as_label_system_label_column
82
+ class_attribute :acts_as_label_label_column
83
+ class_attribute :acts_as_label_scope
84
+ class_attribute :acts_as_label_default_system_label
85
+
86
+ self.acts_as_label_system_label_column = system_label
87
+ self.acts_as_label_label_column = label
88
+ self.acts_as_label_scope = scope
89
+ self.acts_as_label_default_system_label = default
90
+
91
91
  # protect attributes
92
92
  attr_readonly system_label
93
93
 
94
-
95
94
  # validations
96
95
  validates_presence_of system_label
97
96
  validates_length_of system_label, :maximum => 255
@@ -99,8 +98,6 @@ module Coroutine #:nodoc:
99
98
  validates_presence_of label
100
99
  validates_length_of label, :maximum => 255
101
100
 
102
-
103
-
104
101
  # This method catches all undefined method calls. It first sees if any ancestor
105
102
  # understands the request. If not, it tries to match the method call to an
106
103
  # existing system label. If that is found, it lazily manufacturers a method on the
@@ -112,8 +109,6 @@ module Coroutine #:nodoc:
112
109
  rescue NoMethodError => e
113
110
  if has_acts_as_label_method?(method)
114
111
  self.__send__(method)
115
- elsif method.to_s == "to_ary"
116
- # do nothing
117
112
  else
118
113
  throw e
119
114
  end
@@ -135,6 +130,8 @@ module Coroutine #:nodoc:
135
130
  def #{mn}
136
131
  by_acts_as_label_system_label('#{sl}')
137
132
  end
133
+
134
+ alias_method :#{mn.upcase}, :#{mn}
138
135
  end
139
136
  }
140
137
  end
@@ -144,17 +141,9 @@ module Coroutine #:nodoc:
144
141
 
145
142
 
146
143
  # This method finds an active record object for the given system label.
147
- # It automatically determines the correct syntax for the current version
148
- # of rails via duck typing.def typing.
149
144
  #
150
145
  def self.by_acts_as_label_system_label(system_label)
151
- sl = system_label.to_s.upcase
152
-
153
- if @by_system_label_has_arel ||= ActiveRecord::Base.respond_to?(:where)
154
- where("#{acts_as_label_system_label_column} = ?", sl).first
155
- else
156
- find(:first, :conditions => ["#{acts_as_label_system_label_column} = ?", sl])
157
- end
146
+ where("#{acts_as_label_system_label_column} = ?", system_label.to_s.upcase).first
158
147
  end
159
148
 
160
149
 
@@ -192,6 +181,16 @@ module Coroutine #:nodoc:
192
181
 
193
182
  module InstanceMethods
194
183
 
184
+ # This method overrides to_ary to return nil, which tells anything trying to
185
+ # flatten this we are already flat. This is necessary because we are overriding
186
+ # active records method missing, which must do this somewhere in the bowels
187
+ # of rails.
188
+ #
189
+ def to_ary
190
+ nil
191
+ end
192
+
193
+
195
194
  # This method overrides the to_s method to return the friendly label value.
196
195
  #
197
196
  def to_s
@@ -214,11 +213,11 @@ module Coroutine #:nodoc:
214
213
  # u.role == :superuser
215
214
  #
216
215
  def ==(other)
217
- self.to_sym == other.to_sym
216
+ self.to_sym == (other.to_sym rescue false)
218
217
  end
219
218
 
220
219
  end
221
220
 
222
221
  end
223
222
  end
224
- end
223
+ end
@@ -0,0 +1,5 @@
1
+ module Coroutine
2
+ module ActsAsLabel
3
+ VERSION = "1.1.3"
4
+ end
5
+ end
@@ -293,6 +293,8 @@ class ActsAsLabelTest < ActiveSupport::TestCase
293
293
 
294
294
  assert (r1 == Role.superuser)
295
295
  assert (r1 == :superuser)
296
+
297
+ assert !(r1 == false)
296
298
  end
297
299
 
298
300
  def test_to_s
@@ -306,7 +308,6 @@ class ActsAsLabelTest < ActiveSupport::TestCase
306
308
  end
307
309
 
308
310
  def test_upcase_system_label_value
309
-
310
311
  # default system label column name
311
312
  record = Role.create!({ :system_label => "Customer", :label => "Client" })
312
313
  assert_equal record.system_label, "CUSTOMER"
@@ -314,7 +315,11 @@ class ActsAsLabelTest < ActiveSupport::TestCase
314
315
  # custom system label column name
315
316
  record = Framework.create!( :system_name => "example", :name => "Example")
316
317
  assert_equal record.system_name, "EXAMPLE"
317
-
318
+ end
319
+
320
+ def test_support_upcase_accessors
321
+ assert Role.SUPERUSER == Role.superuser
322
+ assert Role.SUPERUSER == :superuser
318
323
  end
319
324
 
320
325
  end
data/test/test_helper.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # require rails stuff
2
2
  require "rubygems"
3
+ require "active_record"
3
4
  require "active_support"
4
5
  require "active_support/test_case"
5
- require "active_record"
6
6
  require "test/unit"
7
7
 
8
8
  # require plugin
metadata CHANGED
@@ -1,76 +1,77 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_label
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 0
10
- version: 1.1.0
9
+ - 3
10
+ version: 1.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Coroutine
14
14
  - John Dugan
15
- - Rick Branson
16
15
  autorequire:
17
16
  bindir: bin
18
17
  cert_chain: []
19
18
 
20
- date: 2011-05-12 00:00:00 -05:00
19
+ date: 2011-11-16 00:00:00 -06:00
21
20
  default_executable:
22
21
  dependencies:
23
22
  - !ruby/object:Gem::Dependency
24
- name: activerecord
23
+ name: rails
25
24
  prerelease: false
26
25
  requirement: &id001 !ruby/object:Gem::Requirement
27
26
  none: false
28
27
  requirements:
29
28
  - - ">="
30
29
  - !ruby/object:Gem::Version
31
- hash: 11
30
+ hash: 7
32
31
  segments:
33
- - 2
34
32
  - 3
35
- - 4
36
- version: 2.3.4
33
+ - 0
34
+ - 0
35
+ version: 3.0.0
37
36
  type: :runtime
38
37
  version_requirements: *id001
39
38
  - !ruby/object:Gem::Dependency
40
- name: activesupport
39
+ name: rspec
41
40
  prerelease: false
42
41
  requirement: &id002 !ruby/object:Gem::Requirement
43
42
  none: false
44
43
  requirements:
45
44
  - - ">="
46
45
  - !ruby/object:Gem::Version
47
- hash: 11
46
+ hash: 15
48
47
  segments:
49
48
  - 2
50
- - 3
51
- - 4
52
- version: 2.3.4
49
+ - 0
50
+ - 0
51
+ version: 2.0.0
53
52
  type: :development
54
53
  version_requirements: *id002
55
54
  description: This acts_as extension implements a system label and a friendly label on a class and centralizes the logic for performing validations and accessing items by system label.
56
- email: jdugan@coroutine.com
55
+ email:
56
+ - gems@coroutine.com
57
57
  executables: []
58
58
 
59
59
  extensions: []
60
60
 
61
- extra_rdoc_files:
62
- - README.rdoc
61
+ extra_rdoc_files: []
62
+
63
63
  files:
64
+ - .gitignore
64
65
  - .specification
66
+ - Gemfile
65
67
  - MIT-LICENSE
66
68
  - README.rdoc
67
69
  - Rakefile
68
- - VERSION
69
70
  - acts_as_label.gemspec
70
71
  - init.rb
71
72
  - lib/acts_as_label.rb
72
73
  - lib/acts_as_label/base.rb
73
- - rails/init.rb
74
+ - lib/acts_as_label/version.rb
74
75
  - test/acts_as_label_test.rb
75
76
  - test/test_helper.rb
76
77
  has_rdoc: true
@@ -102,10 +103,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
103
  version: "0"
103
104
  requirements: []
104
105
 
105
- rubyforge_project:
106
+ rubyforge_project: acts_as_label
106
107
  rubygems_version: 1.6.2
107
108
  signing_key:
108
109
  specification_version: 3
109
- summary: Gem version of acts_as_label Rails plugin.
110
- test_files: []
111
-
110
+ summary: This acts_as extension simplifies the process of assigning mutable user-friendly labels to immutable system labels.
111
+ test_files:
112
+ - test/acts_as_label_test.rb
113
+ - test/test_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.1.0
data/rails/init.rb DELETED
@@ -1 +0,0 @@
1
- require "acts_as_label"