cowtech-extensions 1.0.1.0 → 1.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.
data/cowtech-extensions.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cowtech-extensions}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.1.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Shogun}]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-08-02}
|
13
13
|
s.description = %q{Several Ruby object enhancements.}
|
14
14
|
s.email = %q{shogun_panda@me.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
"Rakefile",
|
24
24
|
"cowtech-extensions.gemspec",
|
25
25
|
"lib/cowtech-extensions.rb",
|
26
|
-
"lib/cowtech-extensions/activerecord.rb",
|
27
26
|
"lib/cowtech-extensions/boolean.rb",
|
28
27
|
"lib/cowtech-extensions/datetime.rb",
|
29
28
|
"lib/cowtech-extensions/hash.rb",
|
data/lib/cowtech-extensions.rb
CHANGED
@@ -4,7 +4,6 @@
|
|
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 "pathname"
|
8
7
|
require "cowtech-extensions/object"
|
9
8
|
require "cowtech-extensions/boolean"
|
10
9
|
require "cowtech-extensions/string"
|
@@ -16,7 +15,7 @@ require "cowtech-extensions/pathname"
|
|
16
15
|
module Cowtech
|
17
16
|
module Extensions
|
18
17
|
def self.load!(what = [])
|
19
|
-
what = ["object", "boolean", "string", "hash", "
|
18
|
+
what = ["object", "boolean", "string", "hash", "datetime", "math", "pathname"] if what.count == 0
|
20
19
|
what.collect! { |w| w.to_s }
|
21
20
|
|
22
21
|
yield if block_given?
|
@@ -45,7 +44,7 @@ module Cowtech
|
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
48
|
-
if what.include?("
|
47
|
+
if what.include?("hash") then
|
49
48
|
::Hash.class_eval do
|
50
49
|
include Cowtech::Extensions::Hash
|
51
50
|
end
|
@@ -72,16 +71,12 @@ module Cowtech
|
|
72
71
|
end
|
73
72
|
|
74
73
|
if what.include?("pathname") then
|
74
|
+
require "pathname"
|
75
|
+
|
75
76
|
::Pathname.class_eval do
|
76
77
|
include Cowtech::Extensions::Pathname
|
77
78
|
end
|
78
79
|
end
|
79
|
-
|
80
|
-
if what.include?("activerecord") then
|
81
|
-
::ActiveRecord::Base.class_eval do
|
82
|
-
include Cowtech::Extensions::AR
|
83
|
-
end
|
84
|
-
end
|
85
80
|
end
|
86
81
|
end
|
87
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cowtech-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-08-02 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jeweler
|
16
|
-
requirement: &
|
16
|
+
requirement: &70301383724200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70301383724200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: actionpack
|
27
|
-
requirement: &
|
27
|
+
requirement: &70301383722080 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70301383722080
|
36
36
|
description: Several Ruby object enhancements.
|
37
37
|
email: shogun_panda@me.com
|
38
38
|
executables: []
|
@@ -47,7 +47,6 @@ files:
|
|
47
47
|
- Rakefile
|
48
48
|
- cowtech-extensions.gemspec
|
49
49
|
- lib/cowtech-extensions.rb
|
50
|
-
- lib/cowtech-extensions/activerecord.rb
|
51
50
|
- lib/cowtech-extensions/boolean.rb
|
52
51
|
- lib/cowtech-extensions/datetime.rb
|
53
52
|
- lib/cowtech-extensions/hash.rb
|
@@ -1,62 +0,0 @@
|
|
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 "active_support/all"
|
8
|
-
|
9
|
-
module Cowtech
|
10
|
-
module Extensions
|
11
|
-
module AR
|
12
|
-
extend ActiveSupport::Concern
|
13
|
-
|
14
|
-
module ClassMethods
|
15
|
-
if defined?(Rails) then
|
16
|
-
def self.table_prefix
|
17
|
-
p = ActiveRecord::Base.configurations[Rails.env]["table_prefix"]
|
18
|
-
!p.blank? ? p + "_" : ""
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.table_suffix
|
22
|
-
p = ActiveRecord::Base.configurations[Rails.env]["table_suffix"]
|
23
|
-
!p.blank? ? p + "_" : ""
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.set_table_name(value = nil, &block)
|
28
|
-
define_attr_method :table_name, "#{ActiveRecord::Base.table_prefix}#{value}#{ActiveRecord::Base.table_suffix}", &block
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.find_or_create(oid, attributes = nil)
|
32
|
-
begin
|
33
|
-
self.find(oid)
|
34
|
-
rescue ActiveRecord::RecordNotFound
|
35
|
-
self.new(attributes)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.safe_find(oid)
|
40
|
-
begin
|
41
|
-
rv = self.find(oid)
|
42
|
-
rescue ActiveRecord::RecordNotFound
|
43
|
-
nil
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.random
|
48
|
-
c = self.count
|
49
|
-
c != 0 ? self.find(:first, :offset => rand(c)) : nil
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.per_page
|
53
|
-
25
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
module InstanceMethods
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|