Sha256: 7ddf98eb6654e124f7464adb10c410b1543575df94ccf2d500527dd30f29c81b

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

require 'wright/resource'
require 'wright/dsl'

module Wright
  class Resource
    # Symlink resource, represents a symlink.
    #
    # @example
    #   file = Wright::Resource::File.new('/tmp/foo')
    #   file.content = 'bar'
    #   file.create
    class File < Wright::Resource
      # @return [String] the file's intended content
      attr_accessor :content

      # @return [String] the file's intended group
      attr_accessor :group

      # @return [String, Integer] the file's intended mode
      attr_accessor :mode

      # @return [String] the file's intended owner
      attr_reader :owner

      # Initializes a File.
      #
      # @param name [String] the file's name
      def initialize(name)
        super
        @content = nil
        @mode = nil
        @owner = nil
        @group = nil
        @action = :create
      end

      # Sets the file's owner.
      def owner=(owner)
        target_owner, target_group =
          Wright::Util::User.owner_to_owner_group(owner)
        @owner = target_owner unless target_owner.nil?
        @group = target_group unless target_group.nil?
      end

      # Creates or updates the file.
      #
      # @return [Bool] true if the file was updated and false
      #   otherwise
      def create
        might_update_resource do
          @provider.create
        end
      end

      # Removes the file.
      #
      # @return [Bool] true if the file was updated and false
      #   otherwise
      def remove
        might_update_resource do
          @provider.remove
        end
      end
    end
  end
end

Wright::DSL.register_resource(Wright::Resource::File)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wright-0.2.0 lib/wright/resource/file.rb