sc-core-ext 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,30 @@
1
- === 0.0.1 2010-03-18
2
-
3
- * 1 major enhancement:
4
- * Initial release
1
+ === 1.1.1 2010-03-30
2
+
3
+ * Forgot to update the manifest. Whoops.
4
+
5
+ === 1.1.0 2010-03-30
6
+
7
+ * Merged some of my other core extensions:
8
+ * Array#deep_dup
9
+ * Array#%
10
+ * Hash#deep_dup
11
+ * Object#dup?
12
+ * String#parenthesize
13
+ * String#depunctuate
14
+ * String#indent
15
+ * String#hex_to_bin
16
+ * DateTime#to_i / DateTime#to_f
17
+ * https://rails.lighthouseapp.com/projects/8994/tickets/3511-to_yaml-fails-for-datetime-objects
18
+ * Object#attr_boolean
19
+ * ActiveSupport::OrderedHash
20
+ * patched to support #to_yaml, unless patch is already applied
21
+ * Float#to_frac
22
+
23
+ * 2 minor enhancements:
24
+ * Hash and array methods now call self.class.new instead of {} or [], so that their descendants work as expected.
25
+ * Hash#camelize_keys saw some improvement by removing redundant calls to #to_s
26
+
27
+ === 1.0.0 2010-03-18
28
+
29
+ * 1 major enhancement:
30
+ * Initial release
@@ -1,19 +1,29 @@
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
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/active_support/ordered_hash.rb
8
+ lib/sc-core-ext/array.rb
9
+ lib/sc-core-ext/date_time.rb
10
+ lib/sc-core-ext/dependencies.rb
11
+ lib/sc-core-ext/float.rb
12
+ lib/sc-core-ext/hash.rb
13
+ lib/sc-core-ext/object.rb
14
+ lib/sc-core-ext/regexp.rb
15
+ lib/sc-core-ext/string.rb
16
+ script/console
17
+ script/destroy
18
+ script/generate
19
+ spec/rcov.opts
20
+ spec/sc-core-ext/active_support/ordered_hash_spec.rb
21
+ spec/sc-core-ext/array_spec.rb
22
+ spec/sc-core-ext/date_time_spec.rb
23
+ spec/sc-core-ext/float_spec.rb
24
+ spec/sc-core-ext/hash_spec.rb
25
+ spec/sc-core-ext/object_spec.rb
26
+ spec/sc-core-ext/regexp_spec.rb
27
+ spec/sc-core-ext/string_spec.rb
28
+ spec/spec.opts
29
+ spec/spec_helper.rb
@@ -1,7 +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
-
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
+
@@ -1,41 +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
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
41
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -4,10 +4,6 @@ require 'hoe'
4
4
  require 'fileutils'
5
5
  require './lib/sc-core-ext'
6
6
 
