local_json 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +27 -0
- data/lib/local-json.rb +15 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8b22b4845d038399cf6d2467c4d4c4fa04182ae0a0e66bbb65f0041d53d82792
|
4
|
+
data.tar.gz: aa5381d87cb346b8a9797cea149948f32af866b309c7c0d91bbac213bc4c7f7a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a89dc9c24fb52610059cd7ff16fbb7863761e2537eb2a00486e8b311456c722604fbf37d628e332fbefdc33d9dbc4377e408d07f59ee576c58d09f47ceaeea9c
|
7
|
+
data.tar.gz: b064e3cf519a2ad476bc5e14ef0f94d6d770331a06901a5aa6bf7490a90f5336f1ee6dc43805ee75305447818c2bcb8c4b0cb0d283ff09f7e0da369b0ea6413a
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# local_json
|
2
|
+
|
3
|
+
Just a tiny little utility because I got tired of constantly typing out code to
|
4
|
+
snarf in a JSON file that is local to a library file.
|
5
|
+
|
6
|
+
To read and parse a JSON file in your library file:
|
7
|
+
|
8
|
+
```
|
9
|
+
filter = local_json('./filter.json')
|
10
|
+
```
|
11
|
+
|
12
|
+
## Install
|
13
|
+
|
14
|
+
```
|
15
|
+
gem install local-json
|
16
|
+
```
|
17
|
+
|
18
|
+
## Author
|
19
|
+
|
20
|
+
Mike O'Sullivan
|
21
|
+
mike@idocs.com
|
22
|
+
|
23
|
+
## History
|
24
|
+
|
25
|
+
| version | date | notes |
|
26
|
+
|----------|--------------|-----------------|
|
27
|
+
| 1.0 | May 16, 2023 | Initial upload. Probably also last upload. |
|
data/lib/local-json.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
# local_json() takes a file path as its single param. It parses the contents of
|
4
|
+
# that file as JSON. The path is relative to the location of the file in which
|
5
|
+
# this method is called.
|
6
|
+
#
|
7
|
+
# If the path is not valid or the file cannot be read, File.read will raise an
|
8
|
+
# exception. If the content of the file is not valid JSON then JSON.parse raises
|
9
|
+
# an exception.
|
10
|
+
|
11
|
+
def local_json(path)
|
12
|
+
dir = File.dirname(caller_locations.first.path)
|
13
|
+
abs_path = File.expand_path(path, dir)
|
14
|
+
return JSON.parse( File.read(abs_path) )
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: local_json
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike O'Sullivan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Slurp in and parse a JSON file relative to a library file.
|
14
|
+
email: mike@idocs.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- README.md
|
20
|
+
- lib/local-json.rb
|
21
|
+
homepage: https://github.com/mikosullivan/local-json
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.1.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Local JSON
|
44
|
+
test_files: []
|