pick_and_roll 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/pick_and_roll.rb +69 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 774abf4612a41866f7142754542c30bc1454c18d
|
4
|
+
data.tar.gz: 44186944b8e6f923fe21af174b8bfea81a41aa3b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b68d65792f70fd8a8e852b424bea61740a6d084db4384ecfeae01d93628d597b87e6360a6aa6770ad2664857f34173579e465bfcad37ea7d03230b8ca3cc56b
|
7
|
+
data.tar.gz: 7eba64a649411124541309b456746ec891197853e3c3a9ed336ddf35f18c55f214d3307246fc431c828f4d66b755e30403d70bb30b5ee9dadd734e7217d1cecd
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'hash_deep_merge'
|
3
|
+
#require 'awesome_print'
|
4
|
+
|
5
|
+
class PickAndRoll
|
6
|
+
MASTER_CONFIG = 'config.json'
|
7
|
+
PARCONFIG_FILE_NAME = '.parconfig'
|
8
|
+
|
9
|
+
def initialize(config_path = '')
|
10
|
+
@config_file = config_path.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def pick
|
14
|
+
if File.exist?(MASTER_CONFIG)
|
15
|
+
@config = JSON.parse(File.read(MASTER_CONFIG))
|
16
|
+
puts "pick config: #{MASTER_CONFIG}"
|
17
|
+
else
|
18
|
+
@config = Hash.new
|
19
|
+
end
|
20
|
+
|
21
|
+
if @config_file.strip.empty? == false && File.exists?("#{@config_file}.json")
|
22
|
+
@config.deep_merge!(JSON.parse(File.read("#{@config_file}.json")))
|
23
|
+
puts "pick config: #{@config_file}.json"
|
24
|
+
elsif File.exist?("#{ENV["COMPUTERNAME"]}.json")
|
25
|
+
@config.deep_merge!(JSON.parse(File.read("#{ENV["COMPUTERNAME"]}.json")))
|
26
|
+
puts "pick config: #{ENV["COMPUTERNAME"]}.json"
|
27
|
+
end
|
28
|
+
|
29
|
+
if @config.empty?
|
30
|
+
printf 'Please set configuration path or create config.json file'
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def roll
|
36
|
+
file_patterns = read_file_patterns()
|
37
|
+
|
38
|
+
file_patterns.each {|file_pattern|
|
39
|
+
Dir.glob("**/#{file_pattern}"){ |file_name|
|
40
|
+
File.open(file_name,'r'){ |config_file|
|
41
|
+
puts "roll file: #{file_name}"
|
42
|
+
File.open(file_name.gsub(/\.generic\./,'.'), 'w'){ |f|
|
43
|
+
f.write config_file.read().gsub(/@@([\w\.]*)@@/) {|s| find_config_value $1}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def read_file_patterns
|
51
|
+
file_patterns = Array.new
|
52
|
+
if File.exist?(PARCONFIG_FILE_NAME)
|
53
|
+
File.open(PARCONFIG_FILE_NAME, 'r').each { |line|
|
54
|
+
file_patterns.push(line.strip)
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
file_patterns
|
59
|
+
end
|
60
|
+
|
61
|
+
def find_config_value(key)
|
62
|
+
key.split('.').inject(@config) { |config, name| config[name] }
|
63
|
+
end
|
64
|
+
|
65
|
+
def go
|
66
|
+
pick
|
67
|
+
roll
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pick_and_roll
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dima Salakhov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Creates customizable configuration files
|
14
|
+
email: to@dimasalakhov.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/pick_and_roll.rb
|
20
|
+
homepage: ''
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.0.0
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Configuration helper
|
44
|
+
test_files: []
|