jsontemplate 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c6bb416c8e7f40f34ce5b4d98cf739dd2e63ba2
4
- data.tar.gz: a3d9d6d43d1f0f06d93c676433409a86a0f86e00
3
+ metadata.gz: 341367051a162f6aa01706ffa58ea3a298870438
4
+ data.tar.gz: db0ebf309531391d9b8de428582202bbd1cbb746
5
5
  SHA512:
6
- metadata.gz: 6380a11c7a4cca159cb8f7a97457cc30e86a76c78ed92820f286943889fdb577deeacd51dc067df827f0dc100f7da76288cc3bf367cd3e7763eefecae82d97d5
7
- data.tar.gz: 84b91beaf683adebd9562088334dcb954b23bdf20ae6910d4870b350a68adcf810331ddba849750ca811703456e2942da0bbae9b7f92a56a8c68e1d8d9fddf01
6
+ metadata.gz: 49d81e57206b00c714e20f17c88b10089f9f877f41f07469076c09f17b869f7752426151a63e27b68939bd7ddd6e18cd90e20f3e3836f88d51fa2b3117e8ac1e
7
+ data.tar.gz: b2de6bc3d5f681e751e9ff5e0b2bfbb22ee4627aa4f8ce99a93435128d43717a77e69f553d4634fb0c952ba9762172c7ea642aa90a53d61b5f26fdb972f9adda
data/Dockerfile ADDED
@@ -0,0 +1,9 @@
1
+ # -*- sh -*-
2
+ FROM ruby:2.2
3
+
4
+ RUN gem install -n /usr/bin bundler
5
+ RUN gem install -n /usr/bin rake
6
+ ADD bundle_config /usr/local/bundle/config
7
+
8
+ WORKDIR /app
9
+
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jsontemplate (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.1)
10
+ diff-lcs (1.2.5)
11
+ method_source (0.8.2)
12
+ pry (0.10.4)
13
+ coderay (~> 1.1.0)
14
+ method_source (~> 0.8.1)
15
+ slop (~> 3.4)
16
+ rake (10.4.2)
17
+ rspec (3.5.0)
18
+ rspec-core (~> 3.5.0)
19
+ rspec-expectations (~> 3.5.0)
20
+ rspec-mocks (~> 3.5.0)
21
+ rspec-core (3.5.1)
22
+ rspec-support (~> 3.5.0)
23
+ rspec-expectations (3.5.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.5.0)
26
+ rspec-mocks (3.5.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.5.0)
29
+ rspec-support (3.5.0)
30
+ slop (3.6.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 1.9)
37
+ jsontemplate!
38
+ pry
39
+ rake (~> 10.0)
40
+ rspec
41
+
42
+ BUNDLED WITH
43
+ 1.12.5
data/Makefile ADDED
@@ -0,0 +1,4 @@
1
+ NAME=jsontemplate
2
+ IMAGE=dev-${NAME}
3
+
4
+ include Rules.mk
data/Rules.mk ADDED
@@ -0,0 +1,35 @@
1
+ DR=docker run -t -i -v ${PWD}:/app ${IMAGE}
2
+ B=${DR} bundle
3
+ BE=${B} exec
4
+
5
+ build: container
6
+ echo Building gem
7
+ rm -f pkg/*
8
+ ${BE} rake build
9
+
10
+ push: build spec
11
+ gem push `/bin/ls -q pkg/* | tail -n1`
12
+
13
+ container: Dockerfile
14
+ docker build -t ${IMAGE} .
15
+
16
+ update: container
17
+ ${B} update
18
+
19
+ bundle: container
20
+ ${B} install --binstubs ./bin --path=./vendor/bundle
21
+
22
+ rdoc: container
23
+ rm -rf doc
24
+ ${BE} rdoc --main=README.md -O -U -x'~' README.md lib
25
+
26
+ .PHONY: spec
27
+ spec: container
28
+ ${BE} rspec ./spec
29
+
30
+
31
+ cli:
32
+ ${DR} /bin/bash -l
33
+
34
+ pry:
35
+ ${BE} pry -r bundler/setup -r jsontemplate
data/bin/console CHANGED
File without changes
data/bundle_config ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ BUNDLE_PATH: "./vendor/bundle"
3
+ BUNDLE_DISABLE_SHARED_GEMS: true
data/jsontemplate.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
 
22
+ spec.add_development_dependency "pry"
22
23
  spec.add_development_dependency "rspec"
23
24
  spec.add_development_dependency "bundler", "~> 1.9"
24
25
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,3 +1,3 @@
1
1
  class JsonTemplate
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/jsontemplate.rb CHANGED
@@ -2,21 +2,31 @@ require 'json'
2
2
  require "jsontemplate/version"
3
3
 
4
4
  class JsonTemplate
5
- def initialize(path)
6
- @path = path
7
- @dir = File.dirname(path)
8
- @json = JSON.load(File.read(path))
5
+ attr_reader :json
6
+
7
+ def initialize(src, path=nil)
8
+ path ||= src.kind_of?(String) ? src : nil
9
+ @path = path || (src.respond_to?(:path) ? src.path : nil)
10
+ @dir = File.expand_path(path ? File.dirname(path) : ".")
11
+
12
+ data = src.respond_to?(:read) ? src.read : File.read(src)
13
+ @json = JSON.load(data)
9
14
  end
10
15
 
11
16
  def process_dirmerge(pattern)
12
17
  files = Dir.glob(@dir+"/"+pattern)
13
18
  files.collect do |path|
14
- r = JsonTemplate.new(path).process_dict
19
+ r = JsonTemplate.new(path,@path).process_dict
15
20
  key=File.basename(path).split(".")[0..-2].join(".")
16
21
  [key, r]
17
22
  end.flatten(1)
18
23
  end
19
24
 
25
+ def process_flookup(file, v)
26
+ map = JsonTemplate.new(file,@path).process_dict
27
+ map[v]
28
+ end
29
+
20
30
  def process_dict(root=nil)
21
31
  root ||= @json
22
32
 
@@ -27,13 +37,19 @@ class JsonTemplate
27
37
 
28
38
  if k == "$DirMerge"
29
39
  process_dirmerge(v)
40
+ elsif k == "$FLookup"
41
+ process_flookup(*v)
30
42
  elsif k[0] == "$"
31
43
  raise "Unknown directive #{k}"
32
44
  else
33
- [[k,v]]
45
+ [k,v]
34
46
  end
35
47
  end
36
- Hash[*pairs.flatten(2)]
48
+ if pairs.length == 1 && !pairs.first.kind_of?(Array)
49
+ pairs.first
50
+ else
51
+ Hash[*pairs.flatten(1)]
52
+ end
37
53
  end
38
54
  end
39
55
 
data/parameters.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "key1": "value1"
3
+ }
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsontemplate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vidar Hokstad
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-14 00:00:00.000000000 Z
11
+ date: 2016-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
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'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rspec
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -63,16 +77,22 @@ files:
63
77
  - ".gitignore"
64
78
  - ".rspec"
65
79
  - ".travis.yml"
80
+ - Dockerfile
66
81
  - Gemfile
82
+ - Gemfile.lock
67
83
  - LICENSE
84
+ - Makefile
68
85
  - README.md
69
86
  - Rakefile
87
+ - Rules.mk
70
88
  - bin/console
71
89
  - bin/setup
90
+ - bundle_config
72
91
  - exe/jsontemplate
73
92
  - jsontemplate.gemspec
74
93
  - lib/jsontemplate.rb
75
94
  - lib/jsontemplate/version.rb
95
+ - parameters.json
76
96
  homepage: https://github.com/hokstadconsulting/jsontemplate
77
97
  licenses: []
78
98
  metadata: {}