Class: Ghundle::Source::Directory

Inherits:
Common
  • Object
show all
Defined in:
lib/ghundle/source/directory.rb

Overview

Represents a directory on the filesystem that has a hook-compatible directory structure. It needs to be fetched to the local hook root in order to use the hook.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Common

#fetched?

Constructor Details

#initialize(path) ⇒ Directory

Returns a new instance of Directory.



15
16
17
# File 'lib/ghundle/source/directory.rb', line 15

def initialize(path)
  @source_path = Pathname.new(path)
end

Instance Attribute Details

#source_pathObject (readonly)

Returns the value of attribute source_path.



13
14
15
# File 'lib/ghundle/source/directory.rb', line 13

def source_path
  @source_path
end

Instance Method Details

#fetch(destination_path) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ghundle/source/directory.rb', line 31

def fetch(destination_path)
  validate
  destination_path = Pathname.new(destination_path)

  local_source = Local.new(destination_path)
  return local_source if local_source.exists?

  FileUtils.mkdir_p(destination_path)
  FileUtils.cp source_path.join("meta.yml"), destination_path.join("meta.yml")
  FileUtils.cp source_path.join("run"), destination_path.join("run")

  local_source
end

#hook_nameObject



19
20
21
# File 'lib/ghundle/source/directory.rb', line 19

def hook_name
  @source_path.basename
end

#metadataObject



23
24
25
26
27
28
29
# File 'lib/ghundle/source/directory.rb', line 23

def 
   ||=
    begin
      validate
      .new(YAML.load_file(source_path.join("meta.yml")))
    end
end

#to_sObject



62
63
64
# File 'lib/ghundle/source/directory.rb', line 62

def to_s
  source_path
end

#validateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ghundle/source/directory.rb', line 45

def validate
  source_script_path   = source_path.join('run')
   = source_path.join('meta.yml')

  if not source_script_path.file?
    raise AppError.new("Script not found: #{source_script_path}")
  end

  if not source_script_path.executable?
    raise AppError.new("Script not executable: #{source_script_path}")
  end

  if not .file?
    raise AppError.new("Metadata file not found: #{metadata_source_path}")
  end
end