cowtech-extensions 1.6.1 → 1.6.3

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/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ coverage/
1
2
  pkg/
2
3
  .idea/
3
4
  Gemfile.lock
data/Rakefile CHANGED
@@ -4,4 +4,12 @@
4
4
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
5
  #
6
6
 
7
- require "bundler/gem_tasks"
7
+ require "bundler/gem_tasks"
8
+ require "rspec/core/rake_task"
9
+
10
+ RSpec::Core::RakeTask.new("spec")
11
+
12
+ desc "Run all specs with rcov"
13
+ RSpec::Core::RakeTask.new("spec:coverage") do |t|
14
+ t.rcov_opts = %q[--exclude "spec"]
15
+ end
@@ -4,22 +4,27 @@
4
4
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
5
  #
6
6
 
7
- require "./lib/cowtech-extensions/version"
7
+ require File.expand_path('../lib/cowtech-extensions/version', __FILE__)
8
8
 
9
- Gem::Specification.new do |s|
10
- s.name = "cowtech-extensions"
11
- s.version = Cowtech::Extensions::Version::STRING
12
- s.authors = ["Shogun"]
13
- s.email = ["shogun_panda@me.com"]
14
- s.homepage = "http://github.com/ShogunPanda/cowtech-extensions"
15
- s.summary = %q{Several Ruby object enhancements.}
16
- s.description = %q{Several Ruby object enhancements.}
9
+ Gem::Specification.new do |gem|
10
+ gem.name = "cowtech-extensions"
11
+ gem.version = Cowtech::Extensions::Version::STRING
12
+ gem.homepage = "http://github.com/ShogunPanda/cowtech-extensions"
13
+ gem.summary = %q{Several Ruby object enhancementa.}
14
+ gem.description = %q{Several Ruby object enhancements.}
15
+ gem.rubyforge_project = "cowtech-extensions"
17
16
 
18
- s.rubyforge_project = "cowtech-extensions"
19
- s.files = `git ls-files`.split("\n")
20
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
- s.require_paths = ["lib"]
17
+ gem.authors = ["Shogun"]
18
+ gem.email = ["shogun_panda@me.com"]
23
19
 
24
- s.add_dependency("actionpack", "~> 3.0")
20
+ gem.files = `git ls-files`.split($\)
21
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
22
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
23
+ gem.require_paths = ["lib"]
24
+
25
+ gem.add_dependency("actionpack", "~> 3.0")
26
+
27
+ gem.add_development_dependency("rspec", "~> 2.10")
28
+ gem.add_development_dependency("rcov", "~> 1.0.0")
29
+ gem.add_development_dependency("pry", "~> 0.9.9")
25
30
  end
@@ -4,6 +4,11 @@
4
4
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
5
  #
6
6
 
7
+ $KCODE='UTF8' if RUBY_VERSION < '1.9'
8
+
9
+ require "active_support/all"
10
+ require "action_view"
11
+
7
12
  require "cowtech-extensions/utils"
8
13
  require "cowtech-extensions/object"
9
14
  require "cowtech-extensions/boolean"
@@ -15,7 +20,7 @@ require "cowtech-extensions/pathname"
15
20
 
16
21
  module Cowtech
17
22
  module Extensions
18
- def self.load(what = [])
23
+ def self.load!(*what)
19
24
  what = ["object", "boolean", "string", "hash", "datetime", "math", "pathname"] if what.count == 0
20
25
  what.collect! { |w| w.to_s }
21
26
 
@@ -65,8 +70,6 @@ module Cowtech
65
70
  ::DateTime.class_eval do
66
71
  include Cowtech::Extensions::DateTime
67
72
  end
68
-
69
- #DateTime.cowtech_extensions_setup
70
73
  end
71
74
 
72
75
  if what.include?("math") then
@@ -84,5 +87,4 @@ module Cowtech
84
87
  end
85
88
  end
86
89
  end
87
- end
88
-
90
+ end
@@ -14,6 +14,7 @@ module Cowtech
14
14
  end
15
15
 
16
16
  module ClassMethods
17
+ # TODO: To test
17
18
  def cowtech_extensions_setup
18
19
  TrueClass::boolean_names = ["No", "Yes"]
19
20
  end
@@ -4,8 +4,7 @@
4
4
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
5
  #
6
6
 
7
- require "active_support/all"
8
-
7
+ # TODO: To test
9
8
  module Cowtech
10
9
  module Extensions
11
10
  module DateTime
@@ -10,7 +10,17 @@ module Cowtech
10
10
  extend ActiveSupport::Concern
11
11
 
12
12
  def method_missing(method, *args, &block)
13
- (self.has_key?(method.to_sym) || self.has_key?(method.to_s)) ? (self[method.to_sym] || self[method.to_s]) : super(method, *args, &block)
13
+ rv = nil
14
+
15
+ if self.has_key?(method.to_sym) then
16
+ rv = self[method.to_sym]
17
+ elsif self.has_key?(method.to_s) then
18
+ rv = self[method.to_s]
19
+ else
20
+ rv = super(method, *args, &block)
21
+ end
22
+
23
+ rv
14
24
  end
