Class: Glean::Dataset

Inherits:
Object
  • Object
show all
Defined in:
lib/glean/dataset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, dir = "~") ⇒ Dataset

Returns a new instance of Dataset.



5
6
7
8
9
# File 'lib/glean/dataset.rb', line 5

def initialize(identifier, dir="~")
  @identifier = Glean::Source.resolve_identifier(identifier)
  @dir = dir
  sync
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



3
4
5
# File 'lib/glean/dataset.rb', line 3

def identifier
  @identifier
end

Instance Method Details

#eachObject



33
34
35
36
37
# File 'lib/glean/dataset.rb', line 33

def each
  Dir.glob(File.join(path, "**", "*.toml")) do |f|
    yield Hashie::Mash.new(TOML.load_file(f))
  end
end

#pathObject



15
16
17
# File 'lib/glean/dataset.rb', line 15

def path
  File.join(storage_path, identifier)
end

#repo_urlObject



19
20
21
# File 'lib/glean/dataset.rb', line 19

def repo_url
  "http://github.com/#{identifier}"
end

#storage_pathObject



11
12
13
# File 'lib/glean/dataset.rb', line 11

def storage_path
  File.join(File.expand_path(@dir), ".glean")
end

#syncObject



23
24
25
26
27
28
29
30
31
# File 'lib/glean/dataset.rb', line 23

def sync
  Dir.mkdir(storage_path) unless File.exists?(storage_path)
  begin
    g = Git.open(path)
    g.pull
  rescue
    Git.clone(repo_url, identifier, :path => storage_path)
  end
end