Module: DataMapper::Support::String
- Included in:
- String
- Defined in:
- lib/data_mapper/support/string.rb
Class Method Summary collapse
-
.included(base) ⇒ Object
I set the constant on the String itself to avoid inheritance chain lookups.
Instance Method Summary collapse
-
#compress_lines ⇒ Object
Matches any whitespace (including newline) and replaces with a single space EXAMPLE: <<QUERY.compress_lines SELECT name FROM users QUERY => “SELECT name FROM users”.
- #ensure_ends_with(part) ⇒ Object
- #ensure_starts_with(part) ⇒ Object
- #ensure_wrapped_with(a, b = nil) ⇒ Object
Class Method Details
.included(base) ⇒ Object
I set the constant on the String itself to avoid inheritance chain lookups.
6 7 8 |
# File 'lib/data_mapper/support/string.rb', line 6 def self.included(base) base.const_set('EMPTY', ''.freeze) end |
Instance Method Details
#compress_lines ⇒ Object
Matches any whitespace (including newline) and replaces with a single space EXAMPLE:
<<QUERY.compress_lines
SELECT name
FROM users
QUERY
=> "SELECT name FROM users"
29 30 31 |
# File 'lib/data_mapper/support/string.rb', line 29 def compress_lines gsub(/\s+/, ' ').strip end |
#ensure_ends_with(part) ⇒ Object
14 15 16 |
# File 'lib/data_mapper/support/string.rb', line 14 def ensure_ends_with(part) [-1,1] == part ? self : (self + part) end |
#ensure_starts_with(part) ⇒ Object
10 11 12 |
# File 'lib/data_mapper/support/string.rb', line 10 def ensure_starts_with(part) [0,1] == part ? self : (part + self) end |
#ensure_wrapped_with(a, b = nil) ⇒ Object
18 19 20 |
# File 'lib/data_mapper/support/string.rb', line 18 def ensure_wrapped_with(a, b = nil) ensure_starts_with(a).ensure_ends_with(b || a) end |