Sha256: ebb3ef0214eb42eab776b77e4a8f193c10299a1545a6c4446f893c480cefd890

Contents?: true

Size: 1.41 KB

Versions: 25

Compression:

Stored size: 1.41 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 set_current_attributes
        exist = run_specinfra(:check_file_is_directory, path)
        @current_attributes[:exist?] = exist

        if exist
          @current_attributes[:mode] = run_specinfra(:get_file_mode, path).stdout.chomp
          @current_attributes[:owner] = run_specinfra(:get_file_owner_user, path).stdout.chomp
          @current_attributes[:group] = run_specinfra(:get_file_owner_group, path).stdout.chomp
        else
          @current_attributes[:mode] = nil
          @current_attributes[:owner] = nil
          @current_attributes[:group] = nil
        end

        if action == :create
          @attributes[:exist?] = true
        end
      end

      def create_action
        if !run_specinfra(:check_file_is_directory, path)
          run_specinfra(:create_file_as_directory, path)
        end
        if attributes[:mode]
          run_specinfra(:change_file_mode, path, attributes[:mode])
        end
        if attributes[:owner] || attributes[:group]
          run_specinfra(:change_file_owner, path, attributes[:owner], attributes[:group])
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
itamae-1.0.0.beta29 lib/itamae/resource/directory.rb
itamae-1.0.0.beta28 lib/itamae/resource/directory.rb
itamae-1.0.0.beta27 lib/itamae/resource/directory.rb
itamae-1.0.0.beta26 lib/itamae/resource/directory.rb
itamae-1.0.0.beta25 lib/itamae/resource/directory.rb
itamae-1.0.0.beta24 lib/itamae/resource/directory.rb
itamae-1.0.0.beta23 lib/itamae/resource/directory.rb
itamae-1.0.0.beta22 lib/itamae/resource/directory.rb
itamae-1.0.0.beta21 lib/itamae/resource/directory.rb
itamae-1.0.0.beta20 lib/itamae/resource/directory.rb
itamae-1.0.0.beta19 lib/itamae/resource/directory.rb
itamae-1.0.0.beta18 lib/itamae/resource/directory.rb
itamae-1.0.0.beta17 lib/itamae/resource/directory.rb
itamae-1.0.0.beta16 lib/itamae/resource/directory.rb
itamae-1.0.0.beta15 lib/itamae/resource/directory.rb
itamae-1.0.0.beta14 lib/itamae/resource/directory.rb
itamae-1.0.0.beta13 lib/itamae/resource/directory.rb
itamae-1.0.0.beta12 lib/itamae/resource/directory.rb
itamae-1.0.0.beta11 lib/itamae/resource/directory.rb
itamae-1.0.0.beta10 lib/itamae/resource/directory.rb