inflector_literals 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README +21 -0
  3. data/Rakefile +19 -0
  4. data/init.rb +25 -0
  5. metadata +65 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,21 @@
1
+ InflectorLiterals
2
+ =================
3
+
4
+ When you call String#humanize, it calls capitalize on the result. This means that something like "ip_address".humanize returns "Ip address" instead of "IP address".
5
+
6
+ I added a method to ActiveSupport::Inflector::Inflections called literal, that lets you specify exactly what humans expect to read for a field name.
7
+
8
+ Example
9
+ =======
10
+
11
+ in inflections.rb:
12
+
13
+ ActiveSupport::Inflector.inflections do |inflect|
14
+ inflect.literal "po_number", "PO number"
15
+ end
16
+
17
+ Thenceforth:
18
+
19
+ "po_number".humanize ==> "PO number"
20
+
21
+ Copyright (c) 2010 Ross Andrews, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the inflector_literals plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ end
11
+
12
+ desc 'Generate documentation for the inflector_literals plugin.'
13
+ Rake::RDocTask.new(:rdoc) do |rdoc|
14
+ rdoc.rdoc_dir = 'rdoc'
15
+ rdoc.title = 'InflectorLiterals'
16
+ rdoc.options << '--line-numbers' << '--inline-source'
17
+ rdoc.rdoc_files.include('README')
18
+ rdoc.rdoc_files.include('lib/**/*.rb')
19
+ end
data/init.rb ADDED
@@ -0,0 +1,25 @@
1
+ # InflectorLiterals
2
+ #
3
+ # This exists so I can say inflect.literal, pass it two strings, and control exactly
4
+ # what humanize returns for some strings. The default humanize calls capitalize on
5
+ # the result, which I don't want.
6
+
7
+ module InflectorLiterals
8
+ def literal(str, replacement)
9
+ literals.insert(0, [str, replacement])
10
+ end
11
+
12
+ def literals ; @literals ||= [] ; end
13
+ end
14
+
15
+ ActiveSupport::Inflector::Inflections.send :include, InflectorLiterals
16
+
17
+ # I hate having to do this but I couldn't find another way.
18
+ module ActiveSupport::Inflector
19
+ alias humanize_without_literals humanize
20
+
21
+ def humanize word
22
+ inflections.literals.each { |(str, replacement)| return replacement if word == str }
23
+ humanize_without_literals word
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inflector_literals
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Andrews, Ross
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-22 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Adds a literal method to Rails 3 inflections
22
+ email: randrews@geekfu.org
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - MIT-LICENSE
31
+ - README
32
+ - Rakefile
33
+ - init.rb
34
+ has_rdoc: true
35
+ homepage: https://github.com/randrews/inflector_literals
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ requirements: []
58
+
59
+ rubyforge_project: inflector_literals
60
+ rubygems_version: 1.3.6
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Adds a literal method to Rails 3 inflections
64
+ test_files: []
65
+