sc-core-ext 1.0.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.
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2010-03-18
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,19 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/sc-core-ext.rb
7
+ lib/sc-core-ext/dependencies.rb
8
+ lib/sc-core-ext/hash.rb
9
+ lib/sc-core-ext/regexp.rb
10
+ lib/sc-core-ext/string.rb
11
+ script/console
12
+ script/destroy
13
+ script/generate
14
+ spec/rcov.opts
15
+ spec/sc-core-ext/hash_spec.rb
16
+ spec/sc-core-ext/regexp_spec.rb
17
+ spec/sc-core-ext/string_spec.rb
18
+ spec/spec.opts
19
+ spec/spec_helper.rb
@@ -0,0 +1,7 @@
1
+
2
+ For more information on sc-core-ext, see http://sc-core-ext.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
@@ -0,0 +1,41 @@
1
+ = sc-core-ext
2
+
3
+ * http://github.com/sinisterchipmunk/core-ext
4
+
5
+ == DESCRIPTION:
6
+
7
+ A collection of core extensions for Ruby that I've built up over time. Most of my projects will probably end up
8
+ requiring this as a dependency.
9
+
10
+ == REQUIREMENTS:
11
+
12
+ * ActiveSupport 2.3.5+
13
+
14
+ == INSTALL:
15
+
16
+ * sudo gem install sc-core-ext
17
+
18
+ == LICENSE:
19
+
20
+ (The MIT License)
21
+
22
+ Copyright (c) 2010 FIXME Colin MacKenzie IV
23
+
24
+ Permission is hereby granted, free of charge, to any person obtaining
25
+ a copy of this software and associated documentation files (the
26
+ 'Software'), to deal in the Software without restriction, including
27
+ without limitation the rights to use, copy, modify, merge, publish,
28
+ distribute, sublicense, and/or sell copies of the Software, and to
29
+ permit persons to whom the Software is furnished to do so, subject to
30
+ the following conditions:
31
+
32
+ The above copyright notice and this permission notice shall be
33
+ included in all copies or substantial portions of the Software.
34
+
35
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
36
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
38
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
39
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
40
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
41
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/sc-core-ext'
6
+
7
+ def rcov_opts
8
+ IO.readlines("spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
9
+ end
10
+
11
+ Hoe.plugin :newgem
12
+ # Hoe.plugin :website
13
+ # Hoe.plugin :cucumberfeatures
14
+
15
+ # Generate all the Rake tasks
16
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
17
+ $hoe = Hoe.spec 'sc-core-ext' do
18
+ self.developer 'Colin MacKenzie IV', 'sinisterchipmunk@gmail.com'
19
+ self.description = "A collection of core extensions that I have come to rely on in more than one package"
20
+ self.readme_file = 'README.rdoc'
21
+ self.extra_deps = [['activesupport','>= 2.3.5']]
22
+ self.extra_dev_deps = [['rspec','>=1.3.0'],['rcov','>=0.9.8']]
23
+ end
24
+
25
+ Rake::RDocTask.new(:docs) do |rdoc|
26
+ files = ['README.rdoc', # 'LICENSE', 'CHANGELOG',
27
+ 'lib/**/*.rb', 'doc/**/*.rdoc']#, 'spec/*.rb']
28
+ rdoc.rdoc_files.add(files)
29
+ rdoc.main = 'README.rdoc'
30
+ rdoc.title = 'sc-core-ext'
31
+ rdoc.rdoc_dir = 'doc'
32
+ rdoc.options << '--line-numbers' << '--inline-source'
33
+ end
34
+
35
+ namespace :spec do
36
+ desc "Run all specs with rcov"
37
+ Spec::Rake::SpecTask.new(:rcov) do |t|
38
+ t.spec_files = FileList['spec/**/*_spec.rb']
39
+ t.spec_opts = ['--options', 'spec/spec.opts']
40
+ t.rcov = true
41
+ t.rcov_dir = 'coverage'
42
+ t.rcov_opts = rcov_opts
43
+ end
44
+ end
45
+
46
+ require 'newgem/tasks'
47
+ Dir['tasks/**/*.rake'].each { |t| load t }
48
+
49
+ remove_task :default
50
+ task :default => :spec
@@ -0,0 +1,10 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__))
2
+
3
+ require 'sc-core-ext/dependencies'
4
+ require 'sc-core-ext/hash'
5
+ require 'sc-core-ext/string'
6
+ require 'sc-core-ext/regexp'
7
+
8
+ module ScCoreExt
9
+ VERSION = '1.0.0'
10
+ end
@@ -0,0 +1,6 @@
1
+ unless defined?(Gem)
2
+ require 'rubygems'
3
+ gem 'activesupport', '>= 2.3.5'
4
+ end
5
+
6
+ require 'active_support/core_ext'
@@ -0,0 +1,51 @@
1
+ class Hash
2
+ def without(*keys)
3
+ keys.flatten!
4
+ inject({}) do |hash, (key, value)|
5
+ hash[key] = value unless keys.include?(key)
6
+ hash
7
+ end
8
+ end
9
+
10
+ def without_values(*values)
11
+ values.flatten!
12
+ inject({}) do |hash, (key, value)|
13
+ hash[key] = value unless values.include?(value)
14
+ hash
15
+ end
16
+ end
17
+
18
+ # Returns a hash that is a copy of this one, except that all nil values have been removed, making them
19
+ # essentially "optional" keys.
20
+ def optionalize
21
+ without_values(nil)
22
+ end
23
+
24
+ alias without_nil_values optionalize
25
+
26
+ def camelize_keys
27
+ stringify_keys.rename(inject({}) do |renamed, (key, value)|
28
+ renamed[key.to_s] = key.to_s.camelize
29
+ renamed
30
+ end)
31
+ end
32
+
33
+ # Takes a hash whose keys must match keys in this hash. Those keys will be renamed to match the
34
+ # corresponding value in the specified hash.
35
+ #
36
+ # Keys not found are ignored.
37
+ #
38
+ # Returns self.
39
+ #
40
+ # Example:
41
+ # { :a => 1 }.rename(:a => :b)
42
+ # => {:b => 1}
43
+ #
44
+ def rename(to)
45
+ merge!(inject({}) do |hash, (old_key, value)|
46
+ hash[to[old_key] || old_key] = value
47
+ delete(old_key)
48
+ hash
49
+ end)
50
+ end
51
+ end
@@ -0,0 +1,14 @@
1
+ class Regexp
2
+ # Searches the target for all occurrances of this Regex. If a block is given, yields each match found.
3
+ # Returns an array of all matches found.
4
+ def each_match(target)
5
+ matches = []
6
+ offset = 0
7
+ while offset < target.length && !(match = match(target[offset..-1])).nil?
8
+ offset += match.offset(0)[1]
9
+ yield match if block_given?
10
+ matches << match
11
+ end
12
+ matches
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ class String
2
+ # The inverse of +ActiveSupport::Inflection#humanize+: Lowercases the first letter, and turns spaces into underscores.
3
+ # This is meant to assist in creating method names. A camelCase method name can be created using #dehumanize:
4
+ # "say_hello_to_the_world".camelize.dehumanize # => "sayHelloToTheWorld"
5
+ #
6
+ # This can also be used for creating permalinks:
7
+ # "Say hello to the world".dehumanize # => "say_hello_to_the_world"
8
+ def dehumanize
9
+ self.camelize.gsub(/^([A-Z])/) { |x| x.downcase }.gsub(/ /, '_')
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/sc-core-ext.rb'}"
9
+ puts "Loading sc-core-ext gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,2 @@
1
+ --exclude "spec/*,gems/*"
2
+ --aggregate coverage.data
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hash do
4
+ it "#without" do
5
+ { :a => 1, :b => 2, :c => 3 }.without(:a, :b).should == {:c => 3}
6
+ end
7
+
8
+ it "#without_values" do
9
+ { :a => 1, :b => 1, :c => 2, :d => 2}.without_values(1).should == {:c => 2, :d => 2}
10
+ end
11
+
12
+ it "#optionalize" do
13
+ { :a => nil, :b => nil, :c => 1, :d => 2 }.optionalize.should == { :c => 1, :d => 2}
14
+ end
15
+
16
+ it "#camelize_keys" do
17
+ { :hello_world => 1, :goodbye_john => 2}.camelize_keys.should == { 'HelloWorld' => 1, 'GoodbyeJohn' => 2 }
18
+ end
19
+
20
+ it "#rename" do
21
+ { :a => 1, :b => 2 }.rename(:a => :b, :b => :c).should == { :b => 1, :c => 2 }
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Regexp do
4
+ before(:each) { @demo_text = "123abc\n asdf0987 \na1234"}
5
+
6
+ it "should yield all matches in a multiline regexp" do
7
+ @rx = /([0-9]+)/m
8
+ yielded = 0
9
+ @rx.each_match(@demo_text) { |y| yielded += 1 }
10
+ yielded.should == 3
11
+ end
12
+
13
+ it "should return all matches in a multiline regexp" do
14
+ @rx = /([0-9]+)/m
15
+ @rx.each_match(@demo_text).collect { |m| m[0] }.should == %w(123 0987 1234)
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe String do
4
+ it "#dehumanize" do
5
+ "say_hello_to_the_world".camelize.dehumanize.should == "sayHelloToTheWorld"
6
+ "Say hello to the world".dehumanize.should == "say_hello_to_the_world"
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1 @@
1
+ require 'lib/sc-core-ext'
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sc-core-ext
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Colin MacKenzie IV
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-18 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activesupport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 3
30
+ - 5
31
+ version: 2.3.5
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 3
44
+ - 0
45
+ version: 1.3.0
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: rcov
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ - 9
58
+ - 8
59
+ version: 0.9.8
60
+ type: :development
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: hoe
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 2
71
+ - 5
72
+ - 0
73
+ version: 2.5.0
74
+ type: :development
75
+ version_requirements: *id004
76
+ description: A collection of core extensions that I have come to rely on in more than one package
77
+ email:
78
+ - sinisterchipmunk@gmail.com
79
+ executables: []
80
+
81
+ extensions: []
82
+
83
+ extra_rdoc_files:
84
+ - History.txt
85
+ - Manifest.txt
86
+ - PostInstall.txt
87
+ files:
88
+ - History.txt
89
+ - Manifest.txt
90
+ - PostInstall.txt
91
+ - README.rdoc
92
+ - Rakefile
93
+ - lib/sc-core-ext.rb
94
+ - lib/sc-core-ext/dependencies.rb
95
+ - lib/sc-core-ext/hash.rb
96
+ - lib/sc-core-ext/regexp.rb
97
+ - lib/sc-core-ext/string.rb
98
+ - script/console
99
+ - script/destroy
100
+ - script/generate
101
+ - spec/rcov.opts
102
+ - spec/sc-core-ext/hash_spec.rb
103
+ - spec/sc-core-ext/regexp_spec.rb
104
+ - spec/sc-core-ext/string_spec.rb
105
+ - spec/spec.opts
106
+ - spec/spec_helper.rb
107
+ has_rdoc: true
108
+ homepage: http://github.com/sinisterchipmunk/core-ext
109
+ licenses: []
110
+
111
+ post_install_message:
112
+ rdoc_options:
113
+ - --main
114
+ - README.rdoc
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ requirements: []
132
+
133
+ rubyforge_project: sc-core-ext
134
+ rubygems_version: 1.3.6
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: A collection of core extensions for Ruby that I've built up over time
138
+ test_files: []
139
+