7
- def rcov_opts
8
- IO.readlines("spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
9
- end
10
-
11
7
  Hoe.plugin :newgem
12
8
  # Hoe.plugin :website
13
9
  # Hoe.plugin :cucumberfeatures
@@ -28,21 +24,11 @@ Rake::RDocTask.new(:docs) do |rdoc|
28
24
  rdoc.rdoc_files.add(files)
29
25
  rdoc.main = 'README.rdoc'
30
26
  rdoc.title = 'sc-core-ext'
27
+ #rdoc.template = '/path/to/gems/allison-2.0/lib/allison'
31
28
  rdoc.rdoc_dir = 'doc'
32
29
  rdoc.options << '--line-numbers' << '--inline-source'
33
30
  end
34
31
 
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
32
  require 'newgem/tasks'
47
33
  Dir['tasks/**/*.rake'].each { |t| load t }
48
34
 
@@ -1,10 +1,15 @@
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
1
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__))
2
+
3
+ require 'sc-core-ext/dependencies'
4
+ require 'sc-core-ext/object'
5
+ require 'sc-core-ext/hash'
6
+ require 'sc-core-ext/string'
7
+ require 'sc-core-ext/regexp'
8
+ require 'sc-core-ext/array'
9
+ require 'sc-core-ext/date_time'
10
+ require 'sc-core-ext/active_support/ordered_hash'
11
+ require 'sc-core-ext/float'
12
+
13
+ module ScCoreExt
14
+ VERSION = '1.1.1'
15
+ end
@@ -0,0 +1,7 @@
1
+ unless ActiveSupport::OrderedHash.methods.include?("yaml_initialize")
2
+ class ActiveSupport::OrderedHash
3
+ def yaml_initialize(type, val)
4
+ replace(val)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ class Array
2
+ # Performs a "deep copy" of this array; that is, returns an Array that is a duplicate of this Array, and whose
3
+ # elements have each, in turn, had #deep_dup or #dup called on them. This should produce an Array whose every
4
+ # element is a copy of the original.
5
+ #
6
+ # This operation is expensive, and should be used sparingly.
7
+ def deep_dup
8
+ self.collect do |ele|
9
+ ele.respond_to?(:deep_dup) ? ele.deep_dup : ele.dup?
10
+ end
11
+ end
12
+
13
+ # Modulus operator: returns an array consisting only of those elements that are shared by both this array and
14
+ # the arr object. If arr is not an array, then only elements equal to arr itself are returned.
15
+ #
16
+ # Examples:
17
+ # [1, 2, 3] % [1, 2] # => [1, 2]
18
+ # [1, 2, 3] % 2 # => [2]
19
+ #
20
+ def %(arr)
21
+ select { |i| arr.kind_of?(Array) ? arr.include?(i) : arr == i }
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ unless DateTime.methods.include?("seconds_since_unix_epoch")
2
+ # https://rails.lighthouseapp.com/projects/8994/tickets/3511-to_yaml-fails-for-datetime-objects
3
+ class DateTime
4
+ # Converts self to a float number of seconds since the Unix epoch
5
+ def to_f
6
+ seconds_since_unix_epoch.to_f
7
+ end
8
+
9
+ # Converts self to an integer number of seconds since the Unix epoch
10
+ def to_i
11
+ seconds_since_unix_epoch.to_i
12
+ end
13
+
14
+ private
15
+ def seconds_since_unix_epoch
16
+ seconds_per_day = 86_400
17
+ (self - ::DateTime.civil(1970)) * seconds_per_day
18
+ end
19
+ end
20
+ end
@@ -1,6 +1,6 @@
1
- unless defined?(Gem)
2
- require 'rubygems'
3
- gem 'activesupport', '>= 2.3.5'
4
- end
5
-
6
- require 'active_support/core_ext'
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,20 @@
1
+ class Float
2
+ def to_frac
3
+ fraction = case self.abs%1.0
4
+ when 0 : ''
5
+ when 0.25 : '&frac14;'
6
+ when 0.5 : '&frac12;'
7
+ when 0.75 : '&frac34;'
8
+ end
9
+ if fraction
10
+ body = case self.floor
11
+ when -1 : '-'
12
+ when 0 : ''
13
+ else self.to_i.to_s
14
+ end
15
+ body + fraction
16
+ else
17
+ self.to_s
18
+ end
19
+ end
20
+ end
@@ -1,51 +1,66 @@
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
1
+ class Hash
2
+ # Performs a "deep copy" of this hash; that is, returns a Hash that is a duplicate of this Hash, and whose
3
+ # keys and values have each, in turn, had #deep_dup or #dup called on them. This should produce a Hash whose every
4
+ # element is a copy of the original.
5
+ #
6
+ # This operation is expensive, and should be used sparingly.
7
+ def deep_dup
8
+ inject(self.class.new) do |new_hash, (key, value)|
9
+ key = key.respond_to?(:deep_dup) ? key.deep_dup : key.dup?
10
+ value = value.respond_to?(:deep_dup) ? value.deep_dup : value.dup?
11
+ new_hash[key] = value
12
+ new_hash
13
+ end
14
+ end
15
+
16
+ def without(*keys)
17
+ keys.flatten!
18
+ inject(self.class.new) do |hash, (key, value)|
19
+ hash[key] = value unless keys.include?(key)
20
+ hash
21
+ end
22
+ end
23
+
24
+ def without_values(*values)
25
+ values.flatten!
26
+ inject(self.class.new) do |hash, (key, value)|
27
+ hash[key] = value unless values.include?(value)
28
+ hash
29
+ end
30
+ end
31
+
32
+ # Returns a hash that is a copy of this one, except that all nil values have been removed, making them
33
+ # essentially "optional" keys.
34
+ def optionalize
35
+ without_values(nil)
36
+ end
37
+
38
+ alias without_nil_values optionalize
39
+
40
+ def camelize_keys
41
+ stringified = stringify_keys
42
+ stringified.rename(stringified.inject(self.class.new) do |renamed, (key, value)|
43
+ renamed[key] = key.camelize
44
+ renamed
45
+ end)
46
+ end
47
+
48
+ # Takes a hash whose keys must match keys in this hash. Those keys will be renamed to match the
49
+ # corresponding value in the specified hash.
50
+ #
51
+ # Keys not found are ignored.
52
+ #
53
+ # Returns self.
54
+ #
55
+ # Example:
56
+ # { :a => 1 }.rename(:a => :b)
57
+ # => {:b => 1}
58
+ #
59
+ def rename(to)
60
+ merge!(inject(self.class.new) do |hash, (old_key, value)|
61
+ hash[to[old_key] || old_key] = value
62
+ delete(old_key)
63
+ hash
64
+ end)
65
+ end
66
+ end
@@ -0,0 +1,19 @@
1
+ class Object
2
+ # Attempts to call #dup, and returns itself if the object cannot be duped (Symbol, Fixnum, etc.)
3
+ def dup?
4
+ dup rescue self
5
+ end
6
+
7
+ class << self
8
+ # Creates an attribute accessor similar to attr_accessor, except the reader is appended with a question mark.
9
+ # The variable name is the same.
10
+ #
11
+ # Example:
12
+ # attr_boolean :new_record # => { #new_record=(bool), #new_record? }
13
+ #
14
+ def attr_boolean(*a)
15
+ attr_writer *a
16
+ a.each { |i| define_method("#{i}?") { instance_variable_get("@#{i}") } }
17
+ end
18
+ end
19
+ end
@@ -1,14 +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
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
@@ -1,11 +1,44 @@
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
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
+
12
+ def parenthesize(with = "()")
13
+ with[0].chr + self + with[(with.length == 1 ? 0 : 1)].chr
14
+ end
15
+
16
+ # This method assumes that this string represents a Ruby-like method name.
17
+ # Removes question marks and exclamation marks from this string, prepending "is_" or "force_", respectively.
18
+ # If neither of these punctuation marks exist, the original string is returned.
19
+ def depunctuate
20
+ if self[/\?/]
21
+ "is_"+self.gsub(/\?/, '')
22
+ elsif self[/\!/]
23
+ "force_"+self.gsub(/\!/, '')
24
+ else self
25
+ end
26
+ end
27
+
28
+ unless defined?(indent)
29
+ # Returns a copy of itself, except that the first character is preceded by a tabstop (\t) and a tabstop
30
+ # also follows every subsequent newline (\n) character.
31
+ #
32
+ # The unused argument is for compatibility with treetop, a cucumber dependency.
33
+ def indent(unused = 0)
34
+ "\t#{self.gsub(/\n/m, "\n\t")}"
35
+ end
36
+ end
37
+
38
+ def hex_to_bin
39
+ temp = gsub("\s", "");
40
+ ret = []
41
+ (0...temp.length / 2).each { |index| ret[index] = [temp[index*2, 2]].pack("H2") }
42
+ return ret.join
43
+ end
44
+ end
@@ -1,10 +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"
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
10
  exec "#{irb} #{libs} --simple-prompt"
