Class: Geoloader::Assets::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/geoloader/assets/asset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, workspace, desc_path) ⇒ Asset

Set the basename and workspace-prefixed uuid, parse the description.

Parameters:

  • file_path (String)
  • workspace (String)
  • desc_path (String)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/geoloader/assets/asset.rb', line 18

def initialize(file_path, workspace, desc_path)

  @file_path = File.expand_path(file_path)
  @workspace = workspace

  # File name, with and without extension.
  @file_base = File.basename(@file_path, ".*")
  @file_name = File.basename(@file_path)

  # Parse the markdown metadata.
  @description = Description.new(desc_path)

  # Set a workspace-prefixed uuid.
  @uuid = "#{@workspace}_#{@file_base}"

end

Instance Attribute Details

#file_baseObject (readonly)

Returns the value of attribute file_base.



9
10
11
# File 'lib/geoloader/assets/asset.rb', line 9

def file_base
  @file_base
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



9
10
11
# File 'lib/geoloader/assets/asset.rb', line 9

def file_name
  @file_name
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



9
10
11
# File 'lib/geoloader/assets/asset.rb', line 9

def file_path
  @file_path
end

#uuidObject (readonly)

Returns the value of attribute uuid.



9
10
11
# File 'lib/geoloader/assets/asset.rb', line 9

def uuid
  @uuid
end

#workspaceObject (readonly)

Returns the value of attribute workspace.



9
10
11
# File 'lib/geoloader/assets/asset.rb', line 9

def workspace
  @workspace
end

Instance Method Details

#stageObject

Create working copies, yield to a block, remove the copies.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/geoloader/assets/asset.rb', line 38

def stage

  @tempdir = Dir.mktmpdir

  begin

    # Copy the assets into the temp dir.
    files = Dir.glob("#{File.dirname(@file_path)}/#{@file_base}.*")
    FileUtils.cp(files, @tempdir)

    # Change into the temp dir.
    FileUtils.cd(@tempdir) do yield end

  ensure

    # Delete the copies.
    FileUtils.remove_entry @tempdir

  end

end