display_name 0.1.1
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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +25 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/display_name.gemspec +55 -0
- data/lib/display_name.rb +19 -0
- data/lib/display_name/active_record.rb +2 -0
- data/test/helper.rb +10 -0
- data/test/test_display_name.rb +28 -0
- metadata +80 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Javier Martín
|
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.rdoc
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
= display_name
|
2
|
+
|
3
|
+
Easily specify which method to use to display an object. It was created to work in Rails models, though it works with any Ruby class.
|
4
|
+
|
5
|
+
== Install
|
6
|
+
|
7
|
+
gem install display_name
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
class Person < ActiveRecord::Base
|
12
|
+
display_name :full_name
|
13
|
+
end
|
14
|
+
|
15
|
+
This will generate a method "display_name" for the record, which will return the full name. It will also override the "to_s" method, so in the view you could use:
|
16
|
+
|
17
|
+
<%= person %>
|
18
|
+
|
19
|
+
That would automatically display the full name of the person. It also helps populating selects for lists of records.
|
20
|
+
|
21
|
+
Note that the display_name can be any method, and not necessary a database column.
|
22
|
+
|
23
|
+
== Copyright
|
24
|
+
|
25
|
+
Copyright (c) 2010 Javier Martín. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |gem|
|
9
|
+
gem.name = "display_name"
|
10
|
+
gem.summary = %Q{Specify which method to use to display an object}
|
11
|
+
gem.description = %Q{The automatic "to_s" and (for some form builders, for example)
|
12
|
+
"display_name" methods display useful information about the record,
|
13
|
+
but not the prettiest one when you want to show it to the end user.
|
14
|
+
This gem allows you to easily display the object in a pretty way}
|
15
|
+
gem.email = "elretirao@elretirao.net"
|
16
|
+
gem.homepage = "http://github.com/javierv/display_name"
|
17
|
+
gem.authors = ["Javier Martín"]
|
18
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
+
end
|
20
|
+
Jeweler::GemcutterTasks.new
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'rake/testtask'
|
26
|
+
Rake::TestTask.new(:test) do |test|
|
27
|
+
test.libs << 'lib' << 'test'
|
28
|
+
test.pattern = 'test/**/test_*.rb'
|
29
|
+
test.verbose = true
|
30
|
+
end
|
31
|
+
|
32
|
+
begin
|
33
|
+
require 'rcov/rcovtask'
|
34
|
+
Rcov::RcovTask.new do |test|
|
35
|
+
test.libs << 'test'
|
36
|
+
test.pattern = 'test/**/test_*.rb'
|
37
|
+
test.verbose = true
|
38
|
+
end
|
39
|
+
rescue LoadError
|
40
|
+
task :rcov do
|
41
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
task :test => :check_dependencies
|
46
|
+
|
47
|
+
task :default => :test
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "display_name #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{display_name}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Javier Martín"]
|
12
|
+
s.date = %q{2010-08-09}
|
13
|
+
s.description = %q{The automatic "to_s" and (for some form builders, for example)
|
14
|
+
"display_name" methods display useful information about the record,
|
15
|
+
but not the prettiest one when you want to show it to the end user.
|
16
|
+
This gem allows you to easily display the object in a pretty way}
|
17
|
+
s.email = %q{elretirao@elretirao.net}
|
18
|
+
s.extra_rdoc_files = [
|
19
|
+
"LICENSE",
|
20
|
+
"README.rdoc"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
".document",
|
24
|
+
".gitignore",
|
25
|
+
"LICENSE",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"display_name.gemspec",
|
30
|
+
"lib/display_name.rb",
|
31
|
+
"lib/display_name/active_record.rb",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_display_name.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/javierv/display_name}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.7}
|
39
|
+
s.summary = %q{Specify which method to use to display an object}
|
40
|
+
s.test_files = [
|
41
|
+
"test/helper.rb",
|
42
|
+
"test/test_display_name.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
else
|
51
|
+
end
|
52
|
+
else
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
data/lib/display_name.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module DisplayName
|
2
|
+
def self.included(base)
|
3
|
+
base.extend ClassMethods
|
4
|
+
end
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def display_name(method)
|
8
|
+
define_method :display_name do
|
9
|
+
send(method)
|
10
|
+
end
|
11
|
+
|
12
|
+
define_method :to_s do
|
13
|
+
send(method)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'display_name/active_record'
|
data/test/helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Person
|
4
|
+
include DisplayName
|
5
|
+
|
6
|
+
display_name :full_name
|
7
|
+
|
8
|
+
def initialize(name, last_name)
|
9
|
+
@name = name
|
10
|
+
@last_name = last_name
|
11
|
+
end
|
12
|
+
|
13
|
+
def full_name
|
14
|
+
"#{@name} #{@last_name}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class DisplayNameTest < Test::Unit::TestCase
|
19
|
+
test 'using display_name method returns the result of the specified method' do
|
20
|
+
@person = Person.new('Juan', 'Olvido')
|
21
|
+
assert_equal @person.display_name, "Juan Olvido"
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'using to_s retuns the result of the specified method' do
|
25
|
+
@person = Person.new('Juan', 'Olvido')
|
26
|
+
assert_equal "Juan Olvido", @person.to_s
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: display_name
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- "Javier Mart\xC3\xADn"
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-08-09 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: |-
|
22
|
+
The automatic "to_s" and (for some form builders, for example)
|
23
|
+
"display_name" methods display useful information about the record,
|
24
|
+
but not the prettiest one when you want to show it to the end user.
|
25
|
+
This gem allows you to easily display the object in a pretty way
|
26
|
+
email: elretirao@elretirao.net
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- display_name.gemspec
|
42
|
+
- lib/display_name.rb
|
43
|
+
- lib/display_name/active_record.rb
|
44
|
+
- test/helper.rb
|
45
|
+
- test/test_display_name.rb
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://github.com/javierv/display_name
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options:
|
52
|
+
- --charset=UTF-8
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.3.7
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Specify which method to use to display an object
|
78
|
+
test_files:
|
79
|
+
- test/helper.rb
|
80
|
+
- test/test_display_name.rb
|