@@ -1,14 +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)
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)
@@ -1,14 +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)
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)
@@ -1,2 +1,2 @@
1
- --exclude "spec/*,gems/*"
2
- --aggregate coverage.data
1
+ --exclude "spec/*,gems/*"
2
+ --aggregate coverage.data
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveSupport::OrderedHash do
4
+ context "#to_yaml" do
5
+ subject do
6
+ o = ActiveSupport::OrderedHash.new
7
+ o[:one] = 1
8
+ o[:two] = 2
9
+ o
10
+ end
11
+
12
+ it "converts to yaml" do
13
+ subject.to_yaml.should == "--- !map:ActiveSupport::OrderedHash \n:one: 1\n:two: 2\n"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Array do
4
+ subject { [ 1, 2, "abc", "def", ["foo", "bar"], { 'baz' => '42' } ] }
5
+
6
+ context "#%" do
7
+ context "with another array" do
8
+ it "results in an array intersection" do
9
+ (subject % [1,2]).should == [1,2]
10
+ end
11
+ end
12
+
13
+ context "with a non-array value" do
14
+ it "results in elements equal to only that value" do
15
+ (subject % 2).should == [2]
16
+ end
17
+ end
18
+ end
19
+
20
+ context "#deep_dup" do
21
+ it "is not itself" do
22
+ subject.deep_dup.should_not equal(subject)
23
+ end
24
+
25
+ it "elements are not themselves" do
26
+ subject.deep_dup.each_with_index do |ele, index|
27
+ subject[index].should_not equal(ele) unless ele.dup?.equal?(ele)
28
+ end
29
+ end
30
+
31
+ it "hashes' keys are not themselves" do
32
+ hash = subject.deep_dup.last
33
+ hash.keys[0].should_not equal(subject.last.keys[0])
34
+ end
35
+
36
+ it "hashes' values are not themselves" do
37
+ hash = subject.deep_dup.last
38
+ hash.values[0].should_not equal(subject.last.values[0])
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe DateTime do
4
+ context "#to_i" do
5
+ it "works" do
6
+ DateTime.civil(2000).to_i.should == 946684800
7
+ end
8
+ end
9
+
10
+ context "#to_f" do
11
+ it "works" do
12
+ DateTime.civil(1999,12,31,19,0,0,Rational(-5,24)).to_f.should == 946684800.0
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ describe Float do
2
+ context "#to_frac" do
3
+ context "1.0" do
4
+ subject { 1.0 }
5
+ it("== 1") { subject.to_frac.should == "1" }
6
+ end
7
+
8
+ context "1.25" do
9
+ subject { 1.25 }
10
+ it("== 1 1/4") { subject.to_frac.should == "1&frac14;" }
11
+ end
12
+
13
+ context "1.5" do
14
+ subject { 1.5 }
15
+ it("== 1 1/2") { subject.to_frac.should == "1&frac12;" }
16
+ end
17
+
18
+ context "1.75" do
19
+ subject { 1.75 }
20
+ it("== 1 3/4") { subject.to_frac.should == "1&frac34;" }
21
+ end
22
+
23
+ context "1.88" do
24
+ subject { 1.88 }
25
+ it("== 1.88") { subject.to_frac.should == '1.88' }
26
+ end
27
+ end
28
+ end
@@ -1,23 +1,39 @@
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
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
+
24
+ context "#deep_dup" do
25
+ subject { { 'baz' => '42' } }
26
+
27
+ it "is not itself" do
28
+ subject.deep_dup.should_not equal(subject)
29
+ end
30
+
31
+ it "keys are not themselves" do
32
+ subject.deep_dup.keys[0].should_not equal(subject.keys[0])
33
+ end
34
+
35
+ it "values are not themselves" do
36
+ subject.deep_dup.values[0].should_not equal(subject.values[0])
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Object do
4
+ context "#attr_boolean" do
5
+ subject do
6
+ obj = Object.new
7
+ klass = (class << obj; self; end)
8
+ klass.send(:attr_boolean, :new_record)
9
+ obj
10
+ end
11
+
12
+ it("responds_to? accessor?") { subject.should respond_to(:new_record?) }
13
+ it("responds_to? accessor=") { subject.should respond_to(:new_record=) }
14
+ end
15
+
16
+ context "#dup?" do
17
+ context "with an undupable object" do
18
+ subject { nil }
19
+ it("returns itself") { subject.dup?.should be_equal(nil) }
20
+ end
21
+
22
+ context "with a dupable object" do
23
+ subject { "hello" }
24
+ it("does not return itself") { subject.dup?.should_not be_equal(subject) }
25
+ it("== itself") { subject.dup?.should == subject }
26
+ end
27
+ end
28
+ end
@@ -1,17 +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
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
@@ -1,8 +1,56 @@
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
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
+
9
+ context "#hex_to_bin" do
10
+ subject { "61 62 63" }
11
+
12
+ it "converts hex to binary" do
13
+ subject.hex_to_bin.should == "abc"
14
+ end
15
+ end
16
+
17
+ context "#indent" do
18
+ subject { "hello\nworld".indent }
19
+
20
+ it "indents the first character" do
21
+ subject[0].should == ?\t
22
+ end
23
+
24
+ it "indents after newline characters" do
25
+ subject[subject.index(?\n) + 1].should == ?\t
26
+ end
27
+ end
28
+
29
+ context "#parenthesize" do
30
+ it "parenthesizes with one character" do
31
+ 'text'.parenthesize(':').should == ":text:"
32
+ end
33
+
34
+ it "parenthesizes with two characters" do
35
+ 'text'.parenthesize('[]').should == "[text]"
36
+ end
37
+
38
+ it "parenthesizes with defaults" do
39
+ "text".parenthesize.should == "(text)"
40
+ end
41
+ end
42
+
43
+ context "#depunctuate" do
44
+ it "does not include question marks" do
45
+ "kind_of?".depunctuate.should == "is_kind_of"
46
+ end
47
+
48
+ it "does not include exclamation points" do
49
+ "save!".depunctuate.should == "force_save"
50
+ end
51
+
52
+ it "returns itself if no punctuation is found" do
53
+ "save".depunctuate.should == "save"
54
+ end
55
+ end
56
+ end
@@ -1,4 +1,4 @@
1
- --colour
2
- --format progress
3
- --loadby mtime
4
- --reverse
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 0
8
- - 0
9
- version: 1.0.0
7
+ - 1
8
+ - 1
9
+ version: 1.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Colin MacKenzie IV
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-18 00:00:00 -04:00
17
+ date: 2010-03-30 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -68,9 +68,9 @@ dependencies:
68
68
  - !ruby/object:Gem::Version
