Class: VirtualFS::Github
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #entries(path = '/') ⇒ Object
- #glob(pattern, path = '/') ⇒ Object (also: #[])
-
#initialize(opts = {}) ⇒ Github
constructor
A new instance of Github.
- #stream_for(path) ⇒ Object
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
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
10 11 12 |
# File 'lib/virtualfs/github.rb', line 10 def branch @branch end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
10 11 12 |
# File 'lib/virtualfs/github.rb', line 10 def repo @repo end |
#user ⇒ Object (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 |