Class: Wright::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/wright/resource.rb,
lib/wright/resource/file.rb,
lib/wright/resource/package.rb,
lib/wright/resource/symlink.rb,
lib/wright/resource/directory.rb

Overview

Public: Resource base class.

Direct Known Subclasses

Directory, File, Package, Symlink

Defined Under Namespace

Classes: Directory, File, Package, Symlink

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ Resource

Public: Initialize a Resource.

name - The resource’s name.



12
13
14
15
16
17
18
19
# File 'lib/wright/resource.rb', line 12

def initialize(name = nil)
  @name = name
  @resource_name = Util.class_to_resource_name(self.class).to_sym
  @provider = provider_for_resource
  @action = nil
  @on_update = nil
  @ignore_failure = false
end

Instance Attribute Details

#actionObject

Public: Get/Set the name Symbol of the method to be run by run_action.



22
23
24
# File 'lib/wright/resource.rb', line 22

def action
  @action
end

#ignore_failureObject

Public: Get/Set the ignore_failure attribute.



25
26
27
# File 'lib/wright/resource.rb', line 25

def ignore_failure
  @ignore_failure
end

#nameObject

Public: Get/Set the resource’s name attribute.

Examples

foo = Wright::Resource::Symlink.new('/tmp/fstab')
foo.name
# => "/tmp/fstab"

bar = Wright::Resource::Symlink.new
bar.name = '/tmp/passwd'
bar.name
# => "/tmp/passwd"


39
40
41
# File 'lib/wright/resource.rb', line 39

def name
  @name
end

#resource_nameObject (readonly)

Public: Returns a compact resource name Symbol.

Examples

foo = Wright::Resource::Symlink.new
foo.resource_name
# => :symlink


48
49
50
# File 'lib/wright/resource.rb', line 48

def resource_name
  @resource_name
end

Instance Method Details

#on_update=(on_update) ⇒ Object

Public: Set an update action for a resource.

on_update - The block that is called if the resource is

updated. Has to respond to :call.

Returns nothing. Raises ArgumentError if on_update is not callable



57
58
59
60
61
62
63
# File 'lib/wright/resource.rb', line 57

def on_update=(on_update)
  if on_update.respond_to?(:call) || on_update.nil?
    @on_update = on_update
  else
    fail ArgumentError, "#{on_update} is not callable"
  end
end

#run_actionObject

Public: Run the resource’s current action.

Examples

fstab = Wright::Resource::Symlink.new('/tmp/fstab')
fstab.action = :remove
fstab.run_action


72
73
74
# File 'lib/wright/resource.rb', line 72

def run_action
  send @action if @action
end