Class: Deckr::Resource

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

Direct Known Subclasses

Deck, Package

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, name) ⇒ Resource

Returns a new instance of Resource.



5
6
7
# File 'lib/deckr/resource.rb', line 5

def initialize(parent, name)
  @parent, @name = parent, name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/deckr/resource.rb', line 3

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



3
4
5
# File 'lib/deckr/resource.rb', line 3

def parent
  @parent
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
35
# File 'lib/deckr/resource.rb', line 31

def ==(other)
  other.respond_to?(:parent) && parent == other.parent &&
    other.respond_to?(:url) && url == other.url &&
    other.respond_to?(:path) && path == other.path
end

#contentObject



21
22
23
24
25
26
27
28
29
# File 'lib/deckr/resource.rb', line 21

def content
  if not exist?
    ""
  elsif RUBY_VERSION >= "1.9"
    IO.read path, :mode => "rb"
  else
    IO.read path
  end
end

#exist?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/deckr/resource.rb', line 17

def exist?
  File.file?(path)
end

#pathObject



13
14
15
# File 'lib/deckr/resource.rb', line 13

def path
  File.join(parent.path, name)
end

#urlObject



9
10
11
# File 'lib/deckr/resource.rb', line 9

def url
  File.join(parent.url, name)
end