Class: Roast::Resources::BaseResource

Inherits:
Object
  • Object
show all
Defined in:
lib/roast/resources/base_resource.rb

Overview

Base class for all resource types Follows the Strategy pattern to handle different resource types in a polymorphic way

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ BaseResource

Initialize a resource with a target

Parameters:

  • target (String)

    The target specified in the workflow, can be nil



12
13
14
# File 'lib/roast/resources/base_resource.rb', line 12

def initialize(target)
  @target = target
end

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



8
9
10
# File 'lib/roast/resources/base_resource.rb', line 8

def target
  @target
end

Instance Method Details

#contentsString

Get the contents of the resource

Returns:

  • (String)

    The contents of the resource



30
31
32
# File 'lib/roast/resources/base_resource.rb', line 30

def contents
  nil # Override in subclasses
end

#exists?Boolean

Check if the resource exists

Returns:

  • (Boolean)

    true if the resource exists



24
25
26
# File 'lib/roast/resources/base_resource.rb', line 24

def exists?
  false # Override in subclasses
end

#nameString

Get a name for the resource to display in logs

Returns:

  • (String)

    A descriptive name for the resource



36
37
38
# File 'lib/roast/resources/base_resource.rb', line 36

def name
  target || "Unnamed Resource"
end

#processString

Process the resource to prepare it for use

Returns:

  • (String)

    The processed target



18
19
20
# File 'lib/roast/resources/base_resource.rb', line 18

def process
  target
end

#typeSymbol

Get the type of this resource as a symbol

Returns:

  • (Symbol)

    The resource type



42
43
44
# File 'lib/roast/resources/base_resource.rb', line 42

def type
  :unknown
end