extlib_lite 0.0.1 → 0.0.2
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/README.markdown +1 -5
- data/Rakefile +0 -1
- data/VERSION +1 -1
- data/extlib_lite.gemspec +2 -6
- data/lib/extlib_lite/core_extensions/string.rb +17 -53
- data/lib/extlib_lite/inflections.rb +0 -20
- metadata +5 -20
- data/lib/extlib_lite/core_extensions/hash.rb +0 -47
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# extlib_lite
|
2
2
|
|
3
|
-
extlib_lite is a super lightweight alternative to [activesupport](http://github.com/rails/rails/tree/master/activesupport) or [extlib](http://github.com/datamapper/extlib). It contains some of the usual friends such as pluralize, singularize, classify, and constantize without the overhead of its big brothers. I take no credit for extlib_lite, I simply extracted the code
|
3
|
+
extlib_lite is a super lightweight alternative to [activesupport](http://github.com/rails/rails/tree/master/activesupport) or [extlib](http://github.com/datamapper/extlib). It contains some of the usual friends such as pluralize, singularize, classify, and constantize without the overhead of its big brothers. I take no credit for extlib_lite, I simply extracted the code from [activesupport](http://github.com/rails/rails/tree/master/activesupport) and [extlib](http://github.com/datamapper/extlib).
|
4
4
|
## Supported Functions
|
5
5
|
Currently extlib_lite supports the following functions
|
6
6
|
### String
|
@@ -9,10 +9,6 @@ Currently extlib_lite supports the following functions
|
|
9
9
|
* classify
|
10
10
|
* constantize
|
11
11
|
* underscore
|
12
|
-
* from_query
|
13
|
-
|
14
|
-
### Hash
|
15
|
-
* to_query
|
16
12
|
|
17
13
|
## Installation
|
18
14
|
|
data/Rakefile
CHANGED
@@ -22,7 +22,6 @@ begin
|
|
22
22
|
gemspec.email = "dwilkie@gmail.com"
|
23
23
|
gemspec.homepage = "http://github.com/dwilkie/extlib_lite"
|
24
24
|
gemspec.authors = ["David Wilkie"]
|
25
|
-
gemspec.add_runtime_dependency "addressable", ">=2.1.1"
|
26
25
|
end
|
27
26
|
rescue LoadError
|
28
27
|
puts "Jeweler not available. Install it with: gem install jeweler"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/extlib_lite.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{extlib_lite}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David Wilkie"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-26}
|
13
13
|
s.email = %q{dwilkie@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.markdown"
|
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
"extlib_lite.gemspec",
|
24
24
|
"lib/extlib_lite.rb",
|
25
25
|
"lib/extlib_lite/core_extensions.rb",
|
26
|
-
"lib/extlib_lite/core_extensions/hash.rb",
|
27
26
|
"lib/extlib_lite/core_extensions/string.rb",
|
28
27
|
"lib/extlib_lite/inflections.rb",
|
29
28
|
"todo"
|
@@ -39,12 +38,9 @@ Gem::Specification.new do |s|
|
|
39
38
|
s.specification_version = 3
|
40
39
|
|
41
40
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
42
|
-
s.add_runtime_dependency(%q<addressable>, [">= 2.1.1"])
|
43
41
|
else
|
44
|
-
s.add_dependency(%q<addressable>, [">= 2.1.1"])
|
45
42
|
end
|
46
43
|
else
|
47
|
-
s.add_dependency(%q<addressable>, [">= 2.1.1"])
|
48
44
|
end
|
49
45
|
end
|
50
46
|
|
@@ -1,60 +1,24 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
class String
|
2
|
+
def singular
|
3
|
+
Extlib::Inflection.singular(self)
|
4
|
+
end
|
5
|
+
alias_method(:singularize, :singular)
|
3
6
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# "text_message"=>{
|
9
|
-
# "to"=>"61447100308",
|
10
|
-
# "from"=>"61447100547",
|
11
|
-
# "msg"=>"Edin knif lie km",
|
12
|
-
# "date"=>"2010-05-13 23:59:58"
|
13
|
-
# }
|
14
|
-
# }
|
15
|
-
#
|
16
|
-
# @return [Hash] Query string converted to hash.
|
17
|
-
#
|
18
|
-
# @api public
|
19
|
-
def from_query
|
20
|
-
uri = Addressable::URI.new
|
21
|
-
uri.query = self
|
22
|
-
uri.query_values
|
23
|
-
end
|
7
|
+
def plural
|
8
|
+
Extlib::Inflection.plural(self)
|
9
|
+
end
|
10
|
+
alias_method(:pluralize, :plural)
|
24
11
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
# "FooBar::Baz".to_const_path # => "foo_bar/baz"
|
29
|
-
#
|
30
|
-
# @return [String] Path to the file containing the constant named by receiver
|
31
|
-
# (constantized string), assuming a conventional structure.
|
32
|
-
#
|
33
|
-
# @api public
|
34
|
-
def to_const_path
|
35
|
-
snake_case.gsub(/::/, "/")
|
36
|
-
end
|
12
|
+
def classify
|
13
|
+
Extlib::Inflection.classify(self)
|
14
|
+
end
|
37
15
|
|
38
|
-
|
39
|
-
|
40
|
-
#
|
41
|
-
# "FooBar".snake_case #=> "foo_bar"
|
42
|
-
# "HeadlineCNNNews".snake_case #=> "headline_cnn_news"
|
43
|
-
# "CNN".snake_case #=> "cnn"
|
44
|
-
#
|
45
|
-
# @return [String] Receiver converted to snake case.
|
46
|
-
#
|
47
|
-
# @api public
|
48
|
-
def snake_case
|
49
|
-
return downcase if match(/\A[A-Z]+\z/)
|
50
|
-
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
51
|
-
gsub(/([a-z])([A-Z])/, '\1_\2').
|
52
|
-
downcase
|
53
|
-
end
|
16
|
+
def constantize
|
17
|
+
Extlib::Inflection.constantize(self)
|
54
18
|
end
|
55
|
-
end
|
56
19
|
|
57
|
-
|
58
|
-
|
20
|
+
def underscore
|
21
|
+
Extlib::Inflection.underscore(self)
|
22
|
+
end
|
59
23
|
end
|
60
24
|
|
@@ -373,23 +373,3 @@ module Extlib
|
|
373
373
|
end
|
374
374
|
end
|
375
375
|
|
376
|
-
class String
|
377
|
-
def singular
|
378
|
-
Extlib::Inflection.singular(self)
|
379
|
-
end
|
380
|
-
alias_method(:singularize, :singular)
|
381
|
-
def plural
|
382
|
-
Extlib::Inflection.plural(self)
|
383
|
-
end
|
384
|
-
alias_method(:pluralize, :plural)
|
385
|
-
def classify
|
386
|
-
Extlib::Inflection.classify(self)
|
387
|
-
end
|
388
|
-
def constantize
|
389
|
-
Extlib::Inflection.constantize(self)
|
390
|
-
end
|
391
|
-
def underscore
|
392
|
-
Extlib::Inflection.underscore(self)
|
393
|
-
end
|
394
|
-
end
|
395
|
-
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- David Wilkie
|
@@ -14,24 +14,10 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-09-26 00:00:00 +07:00
|
18
18
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
21
|
-
name: addressable
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
|
-
requirements:
|
26
|
-
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 2
|
30
|
-
- 1
|
31
|
-
- 1
|
32
|
-
version: 2.1.1
|
33
|
-
type: :runtime
|
34
|
-
version_requirements: *id001
|
19
|
+
dependencies: []
|
20
|
+
|
35
21
|
description:
|
36
22
|
email: dwilkie@gmail.com
|
37
23
|
executables: []
|
@@ -49,7 +35,6 @@ files:
|
|
49
35
|
- extlib_lite.gemspec
|
50
36
|
- lib/extlib_lite.rb
|
51
37
|
- lib/extlib_lite/core_extensions.rb
|
52
|
-
- lib/extlib_lite/core_extensions/hash.rb
|
53
38
|
- lib/extlib_lite/core_extensions/string.rb
|
54
39
|
- lib/extlib_lite/inflections.rb
|
55
40
|
- todo
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module CoreExtensions
|
2
|
-
module Hash
|
3
|
-
##
|
4
|
-
# Convert to a query string
|
5
|
-
#
|
6
|
-
# {
|
7
|
-
# :text_message => {
|
8
|
-
# :to => 61447100308,
|
9
|
-
# :from => 61447100547,
|
10
|
-
# :msg => "Edin knif lie km"
|
11
|
-
# :date => "2010-05-13 23:59:58"
|
12
|
-
# }
|
13
|
-
# }.to_query #=> "text_message%5Bto%5D=61447100308&text_message%5Bfrom%5D=61447100547&text_message%5Bmsg%5D=Edin%20knif%20lie%20km&text_message%5Bdate%5D=2010-05-13%2023%3A59%3A58"
|
14
|
-
#
|
15
|
-
# @return [String] Hash converted to a query string
|
16
|
-
#
|
17
|
-
# @api public
|
18
|
-
def to_query
|
19
|
-
uri = Addressable::URI.new
|
20
|
-
uri.query_values = self.stringify
|
21
|
-
uri.query.gsub("[", "%5B").gsub("]", "%5D")
|
22
|
-
end
|
23
|
-
|
24
|
-
def stringify
|
25
|
-
Marshal.load(Marshal.dump(self)).stringify!
|
26
|
-
end
|
27
|
-
|
28
|
-
# Destructively convert all keys and values to strings
|
29
|
-
def stringify!
|
30
|
-
keys.each do |key|
|
31
|
-
new_key = key.to_s
|
32
|
-
self[new_key] = delete(key)
|
33
|
-
if self[new_key].is_a?(Hash)
|
34
|
-
self[new_key].stringify!
|
35
|
-
else
|
36
|
-
self[new_key] = delete(new_key).to_s
|
37
|
-
end
|
38
|
-
end
|
39
|
-
self
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class Hash
|
45
|
-
include CoreExtensions::Hash
|
46
|
-
end
|
47
|
-
|