Class: VirtualFS::Github

Inherits:
Backend show all
Defined in:
lib/virtualfs/github.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Backend

#cache, #dotfolders_for, #map_entries

Constructor Details

#initialize(opts = {}) ⇒ Github

Returns a new instance of Github.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/virtualfs/github.rb', line 12

def initialize(opts={})
  super opts

  @user = opts.fetch(:user)
  @repo = opts.fetch(:repo)
  @branch = opts.fetch(:branch, 'master')
  auth = opts.fetch(:authentication, {})

  # @gh = ::Github::GitData.new(opts)
  @gh = Octokit::Client.new(auth)
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



10
11
12
# File 'lib/virtualfs/github.rb', line 10

def branch
  @branch
end

#repoObject (readonly)

Returns the value of attribute repo.



10
11
12
# File 'lib/virtualfs/github.rb', line 10

def repo
  @repo
end

#userObject (readonly)

Returns the value of attribute user.



10
11
12
# File 'lib/virtualfs/github.rb', line 10

def user
  @user
end

Instance Method Details

#entries(path = '/') ⇒ Object



24
25
26
27
28
29
30
# File 'lib/virtualfs/github.rb', line 24

def entries(path='/')
  path = '/' << path unless path.start_with? '/'
  p = path[1..-1]

  contents = path == '/' ? toplevel_contents : tree_contents(p)
  dotfolders_for(path) + map_entries(contents.values, :path) { |item| item.type == 'tree' }
end

#glob(pattern, path = '/') ⇒ Object Also known as: []



32
33
34
35
36
37
38
# File 'lib/virtualfs/github.rb', line 32

def glob(pattern, path='/')
  path = '/' << path unless path.start_with? '/'
  p = path[1..-1]

  contents = path == '/' ? internal_items : tree_contents(p, true)
  map_entries(contents.select { |path, _| ::File.fnmatch(pattern, path, ::File::FNM_PATHNAME) }.values, :path) { |item| item.type == 'tree' }
end

#stream_for(path) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/virtualfs/github.rb', line 40

def stream_for(path)
  path = '/' << path unless path.start_with? '/'
  p = path[1..-1]

  item = internal_items.fetch(p)
  raise 'Not a file' unless item.type == 'blob'

  StringIO.new internal_blob(item.sha)
end