Class: Glean::Dataset

Inherits:
Object
  • Object
show all
Includes:
Enumerable
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.



7
8
9
10
11
# File 'lib/glean/dataset.rb', line 7

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.



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

def identifier
  @identifier
end

Instance Method Details

#eachObject



35
36
37
38
39
# File 'lib/glean/dataset.rb', line 35

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

#pathObject



17
18
19
# File 'lib/glean/dataset.rb', line 17

def path
  File.join(storage_path, identifier)
end

#repo_urlObject



21
22
23
# File 'lib/glean/dataset.rb', line 21

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

#storage_pathObject



13
14
15
# File 'lib/glean/dataset.rb', line 13

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

#syncObject



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

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