iron-extensions 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd65118c887a47d1c3eea243f563344f71102730
4
- data.tar.gz: 569fea9ae3ff29abe4c206a5aee390acfae90de1
3
+ metadata.gz: 2e63fc465ef90d238d07d8d8beedf111d0d6917b
4
+ data.tar.gz: dbdaf486d2d8d468628bd15b79e3e1a317b9b9dc
5
5
  SHA512:
6
- metadata.gz: 496bf1300b56b7cc86721a9040079941ad96830ce5be14f36de1e4140ec7f929cde6a169130ba3fbccc52d9de4080ccda55d5cc19a55c4389ff2d348f584eb1b
7
- data.tar.gz: 8ae83a13b739d8a94a17ba4161e91579438890be3c9c9f29687fb539971e7c363215eb334d055c01ed4c5f916eb2b4cf93dacfb42a39b63be54004cf7d38b15f
6
+ metadata.gz: 9e1c8b753c49c5cdaef18ab2600a677a504feadd84e5c2094dc902a7cb00ca73b9f6415e9d898405200cc18c5d5eb2343f0af89edc66f7daad005d3040ee3854
7
+ data.tar.gz: a363a7c732eeb8494ebd812a508f8fc9dd32b223a1acdeca27124a4007e0cf41940b970ecb4b20517e749485a7a305cf2eb40ecc29f7516ec67fac4dccddffad
@@ -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: removed DslProxy/DslBuilder and the dsl_* accessor helpers and moved them into the iron-dsl gem
8
- * BREAKING CHANGE: removed deprecated Array#rand and Array#rand! - use #shuffle instead
9
- * Improved blank? to work on strings containing only whitespace
10
- * Improved documentation & specs a bit
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
- * Added DslBuilder base class for additional DSL-building goodness, is basically a better blank-slate starter class than BasicObject for working with our DslProxy class
37
- * Added dsl_accessor class method as a way to easily create DSL-style accessors
38
- * DslProxy now only copies back instance vars when they change
39
- * Symbol now supports #starts_with? and #ends_with?
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
- * Added DslProxy class and specs, which enables slim and sexy DSL construction
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
- * Updated docs, fixed up minor packaging issues
48
- * Added spec coverage for Kernel extensions
49
- * Added spec coverage for Numeric extensions
50
- * Added spec coverage for Symbol extensions
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
- * Broke out extensions from older irongaze gem
56
- * Vastly improved README with listing of extensions added
57
- * Improved spec coverage
58
- * Integrated several new extensions
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
@@ -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/extensions'
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'
@@ -1 +1 @@
1
- 1.2.1
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
@@ -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.backtrace_clean_patterns = [/rspec/]
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.1
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: 2015-01-28 00:00:00.000000000 Z
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