powerpack 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/lib/powerpack.rb +5 -0
- data/lib/powerpack/hash.rb +1 -0
- data/lib/powerpack/hash/symbolize_keys.rb +9 -0
- data/lib/powerpack/string.rb +3 -0
- data/lib/powerpack/string/format.rb +8 -0
- data/lib/powerpack/string/strip_indent.rb +22 -0
- data/lib/powerpack/string/strip_margin.rb +21 -0
- data/lib/powerpack/version.rb +3 -0
- data/powerpack.gemspec +24 -0
- data/spec/powerpack/hash/symbolize_keys_spec.rb +9 -0
- data/spec/powerpack/string/format_spec.rb +12 -0
- data/spec/powerpack/string/strip_indent_spec.rb +13 -0
- data/spec/powerpack/string/strip_margin_spec.rb +15 -0
- data/spec/spec_helper.rb +17 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f00f072d1cdb57a2f839f9765d9a20febde24d46
|
4
|
+
data.tar.gz: 9b83e641c01d845078ef7c20d0c1471c1ffafc12
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d5eb9328f399bb63be65fa5863744a0641025b0a89d24a3f46a9a1a2d6a7de6895b009502020f04337e58f513628723226760c6a873f95a34340921e52e2ffad
|
7
|
+
data.tar.gz: 5a49681a9f2de6f06eb95f09abb9da48baa10cf31da30af55e79cb49ea3f75d46f8b3b3ee02e25d545fcac2630853240282866349cdae7be52a03954f798a4d2
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Bozhidar Batsov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Powerpack
|
2
|
+
|
3
|
+
Powerpack offers some useful extensions to the standard Ruby classes (kind of like `ActiveSupport`).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'powerpack'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install powerpack
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
To load the entire `powerpack` do:
|
22
|
+
|
23
|
+
```
|
24
|
+
require 'powerpack'
|
25
|
+
```
|
26
|
+
|
27
|
+
To load only the `String` extensions do:
|
28
|
+
|
29
|
+
```
|
30
|
+
require 'powerpack/string'
|
31
|
+
```
|
32
|
+
|
33
|
+
To load only a specific extension like `String#format` do:
|
34
|
+
|
35
|
+
```
|
36
|
+
require 'powerpack/string/format'
|
37
|
+
```
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/powerpack.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'hash/symbolize_keys'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
unless String.method_defined? :strip_indent
|
2
|
+
class String
|
3
|
+
# The method strips the whitespace preceding the base indentation.
|
4
|
+
# Useful for HEREDOCs and other multi-line strings.
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
#
|
8
|
+
# code = <<-END.strip_indent
|
9
|
+
# def test
|
10
|
+
# some_method
|
11
|
+
# other_method
|
12
|
+
# end
|
13
|
+
# END
|
14
|
+
#
|
15
|
+
# => "def\n some_method\n \nother_method\nend"
|
16
|
+
def strip_indent
|
17
|
+
leading_space = scan(/^[ \t]*(?=\S)/).min
|
18
|
+
indent = leading_space ? leading_space.size : 0
|
19
|
+
gsub(/^[ \t]{#{indent}}/, '')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
unless String.method_defined? :strip_margin
|
2
|
+
class String
|
3
|
+
# The method strips the characters preceding a special margin character.
|
4
|
+
# Useful for HEREDOCs and other multi-line strings.
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
#
|
8
|
+
# code = <<-END.strip_margin('|')
|
9
|
+
# |def test
|
10
|
+
# | some_method
|
11
|
+
# | other_method
|
12
|
+
# |end
|
13
|
+
# END
|
14
|
+
#
|
15
|
+
# => "def\n some_method\n \nother_method\nend"
|
16
|
+
def strip_margin(margin_character)
|
17
|
+
margin = '\\' + margin_character
|
18
|
+
gsub(/^\s+#{margin}/, '')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/powerpack.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'powerpack/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'powerpack'
|
8
|
+
spec.version = Powerpack::VERSION
|
9
|
+
spec.authors = ['Bozhidar Batsov']
|
10
|
+
spec.email = ['bozhidar@batsov.com']
|
11
|
+
spec.description = 'A few useful extensions to core Ruby classes.'
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = 'https://github.com/bbatsov/powerpack'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
21
|
+
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_development_dependency('rspec', '~> 2.13')
|
23
|
+
spec.add_development_dependency('yard', '~> 0.8')
|
24
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'String#format' do
|
4
|
+
it 'behaves like String#%' do
|
5
|
+
expect('%s %s'.format %w(James Bond)).to eq('%s %s' % %w(James Bond))
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'behaves like Kernel#sprintf' do
|
9
|
+
expect('%s %s'.format %w(James Bond))
|
10
|
+
.to eq(sprintf('%s %s', 'James', 'Bond'))
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'String#strip_margin' do
|
4
|
+
it 'strips margin on every line of string' do
|
5
|
+
code = <<-END
|
6
|
+
|def test
|
7
|
+
| some_method
|
8
|
+
| other_method
|
9
|
+
|end
|
10
|
+
END
|
11
|
+
|
12
|
+
expect(code.strip_margin('|'))
|
13
|
+
.to eq("def test\n some_method\n other_method\nend\n")
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'rspec'
|
5
|
+
require 'powerpack'
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
|
10
|
+
config.expect_with :rspec do |c|
|
11
|
+
c.syntax = :expect # disables `should`
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Requires supporting files with custom matchers and macros, etc,
|
16
|
+
# in ./support/ and its subdirectories.
|
17
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: powerpack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bozhidar Batsov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-12 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.13'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.13'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.8'
|
69
|
+
description: A few useful extensions to core Ruby classes.
|
70
|
+
email:
|
71
|
+
- bozhidar@batsov.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- .travis.yml
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/powerpack.rb
|
84
|
+
- lib/powerpack/hash.rb
|
85
|
+
- lib/powerpack/hash/symbolize_keys.rb
|
86
|
+
- lib/powerpack/string.rb
|
87
|
+
- lib/powerpack/string/format.rb
|
88
|
+
- lib/powerpack/string/strip_indent.rb
|
89
|
+
- lib/powerpack/string/strip_margin.rb
|
90
|
+
- lib/powerpack/version.rb
|
91
|
+
- powerpack.gemspec
|
92
|
+
- spec/powerpack/hash/symbolize_keys_spec.rb
|
93
|
+
- spec/powerpack/string/format_spec.rb
|
94
|
+
- spec/powerpack/string/strip_indent_spec.rb
|
95
|
+
- spec/powerpack/string/strip_margin_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
homepage: https://github.com/bbatsov/powerpack
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.0.3
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: A few useful extensions to core Ruby classes.
|
121
|
+
test_files:
|
122
|
+
- spec/powerpack/hash/symbolize_keys_spec.rb
|
123
|
+
- spec/powerpack/string/format_spec.rb
|
124
|
+
- spec/powerpack/string/strip_indent_spec.rb
|
125
|
+
- spec/powerpack/string/strip_margin_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
has_rdoc:
|