seamusabshere-common_name 0.1.2 → 0.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.
Files changed (4) hide show
  1. data/README.rdoc +88 -50
  2. data/VERSION +1 -1
  3. data/common_name.gemspec +2 -2
  4. metadata +2 -2
data/README.rdoc CHANGED
@@ -1,15 +1,71 @@
1
1
  =common_name
2
2
 
3
- DRY up humanize/downcase/underscore/pluralize/to_sym/etc for names that we use all the time.
3
+ Stop needing to use humanize/downcase/underscore/pluralize/to_sym/etc to derive a common name.
4
+
5
+ ==Why this is useful
6
+
7
+ In our app, we have lots of classes that share something (a name) in common:
8
+
9
+ * <tt>class Automobile < Emitter</tt>
10
+ * <tt>class AutomobilesController < EmittersController</tt>
11
+ * <tt>class AutomobilesComponent < Component</tt>
12
+ * <tt>class AutomobileVersion < EmitterVersion</tt>
13
+ * <tt>Boat</tt> et al., <tt>Flight</tt> et al., etc.
14
+
15
+ Of course, there are a million ways to derive the word "automobile" from any of these class names. We could fill up our app with humanize/downcase/underscore/pluralize, but we think that's sloppy.
16
+
17
+ So we use <tt>common_name</tt>:
18
+
19
+ >> Automobile.common_name
20
+ => "automobile"
21
+ >> Automobile.new.common_name
22
+ => "automobile"
23
+ >> AutomobilesController.common_name
24
+ => "automobile"
25
+ >> AutomobilesController.new.common_name
26
+ => "automobile"
27
+ >> AutomobilesComponent.common_name
28
+ => "automobile"
29
+ >> AutomobilesComponent.new.common_name
30
+ => "automobile"
31
+ >> AutomobileVersion.common_name
32
+ => "automobile"
33
+ >> AutomobileVersion.new.common_name
34
+ => "automobile"
35
+
36
+ And when metaprogramming:
37
+
38
+ module EmitterVersionExtensions
39
+ def self.included(klass)
40
+ klass.class_eval do
41
+ set_table_name "#{common_name}_versions" # set_table_name "automobile_versions"
42
+ belongs_to common_symbol # belongs_to :automobile
43
+ has_one :profile, :through => common_symbol # has_one :profile, :through => :automobile
44
+ end
45
+ end
46
+ end
47
+
48
+ We also end up using this constantly in views.
49
+
50
+ ==Quick reference
51
+
52
+ Here are all the methods it gives you:
53
+
54
+ common_name => "bus_company"
55
+ common_symbol => :bus_company
56
+ common_instance => "@bus_company"
57
+ common_title => "Bus company"
58
+ common_human => "bus company"
59
+ common_camel => "BusCompany"
4
60
 
5
- ==Examples
61
+ common_plural => "bus_companies"
62
+ common_plural_symbol => :bus_companies
63
+ common_plural_instance => "@bus_companies"
64
+ common_plural_title => "Bus companies"
65
+ common_plural_human => "bus companies"
66
+ common_plural_camel => "BusCompanies"
6
67
 
7
- >> User.common_name
8
- => "user"
9
- >> User.common_plural_symbol
10
- => :users
11
- >> User.common_plural_instance
12
- => "@users"
68
+ common_model => BusCompany [the class]
13
69
 
14
70
  ==Quick start
15
71
 
@@ -35,24 +91,6 @@ Put this in <tt>app/helpers/application_helper.rb</tt>... (in careers/show, it w
35
91
  end
36
92
  end
37
93
 
38
- Here are all the methods it gives you:
39
-
40
- common_name => "bus_company"
41
- common_symbol => :bus_company
42
- common_instance => "@bus_company"
43
- common_title => "Bus company"
44
- common_human => "bus company"
45
- common_camel => "BusCompany"
46
-
47
- common_plural => "bus_companies"
48
- common_plural_symbol => :bus_companies
49
- common_plural_instance => "@bus_companies"
50
- common_plural_title => "Bus companies"
51
- common_plural_human => "bus companies"
52
- common_plural_camel => "BusCompanies"
53
-
54
- common_model => BusCompany [the class]
55
-
56
94
  ==What it's not
57
95
 
58
96
  It's <em>not</em> a replacement for <tt>humanize</tt>, <tt>pluralize</tt>, etc.
@@ -62,30 +100,6 @@ It's <em>not</em> a replacement for <tt>humanize</tt>, <tt>pluralize</tt>, etc.
62
100
 
63
101
  The point is to cover common names of classes and their instances.
64
102
 
65
- ==Rationale
66
-
67
- I don't like chains of humanize/downcase/underscore/pluralize/to_sym, for example:
68
-
69
- >> BusCompany.name.underscore.humanize.downcase.pluralize
70
- => "bus companies"
71
-
72
- So I replaced them with easy-to-remember methods like:
73
-
74
- >> BusCompany.common_plural_human
75
- => "bus companies"
76
-
77
- I also didn't like worrying about .name versus .class.name:
78
-
79
- >> @bus_company.class.name # @bus_company = BusCompany.new
80
- => "BusCompany"
81
- >> @bus_company.name
82
- => ""
83
-
84
- So, the <tt>common_name</tt> of a class (<tt>BusCompany</tt>) is always equivalent to the <tt>common_name</tt> of its instances (<tt>@bus_company</tt>):
85
-
86
- >> BusCompany.common_plural_human == @bus_company.common_plural_human
87
- => true
88
-
89
103
  ==Advanced usage
90
104
 
91
105
  The <tt>_common_name</tt> method should provide an <em>underscored</em> form that will be used to derive other common forms like <tt>common_human</tt> and <tt>common_plural_symbol</tt>.
@@ -124,6 +138,30 @@ That way you can enforce uncountability
124
138
 
125
139
  without setting a general rule in the Inflector that the word "government" is uncountable.
126
140
 
141
+ ==Rationale
142
+
143
+ I don't like chains of humanize/downcase/underscore/pluralize/to_sym, for example:
144
+
145
+ >> BusCompany.name.underscore.humanize.downcase.pluralize
146
+ => "bus companies"
147
+
148
+ So I replaced them with easy-to-remember methods like:
149
+
150
+ >> BusCompany.common_plural_human
151
+ => "bus companies"
152
+
153
+ I also didn't like worrying about .name versus .class.name:
154
+
155
+ >> @bus_company.class.name # @bus_company = BusCompany.new
156
+ => "BusCompany"
157
+ >> @bus_company.name
158
+ => ""
159
+
160
+ So, the <tt>common_name</tt> of a class (<tt>BusCompany</tt>) is always equivalent to the <tt>common_name</tt> of its instances (<tt>@bus_company</tt>):
161
+
162
+ >> BusCompany.common_plural_human == @bus_company.common_plural_human
163
+ => true
164
+
127
165
  ==Copyright
128
166
 
129
167
  Copyright (c) 2009 Seamus Abshere. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
data/common_name.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{common_name}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Seamus Abshere"]
12
- s.date = %q{2009-08-18}
12
+ s.date = %q{2009-09-01}
13
13
  s.description = %q{Provides methods like User.common_name (#=> "user") and User.common_plural_symbol (#=> :users) so that you don't have to chain humanize/downcase/etc. etc.'}
14
14
  s.email = %q{seamus@abshere.net}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seamusabshere-common_name
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-18 00:00:00 -07:00
12
+ date: 2009-09-01 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency