iron-extensions 1.2.1 → 1.2.2
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.
- checksums.yaml +4 -4
- data/History.txt +21 -17
- data/README.rdoc +21 -5
- data/Version.txt +1 -1
- data/lib/iron-extensions.rb +1 -0
- data/lib/iron/extensions/class.rb +30 -0
- data/spec/extensions/class_spec.rb +37 -0
- data/spec/spec_helper.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e63fc465ef90d238d07d8d8beedf111d0d6917b
|
4
|
+
data.tar.gz: dbdaf486d2d8d468628bd15b79e3e1a317b9b9dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e1c8b753c49c5cdaef18ab2600a677a504feadd84e5c2094dc902a7cb00ca73b9f6415e9d898405200cc18c5d5eb2343f0af89edc66f7daad005d3040ee3854
|
7
|
+
data.tar.gz: a363a7c732eeb8494ebd812a508f8fc9dd32b223a1acdeca27124a4007e0cf41940b970ecb4b20517e749485a7a305cf2eb40ecc29f7516ec67fac4dccddffad
|
data/History.txt
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
+
== 1.2.2 / 2017-08-22
|
2
|
+
|
3
|
+
* Add Class#inspect_only to allow limiting the vars displayed, support methods as well as instance vars
|
4
|
+
|
1
5
|
== 1.2.1 / 2015-01-27
|
2
6
|
|
3
7
|
* Instant revert - move Enumerable#blank? to Array#blank? and Hash#blank? as enumerables don't support #empty?, #count, etc.
|
4
8
|
|
5
9
|
== 1.2.0 / 2015-01-27
|
6
10
|
|
7
|
-
* BREAKING CHANGE:
|
8
|
-
* BREAKING CHANGE:
|
9
|
-
*
|
10
|
-
*
|
11
|
+
* BREAKING CHANGE: Remove DslProxy/DslBuilder and the dsl_* accessor helpers and move them into the iron-dsl gem
|
12
|
+
* BREAKING CHANGE: Remove deprecated Array#rand and Array#rand! - use #shuffle instead
|
13
|
+
* Improve #blank? to work on strings containing only whitespace
|
14
|
+
* Improve documentation & specs
|
11
15
|
|
12
16
|
== 1.1.5 / 2014-03-31
|
13
17
|
|
@@ -33,26 +37,26 @@
|
|
33
37
|
|
34
38
|
== 1.1.1 / 2012-03-13
|
35
39
|
|
36
|
-
*
|
37
|
-
*
|
38
|
-
* DslProxy
|
39
|
-
*
|
40
|
+
* Add DslBuilder base class for additional DSL-building goodness, is basically a better blank-slate starter class than BasicObject for working with our DslProxy class
|
41
|
+
* Add #dsl_accessor class method as a way to easily create DSL-style accessors
|
42
|
+
* Improve DslProxy to only copy back instance vars when they change
|
43
|
+
* Add #starts_with? and #ends_with? to Symbol
|
40
44
|
|
41
45
|
== 1.1.0 / 2012-03-06
|
42
46
|
|
43
|
-
*
|
47
|
+
* Add DslProxy class and specs, which enables slim and sexy DSL construction
|
44
48
|
|
45
49
|
== 1.0.1 / 2012-03-03
|
46
50
|
|
47
|
-
*
|
48
|
-
*
|
49
|
-
*
|
50
|
-
*
|
51
|
+
* Update docs, fixed up minor packaging issues
|
52
|
+
* Add spec coverage for Kernel extensions
|
53
|
+
* Add spec coverage for Numeric extensions
|
54
|
+
* Add spec coverage for Symbol extensions
|
51
55
|
* Commit to GitHub, update gem homepage to reflect same
|
52
56
|
|
53
57
|
== 1.0.0 / 2012-03-02
|
54
58
|
|
55
|
-
*
|
56
|
-
*
|
57
|
-
*
|
58
|
-
*
|
59
|
+
* Break out extensions from older irongaze gem
|
60
|
+
* Integrate several new extensions
|
61
|
+
* Improve README with listing of extensions added
|
62
|
+
* Improve spec coverage
|
data/README.rdoc
CHANGED
@@ -23,6 +23,26 @@ have been moved to the iron-dsl gem!
|
|
23
23
|
|
24
24
|
[1,2,3,4,5].delete_unless(&:odd?) # => [1,3,5]
|
25
25
|
|
26
|
+
* Class#inspect_only - override #inspect to only show the specified variables or methods
|
27
|
+
|
28
|
+
class User
|
29
|
+
# Limit inspect to these attrs
|
30
|
+
inspect_only :name, :admin?
|
31
|
+
|
32
|
+
def initialize
|
33
|
+
@name = 'Bob'
|
34
|
+
@password = 'topSECRET!'
|
35
|
+
@something_complex = ValidationEngine.new
|
36
|
+
end
|
37
|
+
|
38
|
+
def admin?
|
39
|
+
@name == 'Admin'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Inspecting instances of this class show only what we need
|
44
|
+
User.new.inspect # => "<User:1892377440 @name='Bob', :admin?=false>"
|
45
|
+
|
26
46
|
* File.safe_replace - atomic replacement of a file given a block to generate it
|
27
47
|
|
28
48
|
# Defers deleting old file until block completes successfully (ie no exceptions), then
|
@@ -91,7 +111,7 @@ have been moved to the iron-dsl gem!
|
|
91
111
|
|
92
112
|
To use:
|
93
113
|
|
94
|
-
require 'iron
|
114
|
+
require 'iron-extensions'
|
95
115
|
|
96
116
|
After that, simply write code to make use of the new extensions and helper classes.
|
97
117
|
|
@@ -108,7 +128,3 @@ To install, simply run:
|
|
108
128
|
RVM users should drop the 'sudo':
|
109
129
|
|
110
130
|
gem install iron-extensions
|
111
|
-
|
112
|
-
Then simply require the library:
|
113
|
-
|
114
|
-
require 'iron/extensions'
|
data/Version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.2
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'iron/extensions'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Class
|
2
|
+
|
3
|
+
# Override #inspect to only include the specified
|
4
|
+
def inspect_only(*methods)
|
5
|
+
@inspect_field_set = methods
|
6
|
+
alias_method :original_inspect, :inspect
|
7
|
+
class_eval do
|
8
|
+
def inspect
|
9
|
+
fields = self.class.inspect_field_set
|
10
|
+
vars = instance_variables
|
11
|
+
field_vals = fields.collect do |field|
|
12
|
+
if instance_variables.include?("@#{field}".to_sym)
|
13
|
+
"@#{field}=" + instance_variable_get("@#{field}").inspect
|
14
|
+
elsif respond_to?(field)
|
15
|
+
":#{field}=" + send(field).inspect
|
16
|
+
end
|
17
|
+
end.compact
|
18
|
+
text = "#<#{self.class.name}:#{self.object_id}"
|
19
|
+
text += (' ' + field_vals.list_join(', ')) if field_vals.any?
|
20
|
+
text += '>'
|
21
|
+
text
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def inspect_field_set
|
27
|
+
@inspect_field_set || []
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
describe Class do
|
2
|
+
|
3
|
+
it 'should inspect normally' do
|
4
|
+
class Tmp1
|
5
|
+
def initialize
|
6
|
+
@foo = 'bar'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
Tmp1.new.inspect.match(/#<Tmp1:0x[a-z0-9]+ @foo="bar">/).should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should inspect only what is requested' do
|
13
|
+
class Tmp2
|
14
|
+
inspect_only :bar
|
15
|
+
def initialize
|
16
|
+
@foo = 'bar'
|
17
|
+
@bar = 'wingo'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
Tmp2.new.inspect.match(/#<Tmp2:[a-z0-9]+ @bar="wingo">/).should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should inspect methods if requested' do
|
24
|
+
class Tmp3
|
25
|
+
inspect_only :baz
|
26
|
+
def initialize
|
27
|
+
@foo = 'bar'
|
28
|
+
@bar = 'wingo'
|
29
|
+
end
|
30
|
+
def baz
|
31
|
+
@bar + 'zzz'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
Tmp3.new.inspect.match(/#<Tmp3:[a-z0-9]+ :baz="wingozzz">/).should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,7 +5,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'iron',
|
|
5
5
|
RSpec.configure do |config|
|
6
6
|
config.color = true
|
7
7
|
config.add_formatter 'documentation'
|
8
|
-
config.
|
8
|
+
config.backtrace_exclusion_patterns = [/rspec/]
|
9
9
|
end
|
10
10
|
|
11
11
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iron-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Morris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -36,8 +36,10 @@ files:
|
|
36
36
|
- LICENSE
|
37
37
|
- README.rdoc
|
38
38
|
- Version.txt
|
39
|
+
- lib/iron-extensions.rb
|
39
40
|
- lib/iron/extensions.rb
|
40
41
|
- lib/iron/extensions/array.rb
|
42
|
+
- lib/iron/extensions/class.rb
|
41
43
|
- lib/iron/extensions/enumerable.rb
|
42
44
|
- lib/iron/extensions/file.rb
|
43
45
|
- lib/iron/extensions/fixnum.rb
|
@@ -52,6 +54,7 @@ files:
|
|
52
54
|
- lib/iron/extensions/string.rb
|
53
55
|
- lib/iron/extensions/symbol.rb
|
54
56
|
- spec/extensions/array_spec.rb
|
57
|
+
- spec/extensions/class_spec.rb
|
55
58
|
- spec/extensions/enumerable_spec.rb
|
56
59
|
- spec/extensions/kernel_spec.rb
|
57
60
|
- spec/extensions/numeric_spec.rb
|