Skip to content

Commit

Permalink
allow projects in confg to define parents
Browse files Browse the repository at this point in the history
  • Loading branch information
greeneca committed Jun 13, 2016
1 parent d2658ea commit bf6b69e
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
roku_builder (3.6.2)
roku_builder (3.6.3)
faraday (~> 0.9)
faraday-digestauth (~> 0.2)
git (~> 1.3)
Expand Down
9 changes: 8 additions & 1 deletion lib/roku_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ module RokuBuilder
IDENTICAL_SIDELOAD = 13
end

class String
class ::String
def underscore
word = self.dup
word.gsub!(/::/, '/')
Expand All @@ -147,3 +147,10 @@ def underscore
word
end
end

class ::Hash
def deep_merge(second)
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
self.merge(second, &merger)
end
end
9 changes: 9 additions & 0 deletions lib/roku_builder/config_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ def self.get_config(config:, logger:)
value[:stage_method] = value[:stage_method].to_sym
end
end
config[:projects].each_pair do |key, value|
unless key == :default
if value[:parent] and config[:projects][value[:parent].to_sym]
new_value = config[:projects][value[:parent].to_sym]
new_value = new_value.deep_merge value
config[:projects][key] = new_value
end
end
end
config
rescue JSON::ParserError
logger.fatal "Config file is not valid JSON"
Expand Down
8 changes: 5 additions & 3 deletions lib/roku_builder/config_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ def self.validate_config(config:)
config[:projects].each {|project,project_config|
next if project == :default
validate_project(codes: codes, project: project_config)
project_config[:stages].each {|_stage, stage_config|
validate_stage(codes: codes, stage: stage_config, project: project_config)
}
if project_config[:stages]
project_config[:stages].each {|_stage, stage_config|
validate_stage(codes: codes, stage: stage_config, project: project_config)
}
end
}
end
codes.uniq!
Expand Down
2 changes: 1 addition & 1 deletion lib/roku_builder/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

module RokuBuilder
# Version of the RokuBuilder Gem
VERSION = "3.6.2"
VERSION = "3.6.3"
end
15 changes: 15 additions & 0 deletions tests/roku_builder/config_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,19 @@ def test_config_manager_edit_default_stage
io.verify
end

def test_config_manager_parent_config
logger = Logger.new("/dev/null")
target_config = File.join(File.dirname(__FILE__), "test_files", "controller_test", "configure_test.json")
File.delete(target_config) if File.exist?(target_config)
FileUtils.cp(File.join(File.dirname(target_config), "parent_config.json"), target_config)

options = {validate: true, config: target_config, stage: :production}
code, config, configs = RokuBuilder::ConfigManager.load_config(options: options, logger: logger)
assert_equal RokuBuilder::SUCCESS, code
assert_equal "app2", config[:projects][:p2][:app_name]
assert_equal "/dev/null", config[:projects][:p2][:directory]
assert_equal 2, config[:projects][:p2][:files].count
assert_equal 2, config[:projects][:p2][:folders].count
end

end
34 changes: 34 additions & 0 deletions tests/roku_builder/test_files/controller_test/configure_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"devices": {
"default": "roku",
"roku": {
"ip": "111.222.333.444",
"user": "user",
"password": "pass"
}
},
"projects": {
"default": "p1",
"p1": {
"directory": "/dev/null",
"folders": ["resources","source"],
"files": ["manifest"],
"app_name": "app",
"stage_method": "git",
"stages":{
"production": {
"branch": "master",
"key": {
"keyed_pkg": "/dev/null",
"password": "password"
}
}
}
},
"p2": {
"parent": "p1",
"app_name": "app2",
"files": ["manifest", "config.json"]
}
}
}
34 changes: 34 additions & 0 deletions tests/roku_builder/test_files/controller_test/parent_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"devices": {
"default": "roku",
"roku": {
"ip": "111.222.333.444",
"user": "user",
"password": "pass"
}
},
"projects": {
"default": "p1",
"p1": {
"directory": "/dev/null",
"folders": ["resources","source"],
"files": ["manifest"],
"app_name": "app",
"stage_method": "git",
"stages":{
"production": {
"branch": "master",
"key": {
"keyed_pkg": "/dev/null",
"password": "password"
}
}
}
},
"p2": {
"parent": "p1",
"app_name": "app2",
"files": ["manifest", "config.json"]
}
}
}

0 comments on commit bf6b69e

Please sign in to comment.