value_inspect 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 284654571f19001c91bcf97cf58a090bc208720d
4
+ data.tar.gz: aaaec6115d0cd38dba9e0598d14c1d8a99da6c92
5
+ SHA512:
6
+ metadata.gz: 0e78180e7238179a2d2d9554a56ed1517a0a4d57433b8b3a96844526f835d3c784e59959e220c76f1a4d148067046713358513f7209155104dd92d2fdeb94dde
7
+ data.tar.gz: 8cf7956c8d2351e63a723d279d495d74ca627062ff37a39241ac6f3dc77769ed13b3fa9157341aca7c9802401afacec48d3b891fa53793d134d3d06f829ec25b
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in value_inspect.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Wojtek Mach
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # ValueInspect
2
+
3
+ Provides implementation of #inspect that is more readable and can be used in irb.
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ Person = Struct.new :name, :age
9
+
10
+ # Before
11
+ # ======
12
+
13
+ Date.new(1970, 1, 1).inspect
14
+ # => #<Date: 1970-01-01 ((2440588j,0s,0n),+0s,2299161j)>
15
+
16
+ BigDecimal("3.14").inspect
17
+ # => #<BigDecimal:7f97bb1cd658,'0.314E1',18(18)>
18
+
19
+ Person.new("John Doe", 20).inspect
20
+ # => #<struct Person name=\"John Doe\", age=20>
21
+
22
+ # After
23
+ # =====
24
+
25
+ # remeber to put `require "value_inspect"` *after* e.g. `require "bigdecimal"`
26
+ require "value_inspect"
27
+
28
+ Date.new(1970, 1, 1).inspect
29
+ # => Date.new(1970, 1, 1)
30
+
31
+ BigDecimal("3.14").inspect
32
+ # => BigDecimal("3.14")
33
+
34
+ Person.new("John Doe", 20).inspect
35
+ # => Person.new("John Doe", 20)
36
+
37
+ # original implementation is still available:
38
+ Date.new(1970, 1, 1).original_inspect
39
+ # => #<Date: 1970-01-01 ((2440588j,0s,0n),+0s,2299161j)>
40
+ ```
41
+
42
+ ## Supported classes
43
+
44
+ * `Struct`
45
+ * `Time`
46
+ * `Date`
47
+ * `DateTime`
48
+ * `BigDecimal`
49
+ * [`Value`](https://github.com/tcrayford/Values)
50
+
51
+ ## Installation
52
+
53
+ Add this line to your application's Gemfile:
54
+
55
+ ```ruby
56
+ gem 'value_inspect'
57
+ ```
58
+
59
+ And then execute:
60
+
61
+ $ bundle
62
+
63
+ Or install it yourself as:
64
+
65
+ $ gem install value_inspect
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/wojtekmach/value_inspect>.
70
+
71
+ ## License
72
+
73
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module ValueInspect
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,71 @@
1
+ require "value_inspect/version"
2
+
3
+ class Struct
4
+ alias_method :original_inspect, :inspect
5
+
6
+ def inspect
7
+ "%s.new(%s)" % [self.class.name, values.map(&:inspect).join(", ")]
8
+ end
9
+ end
10
+
11
+ if defined? BigDecimal
12
+ class BigDecimal
13
+ alias_method :original_inspect, :inspect
14
+
15
+ def inspect
16
+ "BigDecimal(\"%s\")" % to_s('F')
17
+ end
18
+ end
19
+ end
20
+
21
+ class Time
22
+ alias_method :original_inspect, :inspect
23
+
24
+ def inspect
25
+ strftime("Time.new(%Y, %-d, %-m, %-H, %-M, %-S, \"%:z\")")
26
+ end
27
+ end
28
+
29
+ if defined? Date
30
+ class Date
31
+ alias_method :original_inspect, :inspect
32
+
33
+ def inspect
34
+ "Date.new(%s, %s, %s)" % [year, month, day]
35
+ end
36
+ end
37
+
38
+ class DateTime
39
+ def inspect
40
+ "DateTime.new(%s, %s, %s)" % [year, month, day]
41
+ end
42
+ end
43
+ end
44
+
45
+ if defined? Value
46
+ module ValueInspect
47
+ module Values
48
+ module ClassMethods
49
+ def new(*args)
50
+ cls = super
51
+ cls.send(:alias_method, :original_inspect, :inspect)
52
+ cls.prepend InstanceMethods
53
+ cls
54
+ end
55
+ end
56
+
57
+ module InstanceMethods
58
+ def inspect
59
+ "%s.new(%s)" % [self.class.name, values.map(&:inspect).join(", ")]
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ class Value
66
+ class << self
67
+ prepend ValueInspect::Values::ClassMethods
68
+ end
69
+ end
70
+ end
71
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'value_inspect/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "value_inspect"
8
+ spec.version = ValueInspect::VERSION
9
+ spec.authors = ["Wojtek Mach"]
10
+ spec.email = ["wojtek@wojtekmach.pl"]
11
+
12
+ spec.summary = %q{Provides implementation of #inspect that is more readable and can be used in irb.}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/wojtekmach/value_inspect"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.add_development_dependency "values", "~> 1.8"
26
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: value_inspect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Wojtek Mach
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: values
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ description: 'Provides implementation of #inspect that is more readable and can be
70
+ used in irb.'
71
+ email:
72
+ - wojtek@wojtekmach.pl
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/value_inspect.rb
84
+ - lib/value_inspect/version.rb
85
+ - value_inspect.gemspec
86
+ homepage: https://github.com/wojtekmach/value_inspect
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.5.1
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: 'Provides implementation of #inspect that is more readable and can be used
110
+ in irb.'
111
+ test_files: []