15
25
 
16
26
  def respond_to?(method)
@@ -10,14 +10,33 @@ module Cowtech
10
10
  extend ActiveSupport::Concern
11
11
 
12
12
  module ClassMethods
13
- def self.max(a, b)
14
- a > b ? a : b
15
- end
16
-
17
- def self.min(a, b)
18
- a < b ? a : b
19
- end
20
- end
13
+ def min(*args)
14
+ args = args.ensure_array.flatten
15
+
16
+ if args.length > 0 then
17
+ rv = args[0]
18
+ args.each do |a| rv = a if a < rv end
19
+ else
20
+ rv = nil
21
+ end
22
+
23
+ rv
24
+ end
25
+
26
+ def max(*args)
27
+ args = args.ensure_array.flatten
28
+
29
+ if args.length > 0 then
30
+ rv = args[0]
31
+ args.each do |a| rv = a if a > rv end
32
+ else
33
+ rv = nil
34
+ end
35
+
36
+ rv
37
+ end
38
+
39
+ end
21
40
  end
22
41
  end
23
42
  end
@@ -4,9 +4,7 @@
4
4
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
5
  #
6
6
 
7
- require "active_support/all"
8
- require "action_view"
9
-
7
+ # TODO: To test
10
8
  module Cowtech
11
9
  module Extensions
12
10
  module Object
@@ -10,7 +10,9 @@ module Cowtech
10
10
  extend ActiveSupport::Concern
11
11
 
12
12
  def components
13
- self.each_filename.collect { |p| p }
13
+ rv = []
14
+ self.each_filename { |p| rv << p }
15
+ rv
14
16
  end
15
17
  end
16
18
  end
@@ -4,15 +4,13 @@
4
4
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
5
  #
6
6
 
7
- require "active_support/all"
8
-
9
7
  module Cowtech
10
8
  module Extensions
11
9
  module String
12
10
  extend ActiveSupport::Concern
13
11
 
14
12
  def remove_accents
15
- self.mb_chars.normalize(:kd).gsub(/[^\-x00-\x7F]/n, "").to_s
13
+ self.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n, "").to_s
16
14
  end
17
15
 
18
16
  def untitleize
@@ -4,14 +4,12 @@
4
4
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
5
  #
6
6
 
7
- require "active_support"
8
-
9
7
  module Cowtech
10
8
  module Extensions
11
9
  module Version
12
10
  MAJOR = 1
13
11
  MINOR = 6
14
- PATCH = 1
12
+ PATCH = 3
15
13
 
16
14
  STRING = [MAJOR, MINOR, PATCH].compact.join(".")
17
15
  end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the cowtech-extensions gem. Copyright (C) 2011 and above Shogun <shogun_panda@me.com>.
