Sha256: 6c37252e45e94a9d006299ae34f6f820cf34dd4a835ff3d3471ef40dd918867d

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

#   Copyright 2017 Bloomberg Finance, L.P.
#
#   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.

module Umami
  module Helper
    module FileTools

    require 'fileutils'
    require 'rubocop'

    def write_file(path = nil, content = '')
      parent_dir = File.dirname(path)
      FileUtils.mkdir_p(parent_dir) unless ::File.exist?(parent_dir)
      f = File.open(path, 'w') # Write with prejudice.
      f.write(content)
      f.close
    end

    # Call Rubocop to ensure proper indentation and thus legibility.
    def enforce_styling(path = 'spec/umami/')
      puts "Running Rubocop over '#{path}' to enforce styling..."
      r = RuboCop::CLI.new
      # Don't output to STDOUT.
      args = [
        '--only', 'Style/IndentationWidth,Style/IndentationConsistency',
        '--auto-correct',
        '--out', '/dev/null',
        path
      ]
      r.run(args)
    end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chef-umami-0.0.4 lib/chef-umami/helpers/filetools.rb
chef-umami-0.0.3 lib/chef-umami/helpers/filetools.rb