Class: Ghundle::Source::Github
- Defined in:
- lib/ghundle/source/github.rb
Overview
Represents a remote hook on github.com. The description is of the format:
github.com/<username>/<repo>/<path/to/hook>
Example:
github.com/AndrewRadev/hooks/
It needs to be fetched to the local hook root in order to use the hook.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#script_name ⇒ Object
readonly
Returns the value of attribute script_name.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #fetch(destination_path) ⇒ Object
- #hook_name ⇒ Object
-
#initialize(description) ⇒ Github
constructor
A new instance of Github.
- #metadata ⇒ Object
- #to_s ⇒ Object
Methods inherited from Common
Constructor Details
#initialize(description) ⇒ Github
Returns a new instance of Github.
21 22 23 24 25 26 |
# File 'lib/ghundle/source/github.rb', line 21 def initialize(description) @description = description @username, @repo, @path = parse_description(@description) @path = Pathname.new(@path) @script_name = path.basename end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
18 19 20 |
# File 'lib/ghundle/source/github.rb', line 18 def path @path end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
18 19 20 |
# File 'lib/ghundle/source/github.rb', line 18 def repo @repo end |
#script_name ⇒ Object (readonly)
Returns the value of attribute script_name.
19 20 21 |
# File 'lib/ghundle/source/github.rb', line 19 def script_name @script_name end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
18 19 20 |
# File 'lib/ghundle/source/github.rb', line 18 def username @username end |
Instance Method Details
#fetch(destination_path) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ghundle/source/github.rb', line 46 def fetch(destination_path) destination_path = Pathname.new(destination_path) local_source = Local.new(destination_path) return local_source if local_source.exists? FileUtils.mkdir_p(destination_path) status, script = http_get(raw_github_url(@path.join('run'))) if status != 200 raise AppError.new("Couldn't fetch script file from #{url}, got response status: #{status}") end destination_path.join('run').open('w') do |f| f.write(script) end destination_path.join('meta.yml').open('w') do |f| f.write(YAML.dump(.to_h)) end File.chmod(0755, destination_path.join('run')) local_source end |
#hook_name ⇒ Object
28 29 30 |
# File 'lib/ghundle/source/github.rb', line 28 def hook_name path.basename end |
#metadata ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ghundle/source/github.rb', line 32 def ||= begin url = raw_github_url(@path.join('meta.yml')) status, yaml = http_get(url) if status != 200 raise AppError.new("Couldn't fetch metadata file from #{url}, got response status: #{status}") end Metadata.new(YAML.load(yaml)) end end |
#to_s ⇒ Object
72 73 74 |
# File 'lib/ghundle/source/github.rb', line 72 def to_s @path end |