4
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
+ #
6
+
7
+ require "spec_helper"
8
+
9
+ describe Cowtech::Extensions::Boolean do
10
+ describe "#to_i" do
11
+ it "should return 1 for true" do true.to_i.should == 1 end
12
+ it "should return 0 for false" do false.to_i.should == 0 end
13
+ end
14
+
15
+ describe "#value" do
16
+ it "should return self" do
17
+ true.value.should be_true
18
+ false.value.should be_false
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the cowtech-extensions gem. Copyright (C) 2011 and above Shogun <shogun_panda@me.com>.
4
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
+ #
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the cowtech-extensions gem. Copyright (C) 2011 and above Shogun <shogun_panda@me.com>.
4
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
+ #
6
+
7
+ require "spec_helper"
8
+
9
+ describe Cowtech::Extensions::Hash do
10
+ let(:reference) {
11
+ rv = {:a => 1, "b" => 2}
12
+ rv.default = 0
13
+ rv
14
+ }
15
+
16
+ describe "#method_missing" do
17
+ it "should allow method reference for string key" do reference.a.should == 1 end
18
+ it "should allow method reference for symbol key" do reference.b.should == 2 end
19
+ it "should use super for missing key" do expect {reference.c}.to raise_error(NoMethodError) end
20
+ end
21
+
22
+ describe "#respond_to" do
23
+ it "should return true for string key" do reference.respond_to?(:a).should be_true end
24
+ it "should return true for symbol key" do reference.respond_to?(:b).should be_true end
25
+ it "should return false for missing key" do reference.respond_to?(:c).should be_false end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the cowtech-extensions gem. Copyright (C) 2011 and above Shogun <shogun_panda@me.com>.
4
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
+ #
6
+
7
+ require "spec_helper"
8
+
9
+ describe Cowtech::Extensions::Math do
10
+ let(:first) { 1 }
11
+ let(:second) { 2 }
12
+ let(:third) { 0 }
13
+
14
+ describe "#min" do
15
+ it "should return the minimum argument" do
16
+ ::Math.min().should be_nil
17
+ ::Math.min(first).should == first
18
+ ::Math.min(first, second).should == first
19
+ ::Math.min([first, [second, third]]).should == third
20
+ end
21
+ end
22
+
23
+ describe "#max" do
24
+ it "should return the maximum argument" do
25
+ ::Math.min().should be_nil
26
+ ::Math.max(first).should == first
27
+ ::Math.max(first, second).should == second
28
+ ::Math.max([first, [second, third]]).should == second
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the cowtech-extensions gem. Copyright (C) 2011 and above Shogun <shogun_panda@me.com>.
4
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
+ #
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the cowtech-extensions gem. Copyright (C) 2011 and above Shogun <shogun_panda@me.com>.
4
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
+ #
6
+
7
+ require "spec_helper"
8
+
9
+ describe Cowtech::Extensions::Pathname do
10
+ let(:reference) { Pathname.new($0) }
11
+
12
+ describe "#components" do
13
+ it "should return the components of the path" do
14
+ ([""] + reference.components).should == reference.to_s.split("/")
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the cowtech-extensions gem. Copyright (C) 2011 and above Shogun <shogun_panda@me.com>.
4
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
+ #
6
+
7
+ require "spec_helper"
8
+
9
+ describe Cowtech::Extensions::String do
10
+ let(:reference) { "abc òùà èé &amp;gt;" }
11
+ let(:translated_reference) { "abc oua ee &amp;gt;" }
12
+ let(:untitleized_reference) { "abc-òùà-èé-&amp;gt;" }
13
+ let(:amp_reference) { "abc òùà èé &gt;" }
14
+
15
+ describe "#remove_accents" do
16
+ it "should translate accents" do reference.remove_accents.should == translated_reference end
17
+ end
18
+
19
+ describe "#untitleize" do
20
+ it "should convert spaces to dashes" do reference.untitleize.should == untitleized_reference end
21
+ end
22
+
23
+ describe "#replace_ampersands" do
24
+ it "should remove HTML ampersands" do reference.replace_ampersands.should == amp_reference end
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe Cowtech::Extensions do
4
+ describe "#load!" do
5
+ it "should load the extensions" do
6
+ Cowtech::Extensions.load!
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the cowtech-extensions gem. Copyright (C) 2011 and above Shogun <shogun_panda@me.com>.
4
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
+ #
6
+
7
+ require "rubygems"
8
+ require "bundler/setup"
9
+ require "cowtech-extensions"
10
+
11
+ RSpec.configure do |config|
12
+ Cowtech::Extensions.load!
13
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cowtech-extensions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 6
9
- - 1
10
- version: 1.6.1
9
+ - 3
10
+ version: 1.6.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Shogun
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-05 00:00:00 Z
18
+ date: 2012-06-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: actionpack
@@ -32,6 +32,53 @@ dependencies:
32
32
  version: "3.0"
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 23
44
+ segments:
45
+ - 2
46
+ - 10
47
+ version: "2.10"
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rcov
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 23
59
+ segments:
60
+ - 1
61
+ - 0
62
+ - 0
63
+ version: 1.0.0
64
+ type: :development
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: pry
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 41
75
+ segments:
76
+ - 0
77
+ - 9
78
+ - 9
79
+ version: 0.9.9
80
+ type: :development
81
+ version_requirements: *id004
35
82
  description: Several Ruby object enhancements.
36
83
  email:
37
84
  - shogun_panda@me.com
@@ -58,6 +105,15 @@ files:
58
105
  - lib/cowtech-extensions/string.rb
59
106
  - lib/cowtech-extensions/utils.rb
60
107
  - lib/cowtech-extensions/version.rb
108
+ - spec/cowtech-extensions/boolean_spec.rb
109
+ - spec/cowtech-extensions/datetime_spec.rb
110
+ - spec/cowtech-extensions/hash_spec.rb
111
+ - spec/cowtech-extensions/math_spec.rb
112
+ - spec/cowtech-extensions/object_spec.rb
113
+ - spec/cowtech-extensions/pathname_spec.rb
114
+ - spec/cowtech-extensions/string_spec.rb
115
+ - spec/cowtech-extensions_spec.rb
116
+ - spec/spec_helper.rb
61
117
  homepage: http://github.com/ShogunPanda/cowtech-extensions
62
118
  licenses: []
63
119
 
@@ -90,7 +146,15 @@ rubyforge_project: cowtech-extensions
90
146
  rubygems_version: 1.8.24
91
147
  signing_key:
92
148
  specification_version: 3
93
- summary: Several Ruby object enhancements.
94
- test_files: []
95
-
149
+ summary: Several Ruby object enhancementa.
150
+ test_files:
151
+ - spec/cowtech-extensions/boolean_spec.rb
152
+ - spec/cowtech-extensions/datetime_spec.rb
153
+ - spec/cowtech-extensions/hash_spec.rb
154
+ - spec/cowtech-extensions/math_spec.rb
155
+ - spec/cowtech-extensions/object_spec.rb
156
+ - spec/cowtech-extensions/pathname_spec.rb
157
+ - spec/cowtech-extensions/string_spec.rb
158
+ - spec/cowtech-extensions_spec.rb
159
+ - spec/spec_helper.rb
96
160
  has_rdoc: