Sha256: e374c453223d33b8951e211048365ecec3ccfae94abab8d8eb06a9f6c5576207

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

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

module Wright
  class Resource
    # Public: Symlink resource, represents a symlink.
    #
    # Examples
    #
    #   file = Wright::Resource::File.new('/tmp/foo')
    #   file.content = 'bar'
    #   file.create
    class File < Wright::Resource
      # Public: Get/Set the file's content.
      attr_accessor :content

      # Public: Get/Set the file's group.
      attr_accessor :group

      # Public: Get/Set the file's mode.
      attr_accessor :mode

      # Public: Get the file's owner.
      attr_reader :owner

      # Public: Initialize a File.
      #
      # name - The file's name.
      def initialize(name)
        super
        @content = nil
        @mode = nil
        @owner = nil
        @group = nil
        @action = :create
      end

      # Public: Set 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

      # Public: Create or update the File.
      #
      # Returns true if the file was updated and false otherwise.
      def create
        might_update_resource do
          @provider.create
        end
      end

      # Public: Remove the File.
      #
      # Returns 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

2 entries across 2 versions & 1 rubygems

Version Path
wright-0.1.1 lib/wright/resource/file.rb
wright-0.1.0 lib/wright/resource/file.rb