fat 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gems +2 -0
- data/.gitignore +2 -0
- data/LICENSE +22 -0
- data/Makefile +5 -0
- data/README.md +7 -0
- data/Rakefile +3 -0
- data/ext/fat/extconf.rb +5 -0
- data/ext/fat/fat.c +66 -0
- data/fat.gemspec +17 -0
- data/lib/.gitkeep +0 -0
- data/test/fat_test.rb +62 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3a2a4f02825c7b90cc3693f53b6d54c0762e3065
|
4
|
+
data.tar.gz: 6641e03bd1a109a5b65528da792e2c4e6df90406
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 76bffdd370590a7acad70d29dfdcc3c08b2c56cafc88439ce47c6aab4b7e090e5b46f3af4932021a087a9f88780e21d48a443e5bbf8c19488d0fb2d83f46d4e2
|
7
|
+
data.tar.gz: 54b76753d47a02ee615d41a0f604b6fb0e4e6ad164c5b45565f8e2b815da434c3df1ebde86d6b2ee1848422cceb6cc8b624a493476652b379e087973ce809a9a
|
data/.gems
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Lucas Tolchinsky
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/Makefile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
data/ext/fat/extconf.rb
ADDED
data/ext/fat/fat.c
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
#include<ruby.h>
|
2
|
+
|
3
|
+
VALUE Fat = Qnil;
|
4
|
+
|
5
|
+
void Init_fat();
|
6
|
+
|
7
|
+
static VALUE singleton_method_at(int argc, VALUE *argv, VALUE self);
|
8
|
+
static VALUE method_at(int argc, VALUE *argv, VALUE hash);
|
9
|
+
|
10
|
+
static VALUE fat(VALUE hash, VALUE fields);
|
11
|
+
void parse_fields(VALUE args, VALUE *fields);
|
12
|
+
|
13
|
+
void Init_fat(void) {
|
14
|
+
Fat = rb_define_module("Fat");
|
15
|
+
rb_define_module_function(Fat, "at", singleton_method_at, -1);
|
16
|
+
rb_define_method(Fat, "at", method_at, -1);
|
17
|
+
}
|
18
|
+
|
19
|
+
static VALUE singleton_method_at(int argc, VALUE *argv, VALUE self) {
|
20
|
+
VALUE hash;
|
21
|
+
VALUE args;
|
22
|
+
|
23
|
+
rb_scan_args(argc, argv, "1*", &hash, &args);
|
24
|
+
|
25
|
+
VALUE fields;
|
26
|
+
parse_fields(args, &fields);
|
27
|
+
|
28
|
+
return fat(hash, fields);
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE method_at(int argc, VALUE *argv, VALUE hash) {
|
32
|
+
VALUE args;
|
33
|
+
rb_scan_args(argc, argv, "*", &args);
|
34
|
+
|
35
|
+
VALUE fields;
|
36
|
+
parse_fields(args, &fields);
|
37
|
+
|
38
|
+
return fat(hash, fields);
|
39
|
+
}
|
40
|
+
|
41
|
+
static VALUE fat(VALUE hash, VALUE fields) {
|
42
|
+
VALUE value = hash;
|
43
|
+
for (int i = 0; i < RARRAY_LEN(fields); i++) {
|
44
|
+
value = rb_hash_aref(value, RARRAY_PTR(fields)[i]);
|
45
|
+
|
46
|
+
if (value == Qnil) {
|
47
|
+
return Qnil;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
return value;
|
52
|
+
}
|
53
|
+
|
54
|
+
void parse_fields(VALUE args, VALUE *fields) {
|
55
|
+
if (RARRAY_LEN(args) == 1) {
|
56
|
+
VALUE chain = RARRAY_PTR(args)[0];
|
57
|
+
|
58
|
+
StringValue(chain);
|
59
|
+
const char* dot = ".";
|
60
|
+
|
61
|
+
*fields = rb_str_split(chain, dot);
|
62
|
+
} else {
|
63
|
+
*fields = args;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
data/fat.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "fat"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.summary = "C extension to find values in nested hashes without pain"
|
5
|
+
s.description = s.summary
|
6
|
+
s.authors = ["Lucas Tolchinsky"]
|
7
|
+
s.email = ["lucas.tolchinsky@gmail.com"]
|
8
|
+
s.homepage = "https://github.com/tonchis/fat"
|
9
|
+
s.license = "MIT"
|
10
|
+
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.extensions = ["ext/fat/extconf.rb"]
|
13
|
+
|
14
|
+
s.add_development_dependency "cutest"
|
15
|
+
s.add_development_dependency "rake-compiler"
|
16
|
+
end
|
17
|
+
|
data/lib/.gitkeep
ADDED
File without changes
|
data/test/fat_test.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require "cutest"
|
2
|
+
require_relative "../lib/fat"
|
3
|
+
|
4
|
+
scope do
|
5
|
+
setup do
|
6
|
+
{
|
7
|
+
foo: {
|
8
|
+
"bar" => {
|
9
|
+
baz: :found
|
10
|
+
}
|
11
|
+
}
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
test "honor key type" do |hash|
|
16
|
+
assert_equal nil, Fat.at(hash, "foo", :not, :found)
|
17
|
+
|
18
|
+
assert_equal :found, Fat.at(hash, :foo, "bar", :baz)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
scope do
|
23
|
+
setup do
|
24
|
+
{
|
25
|
+
"foo" => {
|
26
|
+
"bar" => {
|
27
|
+
"baz" => :found
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
test "namespaced string keys" do |hash|
|
34
|
+
assert_equal nil, Fat.at(hash, "foo.not.found")
|
35
|
+
|
36
|
+
assert_equal :found, Fat.at(hash, "foo.bar.baz")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
scope do
|
41
|
+
setup do
|
42
|
+
Hash.include(Fat)
|
43
|
+
end
|
44
|
+
|
45
|
+
test "include the module" do
|
46
|
+
assert Hash.new.respond_to?(:at)
|
47
|
+
end
|
48
|
+
|
49
|
+
test "uses both interfaces" do
|
50
|
+
hash = {
|
51
|
+
"foo" => {
|
52
|
+
"bar" => {
|
53
|
+
"baz" => :found
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
assert_equal :found, hash.at("foo", "bar", "baz")
|
59
|
+
assert_equal :found, hash.at("foo.bar.baz")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lucas Tolchinsky
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cutest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake-compiler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: C extension to find values in nested hashes without pain
|
42
|
+
email:
|
43
|
+
- lucas.tolchinsky@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions:
|
46
|
+
- ext/fat/extconf.rb
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gems"
|
50
|
+
- ".gitignore"
|
51
|
+
- LICENSE
|
52
|
+
- Makefile
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- ext/fat/extconf.rb
|
56
|
+
- ext/fat/fat.c
|
57
|
+
- fat.gemspec
|
58
|
+
- lib/.gitkeep
|
59
|
+
- test/fat_test.rb
|
60
|
+
homepage: https://github.com/tonchis/fat
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.2.0
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: C extension to find values in nested hashes without pain
|
84
|
+
test_files: []
|