default_name 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Readme.markdown +27 -0
  2. data/init.rb +3 -0
  3. data/lib/default_name.rb +17 -0
  4. metadata +49 -0
data/Readme.markdown ADDED
@@ -0,0 +1,27 @@
1
+ Default Name
2
+ ============
3
+
4
+ This gem overwrites the "to_s" method for all models that have attributes named:
5
+ name, title, short_name, long_name
6
+
7
+ This is handy because largely you have that one main attribute that is representing your model.
8
+
9
+ Installation
10
+ ============
11
+
12
+ To install this gem, add it to your Gemfile
13
+ gem 'default_name'
14
+
15
+ Usage
16
+ =====
17
+ In your controller:
18
+ @company = Company.find(1)
19
+ @company.name = "Some company"
20
+
21
+ And in your view:
22
+ <%= @company >
23
+
24
+ It will fire "Some company".
25
+
26
+
27
+ Copyright (c) 2013 Tomislav Car, released under the MIT license
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ $:.unshift "#{File.dirname(__FILE__)}/lib"
2
+ ActiveRecord::Base.class_eval { include DefaultName }
3
+
@@ -0,0 +1,17 @@
1
+ module DefaultName
2
+ AVAILABLE = [:name, :title, :short_name, :long_name]
3
+
4
+ def self.included(receiver)
5
+ receiver.class_eval <<str
6
+ def to_s
7
+ AVAILABLE.each do |method_name|
8
+ if self.respond_to?(method_name)
9
+ return send(method_name)
10
+ end
11
+ end
12
+ return super
13
+ end
14
+ str
15
+ end
16
+ end
17
+
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: default_name
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tomislav Car
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'Overwrite to_s method for attributes named: name, title, short_name,
15
+ long_name'
16
+ email:
17
+ - tomislav@infinum.hr
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - Readme.markdown
23
+ - init.rb
24
+ - lib/default_name.rb
25
+ homepage: https://github.com/infinum/default_name
26
+ licenses: []
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.8.23
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: Overwrite to_s method for common name attributes
49
+ test_files: []