Use awesome_print for printing Ruby objects

This commit is contained in:
Balasankar "Balu" C 2018-02-24 15:14:19 +05:30
parent ef70511f40
commit 761a1e6a90
8 changed files with 52 additions and 10 deletions

View File

@ -77,6 +77,7 @@ dependency 'redis'
dependency 'nginx'
dependency 'mixlib-log'
dependency 'chef-zero'
dependency 'awesome_print'
dependency 'ohai'
dependency 'chef-gem'
dependency 'remote-syslog'

View File

@ -0,0 +1,32 @@
#
# Copyright 2016 GitLab Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name 'awesome_print'
default_version '1.8.0'
license 'MIT'
license_file "https://github.com/awesome-print/awesome_print/blob/v#{version}/LICENSE"
dependency 'ruby'
dependency 'rubygems'
build do
env = with_standard_compiler_flags(with_embedded_path)
gem 'install awesome_print' \
" --version '#{version}'" \
' --no-ri --no-rdoc', env: env
end

View File

@ -16,9 +16,12 @@
#
require 'chef/mash'
require_relative '../../package/libraries/helpers/output_helper.rb'
module Gitaly
class << self
include OutputHelper
def parse_variables
parse_git_data_dirs
parse_gitaly_storages
@ -54,7 +57,7 @@ module Gitaly
Your #{deprecated_key_used} settings are deprecated.
Please update it to the following:
git_data_dirs(#{Chef::JSONCompat.to_json_pretty(converted_git_data_dirs)})
git_data_dirs(#{print_ruby_object(converted_git_data_dirs)})
Please refer to https://docs.gitlab.com/omnibus/settings/configuration.html#storing-git-data-in-an-alternative-directory for updated documentation.
EOS

View File

@ -20,5 +20,5 @@ require 'digest'
require_relative 'helpers/redhat_helper'
require_relative 'helpers/secrets_helper'
require_relative 'helpers/version_helper'
require_relative 'helpers/quote_helper'
require_relative 'helpers/output_helper'
require_relative 'helpers/logging_helper'

View File

@ -0,0 +1,11 @@
require 'awesome_print'
module OutputHelper
def quote(string)
string.to_s.inspect unless string.nil?
end
def print_ruby_object(object)
object.ai(plain: true)
end
end

View File

@ -1,5 +0,0 @@
module QuoteHelper
def quote(string)
string.to_s.inspect unless string.nil?
end
end

View File

@ -28,7 +28,7 @@ property :group, String
property :mode, String
property :cookbook, String
property :variables, Hash, default: {}
property :helpers, Module, default: QuoteHelper
property :helpers, Module, default: OutputHelper
property :restarts, Array, default: []
action :create do

View File

@ -1,7 +1,7 @@
require 'chef_helper'
describe QuoteHelper do
include QuoteHelper
describe OutputHelper do
include OutputHelper
describe "#quote" do
context 'handling nil' do