Class: Ace::Support::Nav::Models::Resource
- Inherits:
-
Object
- Object
- Ace::Support::Nav::Models::Resource
- Defined in:
- lib/ace/support/nav/models/resource.rb
Overview
Represents a resource within a handbook
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#resource_path ⇒ Object
readonly
Returns the value of attribute resource_path.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #content ⇒ Object
- #directory? ⇒ Boolean
- #exists? ⇒ Boolean
-
#initialize(uri:, path:, source:, protocol:, resource_path:) ⇒ Resource
constructor
A new instance of Resource.
- #to_h ⇒ Object
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
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/ace/support/nav/models/resource.rb', line 9 def path @path end |
#protocol ⇒ Object (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_path ⇒ Object (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 |
#source ⇒ Object (readonly)
Returns the value of attribute source.
9 10 11 |
# File 'lib/ace/support/nav/models/resource.rb', line 9 def source @source end |
#uri ⇒ Object (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
#content ⇒ Object
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
28 29 30 |
# File 'lib/ace/support/nav/models/resource.rb', line 28 def directory? File.directory?(path) end |
#exists? ⇒ Boolean
24 25 26 |
# File 'lib/ace/support/nav/models/resource.rb', line 24 def exists? File.exist?(path) end |
#to_h ⇒ Object
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 |