Sha256: 78f9d285f36e65619cab510e347849165bac1b1c19835b89db08e21c958e8e61

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

require 'minarai/actions/base'

module Minarai
  module Actions
    class Directory < Base
      attribute :destination, required: true, type: String
      attribute :owner, type: String
      attribute :group, type: String

      def run
        create
        change_group unless has_valid_group?
        change_owner unless has_valid_owner?
      end

      private

      def create
        run_specific_command(:create_file_as_directory, destination)
      end

      def complete?
        existed_file?
      end

      def existed_file?
        check_specific_command(:check_file_is_directory, destination)
      end

      def has_valid_group?
        group.nil? || check_specific_command(:check_file_is_grouped, destination, group)
      end

      def has_valid_owner?
        owner.nil? || check_specific_command(:check_file_is_owned_by, destination, owner)
      end

      def change_group
        run_specific_command(:change_file_group, destination, group)
      end

      def change_owner
        run_specific_command(:change_file_owner, destination, owner)
      end

      def name
        super || "create #{destination} directory"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
minarai-0.0.3 lib/minarai/actions/directory.rb
minarai-0.0.2 lib/minarai/actions/directory.rb
minarai-0.0.1 lib/minarai/actions/directory.rb