69
69
  segments:
70
70
  - 2
71
- - 5
71
+ - 4
72
72
  - 0
73
- version: 2.5.0
73
+ version: 2.4.0
74
74
  type: :development
75
75
  version_requirements: *id004
76
76
  description: A collection of core extensions that I have come to rely on in more than one package
@@ -91,21 +91,31 @@ files:
91
91
  - README.rdoc
92
92
  - Rakefile
93
93
  - lib/sc-core-ext.rb
94
+ - lib/sc-core-ext/active_support/ordered_hash.rb
95
+ - lib/sc-core-ext/array.rb
96
+ - lib/sc-core-ext/date_time.rb
94
97
  - lib/sc-core-ext/dependencies.rb
98
+ - lib/sc-core-ext/float.rb
95
99
  - lib/sc-core-ext/hash.rb
100
+ - lib/sc-core-ext/object.rb
96
101
  - lib/sc-core-ext/regexp.rb
97
102
  - lib/sc-core-ext/string.rb
98
103
  - script/console
99
104
  - script/destroy
100
105
  - script/generate
101
106
  - spec/rcov.opts
107
+ - spec/sc-core-ext/active_support/ordered_hash_spec.rb
108
+ - spec/sc-core-ext/array_spec.rb
109
+ - spec/sc-core-ext/date_time_spec.rb
110
+ - spec/sc-core-ext/float_spec.rb
102
111
  - spec/sc-core-ext/hash_spec.rb
112
+ - spec/sc-core-ext/object_spec.rb
103
113
  - spec/sc-core-ext/regexp_spec.rb
104
114
  - spec/sc-core-ext/string_spec.rb
105
115
  - spec/spec.opts
106
116
  - spec/spec_helper.rb
107
117
  has_rdoc: true
108
- homepage: http://github.com/sinisterchipmunk/core-ext
118
+ homepage: http://github.com/sinisterchipmunk/core-ext
109
119
  licenses: []
110
120
 
111
121
  post_install_message: