ss-se_gem 0.0.3 → 0.0.4

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ *.sw?
3
+ .DS_Store
4
+ coverage
5
+ rdoc
6
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Scott Steadman
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = se_gem
2
+
3
+ A collection of handy scripts.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Scott Steadman. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = 'se_gem'
8
+ gem.summary = 'A collection of handy scripts.'
9
+ gem.email = 'ss@stdmn.com'
10
+ gem.homepage = 'http://github.com/ss/se_gem'
11
+ gem.authors = ['Scott Steadman']
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts 'Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler'
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort 'RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov'
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ''
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "se_gem #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.4
data/lib/core_ext.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'lib/se/core_ext/meta_class'
2
+ require 'lib/se/core_ext/object'
data/lib/debug.rb ADDED
@@ -0,0 +1 @@
1
+ require 'lib/se/debug/debug'
@@ -0,0 +1,29 @@
1
+ #
2
+ # Array class extensions.
3
+ #
4
+ module SE
5
+ module CoreExtensions
6
+ module Array
7
+
8
+ module InstanceMethods
9
+
10
+ # exclude values from an each call
11
+ def each_except(*values)
12
+ values = [values].flatten
13
+ each do |ii|
14
+ yield ii unless values.include?(ii)
15
+ end
16
+ end
17
+
18
+ end # module InstanceMethods
19
+
20
+ module ClassMethods
21
+
22
+ end # module ClassMethods
23
+
24
+ end # module Array
25
+ end # module CoreExtensions
26
+ end # module SE
27
+
28
+ Array.send(:include, SE::CoreExtensions::Array::InstanceMethods)
29
+ #Array.send(:extend, SE::CoreExtensions::Array::ClassMethods)
@@ -0,0 +1,50 @@
1
+ #
2
+ # Dir class extensions.
3
+ #
4
+ module SE
5
+ module CoreExtensions
6
+ module Dir
7
+
8
+ module InstanceMethods
9
+
10
+ end # module InstanceMethods
11
+
12
+ module ClassMethods
13
+
14
+ # Return a directory as a hash.
15
+ #
16
+ # Example:
17
+ # Dir.to_hash('.')
18
+ # #=> {
19
+ # 'core_ext' => {
20
+ # 'object_test.rb'=>nil,
21
+ # 'dir_test.rb'=>nil,
22
+ # 'array_test.rb'=>nil,
23
+ # },
24
+ # 'test' => {
25
+ # },
26
+ # 'debug' => {
27
+ # 'debug_test.rb'=>nil
28
+ # }
29
+ # }
30
+ #
31
+ # call-seq:
32
+ # Dir.to_hash('/tmp') => hash
33
+ #
34
+ def to_hash(dir)
35
+ return nil unless File.exist?(dir)
36
+
37
+ entries(dir).delete_if {|f| f =~ /^\.{1,2}$/}.inject({}) do |values, entry|
38
+ full_entry = File.join(dir, entry)
39
+ values.merge!(entry => File.directory?(full_entry) ? to_hash(full_entry) : nil)
40
+ end
41
+ end
42
+
43
+ end # module ClassMethods
44
+
45
+ end # module Dir
46
+ end # module CoreExtensions
47
+ end # module SE
48
+
49
+ #Dir.send(:include, SE::CoreExtensions::Dir::InstanceMethods)
50
+ Dir.send(:extend, SE::CoreExtensions::Dir::ClassMethods)
@@ -0,0 +1,16 @@
1
+ # From: http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
2
+ class Object
3
+ # The hidden singleton lurks behind everyone
4
+ def metaclass; class << self; self; end; end
5
+ def meta_eval &blk; metaclass.instance_eval &blk; end
6
+
7
+ # Adds methods to a metaclass
8
+ def meta_def name, &blk
9
+ meta_eval { define_method name, &blk }
10
+ end
11
+
12
+ # Defines an instance method within a class
13
+ def class_def name, &blk
14
+ class_eval { define_method name, &blk }
15
+ end
16
+ end
@@ -0,0 +1,49 @@
1
+ #
2
+ # Object class extensions.
3
+ #
4
+ module SE
5
+ module CoreExtensions
6
+ module Object
7
+
8
+ module InstanceMethods
9
+
10
+ #
11
+ # Example:
12
+ # @person.name unless @person.nil?
13
+ # vs
14
+ # @person.try(:name)
15
+ #
16
+ # call-seq:
17
+ # object.try(:id) => num
18
+ # object.try(:bad_method) => nil
19
+ #
20
+ def try(method, *args, &block)
21
+ self.send(method, *args, &block) if respond_to?(method)
22
+ end
23
+
24
+ # Example:
25
+ # my_method("foo: #{foo}".tap{|ii| p ii})
26
+ # vs
27
+ # p ii = "foo: #{foo}"
28
+ # my_method(ii)
29
+ #
30
+ # call-seq:
31
+ # object.tap {block} => object
32
+ #
33
+ def tap
34
+ yield self
35
+ self
36
+ end
37
+
38
+ end # module InstanceMethods
39
+
40
+ module ClassMethods
41
+
42
+ end # module ClassMethods
43
+
44
+ end # module Object
45
+ end # module CoreExtensions
46
+ end # module SE
47
+
48
+ Object.send(:include, SE::CoreExtensions::Object::InstanceMethods)
49
+ #Object.send(:extend, SE::CoreExtensions::Object::ClassMethods)
@@ -0,0 +1,38 @@
1
+ # This module contains various debugging methods
2
+ module SE
3
+ module Debug
4
+
5
+ # Return class hierarchy as a String.
6
+ #
7
+ # examples:
8
+ # SE::Debug.class_hierarchy(RuntimeError)
9
+ # #=> RuntimeError includes: []
10
+ # #=> extends: StandardError includes: []
11
+ # #=> extends: Exception includes: []
12
+ # #=> extends: Object includes: [Kernel]
13
+ #
14
+ #
15
+ # call-seq:
16
+ # Debug.class_hierarchy(object) => String
17
+ #
18
+ def self.class_hierarchy(value, buf='', indent=0)
19
+ value = value.is_a?(Class) ? value : value.class
20
+ klass = value
21
+
22
+ buf << klass.name
23
+
24
+ if klass.superclass
25
+ buf << " includes: [#{(klass.ancestors[1..-1] - klass.superclass.ancestors).join(',')}]"
26
+ buf << "\n" << (' '*(indent+1)) << 'extends: '
27
+ class_hierarchy(klass.superclass, buf, indent + 1)
28
+ else
29
+ buf << " includes: [#{klass.ancestors[1..-1].join(',')}]"
30
+ end
31
+
32
+ buf
33
+ end
34
+
35
+ end # module Debug
36
+ end # module SE
37
+
38
+ # vim: sw=2 ts=2 et ai nowrap bg=dark
data/lib/se_gem.rb ADDED
File without changes
data/se_gem.gemspec ADDED
@@ -0,0 +1,57 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{se_gem}
5
+ s.version = "0.0.4"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Scott Steadman"]
9
+ s.date = %q{2009-07-05}
10
+ s.email = %q{ss@stdmn.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "lib/core_ext.rb",
23
+ "lib/debug.rb",
24
+ "lib/se/core_ext/array.rb",
25
+ "lib/se/core_ext/dir.rb",
26
+ "lib/se/core_ext/meta_class.rb",
27
+ "lib/se/core_ext/object.rb",
28
+ "lib/se/debug/debug.rb",
29
+ "lib/se_gem.rb",
30
+ "se_gem.gemspec",
31
+ "test/se/core_ext/array_test.rb",
32
+ "test/se/core_ext/dir_test.rb",
33
+ "test/se/core_ext/object_test.rb",
34
+ "test/se/debug/debug_test.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/ss/se_gem}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.4}
40
+ s.summary = %q{A collection of handy scripts.}
41
+ s.test_files = [
42
+ "test/se/debug/debug_test.rb",
43
+ "test/se/core_ext/dir_test.rb",
44
+ "test/se/core_ext/object_test.rb",
45
+ "test/se/core_ext/array_test.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
+ else
54
+ end
55
+ else
56
+ end
57
+ end
@@ -0,0 +1,27 @@
1
+ require 'test/unit'
2
+ require "#{File.dirname(__FILE__)}/../../../lib/se/core_ext/array"
3
+
4
+ class ArrayTest < Test::Unit::TestCase
5
+
6
+ def test_each_except_with_scalar
7
+ array = [1, 2, 3, 4]
8
+ result = []
9
+ array.each_except(3) {|ii| result << ii}
10
+ assert_equal [1,2,4], result
11
+ end
12
+
13
+ def test_each_except_with_scalars
14
+ array = [1, 2, 3, 4]
15
+ result = []
16
+ array.each_except(3,4) {|ii| result << ii}
17
+ assert_equal [1,2], result
18
+ end
19
+
20
+ def test_each_except_with_array
21
+ array = [1, 2, 3, 4]
22
+ result = []
23
+ array.each_except([3,4]) {|ii| result << ii}
24
+ assert_equal [1,2], result
25
+ end
26
+
27
+ end
@@ -0,0 +1,13 @@
1
+ require 'test/unit'
2
+ require "#{File.dirname(__FILE__)}/../../../lib/se/core_ext/dir"
3
+
4
+ class DirTest < Test::Unit::TestCase
5
+
6
+ def test_dir_to_hash
7
+ result = Dir.to_hash("#{File.dirname(__FILE__)}/..")
8
+ assert result['core_ext'].has_key?('dir_test.rb')
9
+ end
10
+
11
+ end
12
+
13
+
@@ -0,0 +1,25 @@
1
+ require 'test/unit'
2
+ require "#{File.dirname(__FILE__)}/../../../lib/se/core_ext/object"
3
+
4
+ class ObjectTest < Test::Unit::TestCase
5
+
6
+ def test_try_with_null
7
+ assert_nil nil.try(:name)
8
+ end
9
+
10
+ def test_try_with_missing_method
11
+ assert_nil "foo".try(:name)
12
+ assert_nil "foo".try(:name, 1)
13
+ end
14
+
15
+ def test_try_with_valid_method
16
+ assert_equal "Class", Class.try(:name)
17
+ assert_equal 'C', "Class".try(:[], (0..0))
18
+ end
19
+
20
+ def test_tap
21
+ assert_equal 'foo', 'foo'.tap {|ii| ii + '_bar'}
22
+ assert_equal 'foo_bar', 'foo'.tap {|ii| ii << '_bar'}
23
+ end
24
+
25
+ end
@@ -0,0 +1,16 @@
1
+ require 'test/unit'
2
+ require "#{File.dirname(__FILE__)}/../../../lib/se/debug/debug"
3
+
4
+ class DebugTest < Test::Unit::TestCase
5
+
6
+ def test_class_hierarchy
7
+ result = SE::Debug.class_hierarchy(RuntimeError)
8
+ assert_match "RuntimeError includes: []\n", result
9
+ assert_match "extends: StandardError includes: []\n", result
10
+ assert_match "extends: Exception includes: []\n", result
11
+ assert_match /extends: Object includes: \[(SE::CoreExtensions::Object::InstanceMethods,)?Kernel\]/, result
12
+ end
13
+
14
+ end
15
+
16
+
metadata CHANGED
@@ -1,40 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ss-se_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
- - Scott Steadman (and others)
7
+ - Scott Steadman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-16 00:00:00 -07:00
12
+ date: 2009-07-05 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description:
17
- email: gems@stdmn.com
17
+ email: ss@stdmn.com
18
18
  executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files: []
23
-
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
24
25
  files:
25
- - README
26
- has_rdoc: true
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/core_ext.rb
33
+ - lib/debug.rb
34
+ - lib/se/core_ext/array.rb
35
+ - lib/se/core_ext/dir.rb
36
+ - lib/se/core_ext/meta_class.rb
37
+ - lib/se/core_ext/object.rb
38
+ - lib/se/debug/debug.rb
39
+ - lib/se_gem.rb
40
+ - se_gem.gemspec
41
+ - test/se/core_ext/array_test.rb
42
+ - test/se/core_ext/dir_test.rb
43
+ - test/se/core_ext/object_test.rb
44
+ - test/se/debug/debug_test.rb
45
+ has_rdoc: false
27
46
  homepage: http://github.com/ss/se_gem
28
47
  post_install_message:
29
- rdoc_options: []
30
-
48
+ rdoc_options:
49
+ - --charset=UTF-8
31
50
  require_paths:
32
51
  - lib
33
52
  required_ruby_version: !ruby/object:Gem::Requirement
34
53
  requirements:
35
54
  - - ">="
36
55
  - !ruby/object:Gem::Version
37
- version: 1.8.6
56
+ version: "0"
38
57
  version:
39
58
  required_rubygems_version: !ruby/object:Gem::Requirement
40
59
  requirements:
@@ -47,7 +66,10 @@ requirements: []
47
66
  rubyforge_project:
48
67
  rubygems_version: 1.2.0
49
68
  signing_key:
50
- specification_version: 2
51
- summary: A collection of useful scripts.
52
- test_files: []
53
-
69
+ specification_version: 3
70
+ summary: A collection of handy scripts.
71
+ test_files:
72
+ - test/se/debug/debug_test.rb
73
+ - test/se/core_ext/dir_test.rb
74
+ - test/se/core_ext/object_test.rb
75
+ - test/se/core_ext/array_test.rb
data/README DELETED
@@ -1 +0,0 @@
1
- This gem contains useful scripts and libraries.