Class: Ghundle::Source::Local

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

Overview

Represents the local source of a hook. This means that the hook has already been fetched to a local directory where it can easily be installed in a repository.

Instance Method Summary collapse

Methods inherited from Common

#fetched?, #hook_name

Constructor Details

#initialize(local_path) ⇒ Local

Returns a new instance of Local.



12
13
14
# File 'lib/ghundle/source/local.rb', line 12

def initialize(local_path)
  @local_path = Pathname.new(local_path)
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ghundle/source/local.rb', line 36

def exists?
  script_path.executable? and .file?
end

#fetchObject



45
46
47
# File 'lib/ghundle/source/local.rb', line 45

def fetch
  self
end

#metadataObject



40
41
42
43
# File 'lib/ghundle/source/local.rb', line 40

def 
  validate
  .from_yaml()
end

#metadata_pathObject



53
54
55
# File 'lib/ghundle/source/local.rb', line 53

def 
  @local_path.join('meta.yml')
end

#nameObject



16
17
18
# File 'lib/ghundle/source/local.rb', line 16

def name
  @local_path.basename.to_s
end

#script_pathObject



49
50
51
# File 'lib/ghundle/source/local.rb', line 49

def script_path
  @local_path.join('run')
end

#validateObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ghundle/source/local.rb', line 20

def validate
  return if exists?

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

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

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