ragabash 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f525237ed9e30ba2686a2d1ee51f33105d4160af
4
- data.tar.gz: 92961fbbd0a3934233c1fcfbd21cc2e4e9ce5414
3
+ metadata.gz: 37191f18ef1617949bfb78247a0ff61d6d28d767
4
+ data.tar.gz: 353ffee2ebe359a2f08a7ae86dfab9a04b0265d8
5
5
  SHA512:
6
- metadata.gz: f2e1493d650a7fccfca4a4c7a2c50b36e6d3127f8126a3b5c9da3650a941e24c787a9aaa6c8c566ad38d8f3e69f3fc1cd1c22c8b972c9ef6b63350f2b9931606
7
- data.tar.gz: f93225111a737a5fe8a50c436c93931a5149ddbd80db3644b2a08c06d9324c9bbca7b8e1683eb4c42f42fff8d34ea4b4e2c9bd0a29cbfa1c3258613eebb14fd7
6
+ metadata.gz: 0cf6d17680f55cc37c7689f4a7bab500a6d1a0c5840b130f8e99325cc951f2df229f60ce741cd4eba157cb32b8347976733106964a9e6b5fcfbaa04ec7eabc79
7
+ data.tar.gz: ead865fc572a59b48a37944e24d187aeb7dff5ece4a8144957b70fc367d776a67b473a3cf021623d3f48ce8e2516e1008eaa685e484fb5ef3f22142e42ced089
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # Ragabash
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/ragabash.svg)](https://badge.fury.io/rb/ragabash)
4
+ [![Dependency Status](https://gemnasium.com/badges/github.com/nomoon/ragabash.svg)](https://gemnasium.com/github.com/nomoon/ragabash)
3
5
  [![Build Status](https://travis-ci.org/nomoon/ragabash.svg?branch=master)](https://travis-ci.org/nomoon/ragabash)
4
- [![Code Climate](https://codeclimate.com/github/nomoon/ragabash/badges/gpa.svg)](https://codeclimate.com/github/nomoon/ragabash)
5
6
  [![Test Coverage](https://codeclimate.com/github/nomoon/ragabash/badges/coverage.svg)](https://codeclimate.com/github/nomoon/ragabash/coverage)
6
- [![Dependency Status](https://gemnasium.com/badges/github.com/nomoon/ragabash.svg)](https://gemnasium.com/github.com/nomoon/ragabash)
7
+ [![Code Climate](https://codeclimate.com/github/nomoon/ragabash/badges/gpa.svg)](https://codeclimate.com/github/nomoon/ragabash)
8
+ [![Inline docs](http://inch-ci.org/github/nomoon/ragabash.svg?branch=master)](http://inch-ci.org/github/nomoon/ragabash)
7
9
 
8
10
  "A collection of useful extensions, refinements, and tools."
9
11
 
data/lib/ragabash.rb CHANGED
@@ -3,6 +3,6 @@ require "ragabash/version"
3
3
  require "ragabash/refinements"
4
4
  require "ragabash/awesome_string_formatter"
5
5
 
6
+ # A utility module full of useful things.
6
7
  module Ragabash
7
- # Your code goes here...
8
8
  end
@@ -2,12 +2,26 @@
2
2
  require "rouge"
3
3
 
4
4
  module Ragabash
5
+ # Custom String formatter module for +awesome_print+ gem.
6
+ #
7
+ # You can activate this automatically by including:
8
+ # require "ragabash/ext/awesome_strings"
9
+ # You can also activate this as part of an awesome_print-based Pry printer by including:
10
+ # require "ragabash/ext/pry_awesome_print"
5
11
  module AwesomeStringFormatter
6
- def self.included(base)
7
- base.send :alias_method, :cast_without_string, :cast
8
- base.send :alias_method, :cast, :cast_with_string
12
+ class << self
13
+ # Intercept awesome_print type-cast method.
14
+ def included(base)
15
+ base.send :alias_method, :cast_without_string, :cast
16
+ base.send :alias_method, :cast, :cast_with_string
17
+ end
9
18
  end
10
19
 
20
+ # Replacement type-cast method for awesome_print.
21
+ #
22
+ # @param object [Object] the object to test
23
+ # @param type [Any] the type to test against
24
+ # @return [Boolean]
11
25
  def cast_with_string(object, type)
12
26
  object.is_a?(::String) ? :string : cast_without_string(object, type)
13
27
  end
@@ -22,6 +36,10 @@ module Ragabash
22
36
  R_LEXERS = ::Rouge::Lexer.all
23
37
  private_constant :MULTILINE_UNESCAPES, :R_FORMATTER, :R_LEXERS
24
38
 
39
+ # Format a String for awesome_print display.
40
+ #
41
+ # @param string [String] the String to format
42
+ # @return [String] the formatted String
25
43
  def awesome_string(string)
26
44
  lexers = ::Rouge::Guessers::Source.new(string).filter(R_LEXERS)
27
45
  if !lexers.empty?
@@ -2,8 +2,47 @@
2
2
  require "ice_nine"
3
3
 
4
4
  module Ragabash
5
+ # A set of useful refinements for base classes.
6
+ #
7
+ # Activate these by including the following in an appropriate lexical scope:
8
+ # using ::Ragabash::Refinements
5
9
  module Refinements
6
10
  # rubocop:disable Style/Alias
11
+
12
+ # @!method deep_freeze
13
+ # Deep-freezes +self+.
14
+ #
15
+ # Refines: +::Object+
16
+ # @see http://www.rubydoc.info/gems/ice_nine/IceNine#deep_freeze-class_method
17
+
18
+ # @!method deep_freeze!
19
+ # Deep-freezes +self+, but skips already-frozen objects.
20
+ #
21
+ # Refines: +::Object+
22
+ # @see http://www.rubydoc.info/gems/ice_nine/IceNine#deep_freeze%21-class_method
23
+
24
+ # @!method try_dup
25
+ # Attempts to duplicate +self+, or returns +self+ on non-duplicable objects.
26
+ #
27
+ # Refines: +::Object+, +::NilClass+, +::FalseClass+, +::TrueClass+, +::Symbol+,
28
+ # +::Numeric+, +::BigDecimal+
29
+
30
+ # @!method deep_dup
31
+ # Recursively duplicates +self+, including non-duplicable objects where necessary.
32
+ #
33
+ # Refines: +::Object+, +::NilClass+, +::FalseClass+, +::TrueClass+, +::Symbol+,
34
+ # +::Numeric+, +::BigDecimal+, +::Array+, +::Hash+, +::Set+
35
+
36
+ # @!method safe_copy
37
+ # Returns +self+ if frozen or otherwise a frozen deep-duplicate.
38
+ #
39
+ # Refines: +::Object+, +::NilClass+, +::FalseClass+, +::TrueClass+, +::Symbol+,
40
+ # +::Numeric+, +::BigDecimal+, +::Array+, +::Hash+, +::Set+
41
+
42
+ # @!method frozen_copy
43
+ # Alias of {safe_copy}.
44
+
45
+ #
7
46
  refine ::Object do
8
47
  def deep_freeze
9
48
  IceNine.deep_freeze(self)
@@ -19,7 +58,11 @@ module Ragabash
19
58
  self
20
59
  end
21
60
  alias deep_dup try_dup
22
- alias safe_copy try_dup
61
+
62
+ def safe_copy
63
+ IceNine.deep_freeze(try_dup)
64
+ end
65
+ alias frozen_copy safe_copy
23
66
  end
24
67
 
25
68
  refine ::NilClass do
@@ -28,6 +71,7 @@ module Ragabash
28
71
  end
29
72
  alias deep_dup try_dup
30
73
  alias safe_copy try_dup
74
+ alias frozen_copy try_dup
31
75
  end
32
76
 
33
77
  refine ::FalseClass do
@@ -36,6 +80,7 @@ module Ragabash
36
80
  end
37
81
  alias deep_dup try_dup
38
82
  alias safe_copy try_dup
83
+ alias frozen_copy try_dup
39
84
  end
40
85
 
41
86
  refine ::TrueClass do
@@ -44,6 +89,7 @@ module Ragabash
44
89
  end
45
90
  alias deep_dup try_dup
46
91
  alias safe_copy try_dup
92
+ alias frozen_copy try_dup
47
93
  end
48
94
 
49
95
  refine ::Symbol do
@@ -52,6 +98,7 @@ module Ragabash
52
98
  end
53
99
  alias deep_dup try_dup
54
100
  alias safe_copy try_dup
101
+ alias frozen_copy try_dup
55
102
  end
56
103
 
57
104
  refine ::Numeric do
@@ -60,6 +107,7 @@ module Ragabash
60
107
  end
61
108
  alias deep_dup try_dup
62
109
  alias safe_copy try_dup
110
+ alias frozen_copy try_dup
63
111
  end
64
112
 
65
113
  # Necessary to re-override Numeric
@@ -71,20 +119,27 @@ module Ragabash
71
119
  alias deep_dup try_dup
72
120
 
73
121
  def safe_copy
74
- frozen? ? self : dup
122
+ frozen? ? self : dup.freeze
75
123
  end
124
+ alias frozen_copy safe_copy
76
125
  end
77
126
 
78
127
  refine ::String do
79
128
  def safe_copy
80
- frozen? ? self : dup
129
+ frozen? ? self : dup.freeze
81
130
  end
131
+ alias frozen_copy safe_copy
82
132
  end
83
133
 
84
134
  refine ::Array do
85
135
  def deep_dup
86
136
  map { |value| value.deep_dup } # rubocop:disable Style/SymbolProc
87
137
  end
138
+
139
+ def safe_copy
140
+ frozen? ? self : deep_dup.deep_freeze
141
+ end
142
+ alias frozen_copy safe_copy
88
143
  end
89
144
 
90
145
  refine ::Hash do
@@ -100,6 +155,11 @@ module Ragabash
100
155
  end
101
156
  hash
102
157
  end
158
+
159
+ def safe_copy
160
+ frozen? ? self : deep_dup.deep_freeze
161
+ end
162
+ alias frozen_copy safe_copy
103
163
  end
104
164
 
105
165
  refine ::Set do
@@ -111,6 +171,11 @@ module Ragabash
111
171
  end
112
172
  self.class[set_a]
113
173
  end
174
+
175
+ def safe_copy
176
+ frozen? ? self : deep_dup.deep_freeze
177
+ end
178
+ alias frozen_copy safe_copy
114
179
  end
115
180
  end
116
181
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Ragabash
3
- VERSION = "0.1.0"
3
+ # The version number.
4
+ VERSION = "0.2.0"
4
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ragabash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Bellefleur
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-23 00:00:00.000000000 Z
11
+ date: 2016-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler