Sha256: a35a2b60345e273dc34136ec15585c35106d42ba6abe21c2da9139ee7fab2b26

Contents?: true

Size: 1.89 KB

Versions: 90

Compression:

Stored size: 1.89 KB

Contents

require 'itamae-mitsurin'

module ItamaeMitsurin
  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
        when :delete
          attributes.exist = false
        end
      end

      def show_differences
        current.mode    = current.mode.rjust(4, '0') if current.mode
        attributes.mode = attributes.mode.rjust(4, '0') if attributes.mode

        super
      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

      def action_delete(options)
        if run_specinfra(:check_file_is_directory, attributes.path)
          run_specinfra(:remove_file, attributes.path)
        end
      end
    end
  end
end

Version data entries

90 entries across 47 versions & 1 rubygems

Version Path
itamae-mitsurin-1.0.3 lib/itamae-mitsurin/resource/directory.rb
itamae-mitsurin-1.0.2 lib/itamae-mitsurin/resource/directory.rb
itamae-mitsurin-1.0.1 lib/itamae-mitsurin/resource/directory.rb
itamae-mitsurin-1.0.0 lib/itamae-mitsurin/resource/directory.rb
itamae-mitsurin-0.50 lib/itamae-mitsurin/resource/directory.rb
itamae-mitsurin-0.50 test/test_itamae-mitsurin/resource/test_directory.rb
itamae-mitsurin-0.49 lib/itamae-mitsurin/resource/directory.rb
itamae-mitsurin-0.49 test/test_itamae-mitsurin/resource/test_directory.rb
itamae-mitsurin-0.48 lib/itamae-mitsurin/resource/directory.rb
itamae-mitsurin-0.48 test/test_itamae-mitsurin/resource/test_directory.rb
itamae-mitsurin-0.47 lib/itamae-mitsurin/resource/directory.rb
itamae-mitsurin-0.47 test/test_itamae-mitsurin/resource/test_directory.rb
itamae-mitsurin-0.46 lib/itamae-mitsurin/resource/directory.rb
itamae-mitsurin-0.46 test/test_itamae-mitsurin/resource/test_directory.rb
itamae-mitsurin-0.45 lib/itamae-mitsurin/resource/directory.rb
itamae-mitsurin-0.45 test/test_itamae-mitsurin/resource/test_directory.rb
itamae-mitsurin-0.44 lib/itamae-mitsurin/resource/directory.rb
itamae-mitsurin-0.44 test/test_itamae-mitsurin/resource/test_directory.rb
itamae-mitsurin-0.43 lib/itamae-mitsurin/resource/directory.rb
itamae-mitsurin-0.43 test/test_itamae-mitsurin/resource/test_directory.rb