Sha256: 16d4ebae168d7dc19d60a64f757d1ec84b78315edb70f38a84b34f2d75ae0e9f

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require 'rainbow'
module Codeguard
  class Install
    extend Forwardable
    attr_accessor :lint

    def self.perform(lint)
      new(lint).tap(&:perform)
    end

    def initialize(lint)
      @lint = lint
    end

    def perform
      output = config_gem_path.read
      prepare_dir
      output = if write_to_file(config_project_path, output)
                 "File: #{config_project_path} was updated!"
               else
                 "File: #{config_project_path} was created!"
               end
      puts Rainbow(output).green
    end

    private

    def prepare_dir
      dir = config_project_path.to_s[%r{(.*)\/[\w\.-]*}, 1]
      FileUtils.mkdir_p(dir) unless dir.nil?
    end

    def write_to_file(path, content)
      if (updating = File.exist?(path))
        FileUtils.chmod 'a+w', path
      end
      File.open(path, 'w+') { |f| f.write(content) }
      FileUtils.chmod 'a-w', path
      updating
    end

    def_delegators :lint, :config_project_path, :config_gem_path
  end # class Install
end # module Codeguard

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
codeguard-0.3.0 lib/codeguard/install.rb
codeguard-0.2.0 lib/codeguard/install.rb