nx 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/README.md +23 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/nx.rb +48 -0
- data/lib/templates/version.rb +3 -0
- data/nx.gemspec +35 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5f7c349f24f446f5d13d739c79eab2b3f133e3a7dc159b0da2df35369c682af6
|
4
|
+
data.tar.gz: 3ec07565edc6d250233e3509f99c96ac7725666b5fc839d939cce4abd1a72108
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bdb9cb3e76b9a956a62a3669b1dde2d2d2ae631a2298e866f03122319e479cde7465ecc68ad1b2fa20501c6588f2ad2d75283b70679e9a1b2896260035f57009
|
7
|
+
data.tar.gz: 1aa016243e19717fc04ca09d459d97564b0aac0951c77802efc423f36a6fc654d368274862f6cde4d93a7e0fb83f78484235273a67b5691ab31b9b3eea99c283
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# nx
|
2
|
+
> Next core for ruby version.
|
3
|
+
|
4
|
+
## install:
|
5
|
+
```rb
|
6
|
+
# add to Gemfile
|
7
|
+
gem 'nx', git: 'https://github.com/afeiship/nx'
|
8
|
+
```
|
9
|
+
|
10
|
+
## usage:
|
11
|
+
```rb
|
12
|
+
## add bundle/setup:
|
13
|
+
require "bundler/setup"
|
14
|
+
require "nx"
|
15
|
+
|
16
|
+
h = { "b" => { "c" => [0, [1, 3]] } }
|
17
|
+
p h.get("b.c[1][1]")
|
18
|
+
```
|
19
|
+
|
20
|
+
## resouces:
|
21
|
+
- https://bugs.ruby-lang.org/issues/13179
|
22
|
+
- http://ruby-doc.org/core-2.3.0_preview1/Hash.html#method-i-dig
|
23
|
+
- https://tagmycode.com/snippet/8218/get-set-hash-values-using-key-path-separated-by-dots#.XIH69BMzaM4
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gem-next-core"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/nx.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "templates/version"
|
2
|
+
|
3
|
+
module Nx
|
4
|
+
def set(path, value)
|
5
|
+
me = self || {}
|
6
|
+
keys = []
|
7
|
+
path.split(".").each do |dot_part|
|
8
|
+
dot_part.split("[").each do |part|
|
9
|
+
keys << (part.include?("]") ? part.to_i : part)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# set by path:
|
14
|
+
keys[0..-2].each_with_index do |key, index|
|
15
|
+
me = me[key] = me[key] || (keys[index + 1].class == String ? {} : [])
|
16
|
+
end
|
17
|
+
|
18
|
+
me[keys[-1]] = value
|
19
|
+
end
|
20
|
+
|
21
|
+
def get( path)
|
22
|
+
result = self
|
23
|
+
path.split(".").each do |dot_part|
|
24
|
+
dot_part.split("[").each do |part|
|
25
|
+
if part.include?("]")
|
26
|
+
index = part.to_i
|
27
|
+
result = result[index] rescue nil
|
28
|
+
else
|
29
|
+
result = result[part] rescue nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
result
|
34
|
+
end
|
35
|
+
|
36
|
+
def mix(*args)
|
37
|
+
result = {}
|
38
|
+
args.each do |arg|
|
39
|
+
result.merge! arg
|
40
|
+
end
|
41
|
+
result
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# extend ruby nx
|
46
|
+
class Hash
|
47
|
+
include Nx
|
48
|
+
end
|
data/nx.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "templates/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nx"
|
8
|
+
spec.version = Nx::VERSION
|
9
|
+
spec.authors = ["afeiship"]
|
10
|
+
spec.email = ["1290657123@qq.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Next core.}
|
13
|
+
spec.description = %q{Next core for ruby gem.}
|
14
|
+
spec.homepage = "https://github.com/afeiship/nx"
|
15
|
+
spec.licenses = ["MIT"]
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- afeiship
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Next core for ruby gem.
|
42
|
+
email:
|
43
|
+
- 1290657123@qq.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- Gemfile
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- lib/nx.rb
|
56
|
+
- lib/templates/version.rb
|
57
|
+
- nx.gemspec
|
58
|
+
homepage: https://github.com/afeiship/nx
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubygems_version: 3.1.2
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Next core.
|
81
|
+
test_files: []
|