Class: Uniword::Resource::ResourceLocation

Inherits:
Struct
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



7
8
9
# File 'lib/uniword/resource/resource_location.rb', line 7

def name
  @name
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



7
8
9
# File 'lib/uniword/resource/resource_location.rb', line 7

def path
  @path
end

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



7
8
9
# File 'lib/uniword/resource/resource_location.rb', line 7

def source
  @source
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of 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

Returns:

  • (Boolean)


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

def exists?
  File.exist?(path)
end

#readObject

Read content



14
15
16
# File 'lib/uniword/resource/resource_location.rb', line 14

def read
  File.read(path) if exists?
end