powerpack 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - jruby-19mode
6
+ - rbx-19mode
7
+ script: bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in powerpack.gemspec
4
+ gemspec
@@ -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.
@@ -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
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ require 'powerpack/version'
2
+
3
+ require 'powerpack/hash'
4
+
5
+ require 'powerpack/string'
@@ -0,0 +1 @@
1
+ require_relative 'hash/symbolize_keys'
@@ -0,0 +1,9 @@
1
+ unless Hash.method_defined? :symbolize_keys
2
+ class Hash
3
+ # The method behaves like turns the keys of the hash to symbols.
4
+ # It returns a copy of the original hash.
5
+ def symbolize_keys
6
+ Hash[map { |(k, v)| [k.to_sym, v] }]
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'string/format'
2
+ require_relative 'string/strip_indent'
3
+ require_relative 'string/strip_margin'
@@ -0,0 +1,8 @@
1
+ unless String.method_defined? :format
2
+ class String
3
+ # The method behaves like `Kernel#sprintf` and `String#%`.
4
+ def format(*args)
5
+ super(self, *(args.flatten(1)))
6
+ end
7
+ end
8
+ end
@@ -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
@@ -0,0 +1,3 @@
1
+ module Powerpack
2
+ VERSION = '0.0.1'
3
+ end
@@ -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,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Hash#symbolize_keys' do
4
+ it 'turn the hash keys into symbols' do
5
+ hash = { 'one' => 1, 'two' => 2 }
6
+
7
+ expect(hash.symbolize_keys).to eq({ one: 1, two: 2 })
8
+ end
9
+ 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,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'String#strip_indent' do
4
+ it 'strips leading indent on every line of string' do
5
+ test = <<-END
6
+ test
7
+ test
8
+ test
9
+ END
10
+
11
+ expect(test.strip_indent).to eq("test\n test\n test\n")
12
+ end
13
+ 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
@@ -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: