jumunge 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 +12 -0
- data/.rspec +2 -0
- data/.travis.yml +12 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/jumunge.gemspec +26 -0
- data/lib/jumunge/version.rb +3 -0
- data/lib/jumunge.rb +140 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6d1087b396ae11b150de7e45101c7f3f10256090
|
4
|
+
data.tar.gz: '0804afa2e6472820175a8a9556f851d36782737c'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 326b8d5f7fe7990ef3161264afa98a9f321e214b6a43fa7dbfc5bce4069b29c6c28268489a5323f211ff0e5f3e39addcdc8a4e0e6681e60670df940637f8521e
|
7
|
+
data.tar.gz: 3735177850e86f78ede9c06a38eb754715a01cc9b9387af70505a839180d84c5296546c7fc6980bac6b98b58494df6ed1e50c0c3f7f07ecc52d457cb8318b07b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.4.1
|
5
|
+
before_install: gem install bundler -v 1.15.4
|
6
|
+
deploy:
|
7
|
+
provider: rubygems
|
8
|
+
api_key:
|
9
|
+
secure: YgPD3zs9Am0R1w7xOYlLrI7ls8v1nuOQpC+R+4GyULeDYMIJg9kHe59n3CuiUmaVs3bQZTlW921sluY6+GPQrZdOf5fF0wGluF7X71DtZYEabic611QI1y4hgrFrHX7JFerqjoDATUMIkN+MAk3m+Ok7czs9PSL89CltNznJcV3PXVFyPHrWZE9+XY8Bl2hh8N3PHdcVKDiT1JK1d3qLoiklW32bOvD0Vt5VPnThps+hDRY+Gm4sfNDextd1LqptXdAGrrd1y+agQD+9GDf6m9Ypo2LofpY0J29nZ93eV04bP5zC2gVWCwwmPANLX7LcUboDt309j5ytbwQT9zAd4ms/mIH+8Jf6taOvugmGDJOzCBSXyDl4sj9gLAeHkrYFv5l/cka0bvBAHiyBNOEJAUyrmc7ZKGAIYJiwCZQ4cExyiQE3ywPMC7z2FhR5OOMpJyXawbgdMkLma1fIWnBUdPBudKYt0yni5+BVlWyDymoduWQxYllkVrLyAfdOLzjUGWF6oXZMTsqQTJ2s34pitrMeXa5Q4RUIN/2A1Yav0pQQ3yP0vODMzLxi3rCj9NM7XX2KC3H+EEfc9zLPOIMSnlnnu7SlX9+65HJQMgFAm/u3zRHSF3FdBX2ZtwmEZbjwhqhdkKWlW4SA70TLoYDyeNqshRlgoJ663jox38iL92Y=
|
10
|
+
on:
|
11
|
+
tags: true
|
12
|
+
repo: miyucy/jumunge
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 miyucy
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Jumunge
|
2
|
+
|
3
|
+
## Usage
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'jumunge'
|
7
|
+
|
8
|
+
params = {}
|
9
|
+
jumunged_params = Jumunge.jumunge(params, 'foo.bar!', 'foo.baz[]', 'foo.qux')
|
10
|
+
# => {"foo"=>{"bar"=>nil, "baz"=>[], "qux"=>{}}}
|
11
|
+
jumunged_params.dig('foo', 'bar')
|
12
|
+
# => nil
|
13
|
+
jumunged_params.dig('foo', 'baz')
|
14
|
+
# => []
|
15
|
+
jumunged_params.dig('foo', 'qux')
|
16
|
+
# => {}
|
17
|
+
```
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'jumunge'
|
25
|
+
```
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ bundle
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install jumunge
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/miyucy/jumunge.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "jumunge"
|
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/jumunge.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "jumunge/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jumunge"
|
8
|
+
spec.version = Jumunge::VERSION
|
9
|
+
spec.authors = ["miyucy"]
|
10
|
+
spec.email = ["fistfvck@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Write a short summary, because Rubygems requires one.}
|
13
|
+
spec.description = %q{Write a longer description or delete this line.}
|
14
|
+
spec.homepage = "https://github.com/miyucy/jumunge"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
end
|
data/lib/jumunge.rb
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
require "jumunge/version"
|
2
|
+
|
3
|
+
module Jumunge
|
4
|
+
class JuValue
|
5
|
+
def initialize(object, trail, trails)
|
6
|
+
@object = object
|
7
|
+
@trail = trail
|
8
|
+
@trails = trails
|
9
|
+
end
|
10
|
+
|
11
|
+
def perform
|
12
|
+
@object[key_name] = empty_value unless @object.key? key_name
|
13
|
+
@object
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def key_name
|
19
|
+
@key_name ||= @trail[0..-2]
|
20
|
+
end
|
21
|
+
|
22
|
+
def empty_value
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class JuArray
|
28
|
+
def initialize(object, trail, trails)
|
29
|
+
@object = object
|
30
|
+
@trail = trail
|
31
|
+
@trails = trails
|
32
|
+
end
|
33
|
+
|
34
|
+
def perform
|
35
|
+
@object[key_name] = empty_value unless @object.key? key_name
|
36
|
+
@object[key_name] = deep_applied_value if @trails.size.positive?
|
37
|
+
@object
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def key_name
|
43
|
+
@key_name ||= @trail[0..-3]
|
44
|
+
end
|
45
|
+
|
46
|
+
def empty_value
|
47
|
+
[]
|
48
|
+
end
|
49
|
+
|
50
|
+
def deep_applied_value
|
51
|
+
@object[key_name].map do |value|
|
52
|
+
Jumunge.new(value, remaining_trails).perform
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def remaining_trails
|
57
|
+
@remaining_trails ||= @trails.join('.')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class JuOther
|
62
|
+
def initialize(object, trail, trails)
|
63
|
+
@object = object
|
64
|
+
@trail = trail
|
65
|
+
@trails = trails
|
66
|
+
end
|
67
|
+
|
68
|
+
def perform
|
69
|
+
@object[key_name] = empty_value unless @object.key? key_name
|
70
|
+
@object[key_name] = deep_applied_value if @trails.size.positive?
|
71
|
+
@object
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def key_name
|
77
|
+
@trail
|
78
|
+
end
|
79
|
+
|
80
|
+
def empty_value
|
81
|
+
{}
|
82
|
+
end
|
83
|
+
|
84
|
+
def deep_applied_value
|
85
|
+
Jumunge.new(@object[key_name], remaining_trails).perform
|
86
|
+
end
|
87
|
+
|
88
|
+
def remaining_trails
|
89
|
+
@remaining_trails ||= @trails.join('.')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class JuThru
|
94
|
+
def initialize(object, *)
|
95
|
+
@object = object
|
96
|
+
end
|
97
|
+
|
98
|
+
def perform
|
99
|
+
@object
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class Jumunge
|
104
|
+
def initialize(object, path)
|
105
|
+
@object = object
|
106
|
+
@trail, *@trails = path.split '.'
|
107
|
+
@is_array = @trail[-2..-1] == '[]'
|
108
|
+
@is_value = @trail[-1] == '!'
|
109
|
+
@performer = performer_class.new @object, @trail, @trails
|
110
|
+
end
|
111
|
+
|
112
|
+
def perform
|
113
|
+
@performer.perform
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def performer_class
|
119
|
+
if @object
|
120
|
+
if @is_array
|
121
|
+
JuArray
|
122
|
+
elsif @is_value
|
123
|
+
JuValue
|
124
|
+
else
|
125
|
+
JuOther
|
126
|
+
end
|
127
|
+
else
|
128
|
+
JuThru
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
private_constant :Jumunge, :JuArray, :JuValue, :JuOther, :JuThru
|
133
|
+
|
134
|
+
def jumunge(object, *paths)
|
135
|
+
paths.inject(object) do |result, path|
|
136
|
+
Jumunge.new(result, path).perform
|
137
|
+
end
|
138
|
+
end
|
139
|
+
module_function :jumunge
|
140
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jumunge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- miyucy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-07 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.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Write a longer description or delete this line.
|
56
|
+
email:
|
57
|
+
- fistfvck@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- jumunge.gemspec
|
72
|
+
- lib/jumunge.rb
|
73
|
+
- lib/jumunge/version.rb
|
74
|
+
homepage: https://github.com/miyucy/jumunge
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.6.13
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Write a short summary, because Rubygems requires one.
|
98
|
+
test_files: []
|