Sha256: 4c869960b8f9220ae20dff0719367f61726811f1b711ee890e713a934feae7de

Contents?: true

Size: 1.45 KB

Versions: 45

Compression:

Stored size: 1.45 KB

Contents

require 'itamae'

module Itamae
  module Resource
    class Directory < Base
      define_attribute :action, default: :create
      define_attribute :path, type: String, default_name: true
      define_attribute :mode, type: String
      define_attribute :owner, type: String
      define_attribute :group, type: String

      def pre_action
        case @current_action
        when :create
          attributes.exist = true
        end
      end

      def set_current_attributes
        exist = run_specinfra(:check_file_is_directory, attributes.path)
        current.exist = exist

        if exist
          current.mode = run_specinfra(:get_file_mode, attributes.path).stdout.chomp
          current.owner = run_specinfra(:get_file_owner_user, attributes.path).stdout.chomp
          current.group = run_specinfra(:get_file_owner_group, attributes.path).stdout.chomp
        else
          current.mode = nil
          current.owner = nil
          current.group = nil
        end
      end

      def action_create(options)
        if !run_specinfra(:check_file_is_directory, attributes.path)
          run_specinfra(:create_file_as_directory, attributes.path)
        end
        if attributes.mode
          run_specinfra(:change_file_mode, attributes.path, attributes.mode)
        end
        if attributes.owner || attributes.group
          run_specinfra(:change_file_owner, attributes.path, attributes.owner, attributes.group)
        end
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
itamae-1.0.0.beta46 lib/itamae/resource/directory.rb
itamae-1.0.0.beta45 lib/itamae/resource/directory.rb
itamae-1.0.0.beta44 lib/itamae/resource/directory.rb
itamae-1.0.0.beta43 lib/itamae/resource/directory.rb
itamae-1.0.0.beta42 lib/itamae/resource/directory.rb