Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Commit

Permalink
Refactor: move yaml generation
Browse files Browse the repository at this point in the history
  • Loading branch information
till committed May 22, 2015
1 parent e4a0733 commit f8ab6cc
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
14 changes: 9 additions & 5 deletions bibcd/providers/app.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
require 'yaml'

action :add do
unless ::File.exist?("#{new_resource.path}/config/apps/#{new_resource.app_name}.yml")
Chef::Log.info "Adding #{new_resource.app_name} config to #{new_resource.path}/config/apps/#{new_resource.app_name}.yml"

template "#{new_resource.path}/config/apps/#{new_resource.app_name}.yml" do
cookbook 'bibcd' # if we dont set this, the template cmd would search in the calling cookbook
yml_file = "#{new_resource.path}/config/apps/#{new_resource.app_name}.yml"

unless ::File.exist?(yml_file)
Chef::Log.info "Adding #{new_resource.app_name} config to #{yml_file}"
Chef::Resource.send(:include, ::EasyBib::Php)

template yml_file do
cookbook 'bibcd'
mode 0644
variables :content => ::EasyBib.to_php_yaml(new_resource.config.to_hash)
variables :content => to_php_yaml(new_resource.config.to_hash)
source 'app.yml.erb'
end

Expand Down
4 changes: 3 additions & 1 deletion easybib-deploy/recipes/qa.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
include_recipe 'php-fpm::service'
include_recipe 'nginx-app::service'

Chef::Resource.send(:include, EasyBib::Php)

node['deploy'].each do |application, deploy|

case application
Expand Down Expand Up @@ -48,7 +50,7 @@
template "#{deploy['deploy_to']}/current/config/deployconfig.yml" do
source 'empty.erb'
mode 0644
variables :content => ::EasyBib.to_php_yaml(node['bibcd']['default'])
variables :content => to_php_yaml(node['bibcd']['default'])
end

node['bibcd']['apps'].each do |appname, config|
Expand Down
12 changes: 12 additions & 0 deletions easybib/libraries/php.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module EasyBib
module Php
def to_php_yaml(obj)
# This is an ugly quick hack: Ruby Yaml adds object info !map:Chef::Node::ImmutableMash which
# the Symfony Yaml parser doesnt like. So lets remove it. First Chef 11.4/Ruby 1.8,
# then Chef 11.10/Ruby 2.0
yaml = YAML.dump(obj)
content = yaml.gsub('!map:Chef::Node::ImmutableMash', '')
content.gsub('!ruby/hash:Chef::Node::ImmutableMash', '')
end
end
end
7 changes: 0 additions & 7 deletions easybib/tests/test_easybib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
class TestEasyBib < Test::Unit::TestCase
include EasyBib

def test_to_php_json
assert_equal(
"--- \nBLA: \n",
to_php_yaml(Chef::Node::ImmutableMash.new(['BLA']))
)
end

def test_use_aptly_mirror
fake_node = Chef::Node.new
assert_equal(
Expand Down
14 changes: 14 additions & 0 deletions easybib/tests/test_php.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'test/unit'
require 'chef'
require File.join(File.dirname(__FILE__), '../libraries', 'php.rb')

class TestPhp < Test::Unit::TestCase
include EasyBib::Php

def test_to_php_json
assert_equal(
"--- \nBLA: \n",
to_php_yaml(Chef::Node::ImmutableMash.new(['BLA']))
)
end
end

0 comments on commit f8ab6cc

Please sign in to comment.