inspectable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2009, 2010 Jordi Bunster <jordi@bunster.org>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ = inspectable
2
+
3
+ Inspectable helps you to customize the output of your Ruby classes's 'inspect'
4
+ method.
5
+
6
+ More documentation forthcoming.
7
+
8
+ == Installation instructions
9
+
10
+ gem install inspectable
11
+
12
+ == Example usage
13
+
14
+ require 'inspectable'
15
+
16
+ class FancyObject
17
+ include Inspectable
18
+ end
19
+
20
+ == Legal
21
+
22
+ Copyright (c) 2010 Jordi Bunster, released under the MIT license
@@ -0,0 +1,2 @@
1
+ * 0.0.1 (2010-11-30):
2
+ - First release. No features, really :P
@@ -0,0 +1,28 @@
1
+ require 'lib/inspectable/version'
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'inspectable'
5
+ gem.version = Inspectable::VERSION
6
+
7
+ gem.author, gem.email = 'Jordi Bunster', 'jordi@bunster.org'
8
+
9
+ gem.summary = 'Ruby mixing to aid in customizing the #inspect method'
10
+ gem.description = %{ Objects that include the Inspectable module can easily
11
+ customize the fields that appear in their #inspect output, to avoid being
12
+ too verbose.
13
+ }.strip!.gsub! /\s+/, ' '
14
+
15
+ gem.has_rdoc = false
16
+
17
+ gem.date = Date.today
18
+ gem.files = %w[
19
+ MIT-LICENSE
20
+ README.rdoc
21
+ WHATSNEW
22
+ inspectable.gemspec
23
+ lib
24
+ lib/inspectable.rb
25
+ lib/inspectable
26
+ lib/inspectable/version.rb
27
+ ]
28
+ end
@@ -0,0 +1,34 @@
1
+ require 'inspectable/version' # to open the module
2
+
3
+ module Inspectable
4
+ module ClassMethods
5
+ def attr_inspector(*names)
6
+ @_attr_inspector ||= []
7
+ @_attr_inspector |= names.map { |n| n.to_s } if names.any?
8
+ @_attr_inspector
9
+ ensure
10
+ define_method(:inspected_attrs) { self.class.attr_inspector }
11
+ end
12
+ end
13
+
14
+ def self.included(base)
15
+ base.extend ClassMethods
16
+ end
17
+
18
+ def inspect
19
+ return super unless respond_to?(:inspected_attrs)
20
+
21
+ inspected = inspected_attrs.map do |attr_name|
22
+ next if attr_name.nil? || attr_name == ''
23
+ next unless respond_to?(attr_name.to_sym)
24
+
25
+ '%s=%s' % [ attr_name.to_s, send(attr_name.to_sym).inspect ]
26
+ end.compact.join(', ')
27
+
28
+ if inspected.any?
29
+ '#<%s:0x%s %s>' % [ self.class.to_s, object_id.to_s(16), inspected ]
30
+ else
31
+ super
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Inspectable
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inspectable
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Jordi Bunster
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-30 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: "Objects that include the Inspectable module can easily customize the fields that appear in their #inspect output, to avoid being too verbose."
23
+ email: jordi@bunster.org
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - MIT-LICENSE
32
+ - README.rdoc
33
+ - WHATSNEW
34
+ - inspectable.gemspec
35
+ - lib/inspectable.rb
36
+ - lib/inspectable/version.rb
37
+ has_rdoc: false
38
+ homepage:
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.7
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: "Ruby mixing to aid in customizing the #inspect method"
71
+ test_files: []
72
+