Class: Uniword::Resource::ResourceLocation
- Inherits:
-
Struct
- Object
- Struct
- Uniword::Resource::ResourceLocation
- Defined in:
- lib/uniword/resource/resource_location.rb
Overview
Immutable value object for resource location Does NOT extend Lutaml::Model::Serializable - this is a value object
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#source ⇒ Object
Returns the value of attribute source.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .determine_source(path) ⇒ Object
-
.from_path(type, path) ⇒ Object
Factory from path.
Instance Method Summary collapse
-
#exists? ⇒ Boolean
Check if location is readable.
-
#read ⇒ Object
Read content.
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name
7 8 9 |
# File 'lib/uniword/resource/resource_location.rb', line 7 def name @name end |
#path ⇒ Object
Returns the value of attribute path
7 8 9 |
# File 'lib/uniword/resource/resource_location.rb', line 7 def path @path end |
#source ⇒ Object
Returns the value of attribute source
7 8 9 |
# File 'lib/uniword/resource/resource_location.rb', line 7 def source @source end |
#type ⇒ Object
Returns the value of attribute type
7 8 9 |
# File 'lib/uniword/resource/resource_location.rb', line 7 def type @type end |
Class Method Details
.determine_source(path) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/uniword/resource/resource_location.rb', line 25 def self.determine_source(path) case path when %r{/\.uniword/} then :cached when %r{/data-private/} then :private when %r{/data/} then :bundled else :unknown end end |
.from_path(type, path) ⇒ Object
Factory from path
19 20 21 22 23 |
# File 'lib/uniword/resource/resource_location.rb', line 19 def self.from_path(type, path) name = File.basename(path, ".*") source = determine_source(path) new(type, name, source, path) end |
Instance Method Details
#exists? ⇒ Boolean
Check if location is readable
9 10 11 |
# File 'lib/uniword/resource/resource_location.rb', line 9 def exists? File.exist?(path) end |
#read ⇒ Object
Read content
14 15 16 |
# File 'lib/uniword/resource/resource_location.rb', line 14 def read File.read(path) if exists? end |