Class: Ace::Support::Nav::Models::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/nav/models/resource.rb

Overview

Represents a resource within a handbook

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri:, path:, source:, protocol:, resource_path:) ⇒ Resource

Returns a new instance of Resource.



11
12
13
14
15
16
17
# File 'lib/ace/support/nav/models/resource.rb', line 11

def initialize(uri:, path:, source:, protocol:, resource_path:)
  @uri = uri
  @path = path
  @source = source
  @protocol = protocol
  @resource_path = resource_path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/ace/support/nav/models/resource.rb', line 9

def path
  @path
end

#protocolObject (readonly)

Returns the value of attribute protocol.



9
10
11
# File 'lib/ace/support/nav/models/resource.rb', line 9

def protocol
  @protocol
end

#resource_pathObject (readonly)

Returns the value of attribute resource_path.



9
10
11
# File 'lib/ace/support/nav/models/resource.rb', line 9

def resource_path
  @resource_path
end

#sourceObject (readonly)

Returns the value of attribute source.



9
10
11
# File 'lib/ace/support/nav/models/resource.rb', line 9

def source
  @source
end

#uriObject (readonly)

Returns the value of attribute uri.



9
10
11
# File 'lib/ace/support/nav/models/resource.rb', line 9

def uri
  @uri
end

Instance Method Details

#contentObject



19
20
21
22
# File 'lib/ace/support/nav/models/resource.rb', line 19

def content
  return nil unless File.exist?(path)
  File.read(path)
end

#directory?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/ace/support/nav/models/resource.rb', line 28

def directory?
  File.directory?(path)
end

#exists?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ace/support/nav/models/resource.rb', line 24

def exists?
  File.exist?(path)
end

#to_hObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/ace/support/nav/models/resource.rb', line 32

def to_h
  {
    uri: uri,
    path: path,
    source: source.to_h,
    protocol: protocol,
    resource_path: resource_path,
    exists: exists?
  }
end