Class: Captain::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/captain/resource.rb

Direct Known Subclasses

Template

Defined Under Namespace

Classes: Template

Constant Summary collapse

PATH =
Pathname.new(File.dirname(__FILE__)).join('..', '..', 'resources')

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Resource

Returns a new instance of Resource.



16
17
18
# File 'lib/captain/resource.rb', line 16

def initialize(name)
  @name = name
end

Class Method Details

.file(name) ⇒ Object



8
9
10
# File 'lib/captain/resource.rb', line 8

def self.file(name)
  new(name)
end

.template(name, binding) ⇒ Object



12
13
14
# File 'lib/captain/resource.rb', line 12

def self.template(name, binding)
  Template.new(name, binding)
end

Instance Method Details

#contentsObject



20
21
22
# File 'lib/captain/resource.rb', line 20

def contents
  PATH.join(@name).read
end

#copy_to(*paths) ⇒ Object



24
25
26
27
28
# File 'lib/captain/resource.rb', line 24

def copy_to(*paths)
  path = File.join(paths)
  FileUtils.mkpath(File.dirname(path))
  File.open(path, 'w') { |f| f.write(contents) }
end