Class: Mascot::Resource
- Inherits:
-
Object
- Object
- Mascot::Resource
- Extended by:
- Forwardable
- Defined in:
- lib/mascot/resource.rb
Overview
Represents the request path of an asset. There may be multiple resources that point to the same asset. Resources are immutable and may be altered by the resource proxy.
Constant Summary collapse
- DEFAULT_FILTER_SCOPE =
Default scope for querying parent/child/sibling resources.
:same
Instance Attribute Summary collapse
-
#asset ⇒ Object
readonly
Returns the value of attribute asset.
- #body ⇒ Object
- #data ⇒ Object
-
#ext ⇒ Object
readonly
Returns the value of attribute ext.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #==(resource) ⇒ Object
- #children(**args) ⇒ Object
-
#initialize(asset:, node:, ext: "") ⇒ Resource
constructor
A new instance of Resource.
- #inspect ⇒ Object
- #parents(**args) ⇒ Object
- #request_path ⇒ Object
- #siblings(**args) ⇒ Object
Constructor Details
#initialize(asset:, node:, ext: "") ⇒ Resource
Returns a new instance of Resource.
17 18 19 20 21 |
# File 'lib/mascot/resource.rb', line 17 def initialize(asset: , node: , ext: "") @asset = asset @node = node @ext = ext # TODO: Meh, feels dirty but I suppose the thingy has to drop it in. end |
Instance Attribute Details
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
12 13 14 |
# File 'lib/mascot/resource.rb', line 12 def asset @asset end |
#body ⇒ Object
35 36 37 |
# File 'lib/mascot/resource.rb', line 35 def body @body ||= asset.body end |
#data ⇒ Object
31 32 33 |
# File 'lib/mascot/resource.rb', line 31 def data @data ||= asset.data end |
#ext ⇒ Object (readonly)
Returns the value of attribute ext.
12 13 14 |
# File 'lib/mascot/resource.rb', line 12 def ext @ext end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
12 13 14 |
# File 'lib/mascot/resource.rb', line 12 def node @node end |
Instance Method Details
#==(resource) ⇒ Object
55 56 57 |
# File 'lib/mascot/resource.rb', line 55 def ==(resource) resource.request_path == request_path end |
#children(**args) ⇒ Object
51 52 53 |
# File 'lib/mascot/resource.rb', line 51 def children(**args) filter_resources(**args){ node.children } end |
#inspect ⇒ Object
39 40 41 |
# File 'lib/mascot/resource.rb', line 39 def inspect "<#{self.class}:#{object_id} request_path=#{request_path.inspect} asset_path=#{@asset.path.to_s.inspect}>" end |
#parents(**args) ⇒ Object
43 44 45 |
# File 'lib/mascot/resource.rb', line 43 def parents(**args) filter_resources(**args){ node.parents } end |
#request_path ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/mascot/resource.rb', line 23 def request_path return unless node # TODO: This `compact` makes me nervous. How can we handle this better? lineage = node.parents.reverse.map(&:name).compact file_name = [node.name, @ext].join File.join("/", *lineage, file_name) end |
#siblings(**args) ⇒ Object
47 48 49 |
# File 'lib/mascot/resource.rb', line 47 def siblings(**args) filter_resources(**args){ node.siblings } end |