evelpidon_core_ext 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +76 -0
- data/Rakefile +10 -0
- data/evelpidon_core_ext.gemspec +23 -0
- data/lib/evelpidon_core_ext/all.rb +1 -0
- data/lib/evelpidon_core_ext/hash.rb +27 -0
- data/lib/evelpidon_core_ext/version.rb +3 -0
- data/lib/evelpidon_core_ext.rb +4 -0
- data/test/hash_test.rb +25 -0
- data/test/test_helper.rb +6 -0
- metadata +108 -0
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyrignt (c) 2011 E-Travel S.A.
|
2
|
+
Copyrignt (c) 2011 Fraudpointer Ltd.
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Evelpidon Core Extensions
|
2
|
+
|
3
|
+
Collection of various core extensions to Ruby classes.
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
* Hash
|
8
|
+
* `#underscore_keys`
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
### Bundler
|
13
|
+
|
14
|
+
Add on your Gemfile :
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'evelpidon_core_ext'
|
18
|
+
```
|
19
|
+
|
20
|
+
### By hand
|
21
|
+
|
22
|
+
On the console :
|
23
|
+
|
24
|
+
```bash
|
25
|
+
gem install evelpidon_core_ext
|
26
|
+
```
|
27
|
+
|
28
|
+
On your code :
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'evelpidon_core_ext'
|
32
|
+
```
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
Extensions are *not* automatically loaded. You can require them explicitly one-by-one or all of them. So for example :
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
# Load only extensions to Hash :
|
40
|
+
require 'evelpidon_core_ext/hash'
|
41
|
+
```
|
42
|
+
|
43
|
+
or
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
# Load everything
|
47
|
+
require 'evelpidon_core_ext/all'
|
48
|
+
```
|
49
|
+
|
50
|
+
## TODOs
|
51
|
+
|
52
|
+
* Better documentation
|
53
|
+
|
54
|
+
## Note on Patches/Pull Requests
|
55
|
+
|
56
|
+
* Fork the project.
|
57
|
+
* Make your feature addition or bug fix.
|
58
|
+
* Add tests for it. This is important so I don't break it in a
|
59
|
+
future version unintentionally (not really...).
|
60
|
+
* Commit, do not mess with gemspec, version, or history.
|
61
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
62
|
+
* Send a pull request. Bonus points for topic branches.
|
63
|
+
|
64
|
+
## Author(s)
|
65
|
+
|
66
|
+
* [Nikos Dimitrakopoulos](http://github.com/nikosd)
|
67
|
+
|
68
|
+
## Copyright
|
69
|
+
|
70
|
+
* Copyrignt (c) 2011 [E-Travel S.A.](http://www.airtickets24.com)
|
71
|
+
* Copyrignt (c) 2011 [Fraudpointer.com](http://www.fraudpointer.com)
|
72
|
+
|
73
|
+
## License
|
74
|
+
|
75
|
+
Evelpidon Core Extensions are released under the MIT license.
|
76
|
+
See [LICENSE](/e-travel/evelpidon_core_ext/blob/master/LICENSE) for more details.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "evelpidon_core_ext/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "evelpidon_core_ext"
|
7
|
+
s.version = EvelpidonCoreExt::VERSION
|
8
|
+
s.authors = ["Nikos Dimitrakopoulos"]
|
9
|
+
s.email = ["n.dimitrakopoulos@pamediakopes.gr"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Core extensions to Ruby classes}
|
12
|
+
s.description = %q{Core extensions to Ruby classes}
|
13
|
+
|
14
|
+
s.rubyforge_project = "evelpidon_core_ext"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_runtime_dependency "activesupport"
|
22
|
+
s.add_runtime_dependency "i18n"
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "evelpidon_core_ext/hash"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'active_support/core_ext/string'
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
|
5
|
+
def underscore_keys
|
6
|
+
self.class.underscore_keys(self.dup)
|
7
|
+
end
|
8
|
+
|
9
|
+
#######
|
10
|
+
private
|
11
|
+
#######
|
12
|
+
|
13
|
+
def self.underscore_keys(hash)
|
14
|
+
hash.inject({}) do |h, (k,v)|
|
15
|
+
h[k.underscore] = case
|
16
|
+
when v.kind_of?(Hash)
|
17
|
+
v.underscore_keys
|
18
|
+
when v.kind_of?(Array)
|
19
|
+
v.map { |element| element.respond_to?(:underscore_keys) ? element.underscore_keys : element }
|
20
|
+
else
|
21
|
+
v
|
22
|
+
end
|
23
|
+
h
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/test/hash_test.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'evelpidon_core_ext/hash'
|
3
|
+
|
4
|
+
class HashTest < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
test "underscore with string camel case keys" do
|
7
|
+
original = {"StringCamelCase" => "string value",
|
8
|
+
"IntegerCamelCase" => 1,
|
9
|
+
"ArrayCamelCase" => ["Foo",
|
10
|
+
"Bar",
|
11
|
+
{"ArrayNestedStringCamelCase" => "string value"}],
|
12
|
+
"HashCamelCase" => {"NestedStringCamelCase" => "string value",
|
13
|
+
"NestedHashCamelCase" => {"SubNestedIntegerCamelCase" => 2}}}
|
14
|
+
expected = {"string_camel_case" => "string value",
|
15
|
+
"integer_camel_case" => 1,
|
16
|
+
"array_camel_case" => ["Foo",
|
17
|
+
"Bar",
|
18
|
+
{"array_nested_string_camel_case" => "string value"}],
|
19
|
+
"hash_camel_case" => {"nested_string_camel_case" => "string value",
|
20
|
+
"nested_hash_camel_case" => {"sub_nested_integer_camel_case" => 2}}}
|
21
|
+
|
22
|
+
assert_equal expected, original.underscore_keys
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: evelpidon_core_ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Nikos Dimitrakopoulos
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-11-01 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: activesupport
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: i18n
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: Core extensions to Ruby classes
|
50
|
+
email:
|
51
|
+
- n.dimitrakopoulos@pamediakopes.gr
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- .gitignore
|
60
|
+
- CHANGELOG.md
|
61
|
+
- Gemfile
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- evelpidon_core_ext.gemspec
|
66
|
+
- lib/evelpidon_core_ext.rb
|
67
|
+
- lib/evelpidon_core_ext/all.rb
|
68
|
+
- lib/evelpidon_core_ext/hash.rb
|
69
|
+
- lib/evelpidon_core_ext/version.rb
|
70
|
+
- test/hash_test.rb
|
71
|
+
- test/test_helper.rb
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: ""
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
requirements: []
|
100
|
+
|
101
|
+
rubyforge_project: evelpidon_core_ext
|
102
|
+
rubygems_version: 1.6.2
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Core extensions to Ruby classes
|
106
|
+
test_files:
|
107
|
+
- test/hash_test.rb
|
108
|
+
- test/test_helper.rb
|