glean 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Glean - A data management tool for humans
2
+
3
+ ## Command line
4
+ ```
5
+ NAME
6
+ glean - A data management tool for humans
7
+
8
+ SYNOPSIS
9
+ glean [global options] command [command options] [arguments...]
10
+
11
+ VERSION
12
+ 0.0.3
13
+
14
+ GLOBAL OPTIONS
15
+ -f, --flagname=The name of the argument - Describe some flag here (default: the default)
16
+ --help - Show this message
17
+ -s, --[no-]switch - Describe some switch here
18
+ --version -
19
+
20
+ COMMANDS
21
+ get - Download a dataset by name
22
+ help - Shows a list of commands or help for one command
23
+ out - Describe out here
24
+ search - Describe search here
25
+ ```
26
+
27
+ ## Rails
28
+
29
+ Gemfile:
30
+ ```ruby
31
+ gem 'glean'
32
+ ```
33
+
34
+ db/seeds.rb:
35
+ ```ruby
36
+ countries = Glean::Dataset.new('glean/countries')
37
+ countries.each do |country|
38
+ Country.create :name => country[:name], :code => country[:code]
39
+ end
40
+ ```
41
+
42
+ ## Other Frameworks
43
+
44
+ I'm not sure how you'd do it, but I want to make it easy. Open an issue, or better yet drop some code in a Pull Request.
data/bin/glean CHANGED
@@ -41,7 +41,6 @@ arg_name 'dataset_identifier'
41
41
  command :get do |c|
42
42
  c.action do |global_options,options,args|
43
43
  dataset = Glean::Dataset.new(args[0])
44
- dataset.download!
45
44
  end
46
45
  end
47
46
 
data/lib/glean/dataset.rb CHANGED
@@ -4,6 +4,7 @@ module Glean
4
4
 
5
5
  def initialize(identifier)
6
6
  @identifier = identifier
7
+ sync
7
8
  end
8
9
 
9
10
  def storage_path
@@ -14,14 +15,33 @@ module Glean
14
15
  File.join(storage_path, identifier)
15
16
  end
16
17
 
17
- def download!
18
- Git.clone("http://github.com/#{identifier}", identifier, :path => storage_path)
18
+ def sync
19
+ begin
20
+ g = Git.open(path)
21
+ g.pull
22
+ rescue
23
+ Git.clone("http://github.com/#{identifier}", identifier, :path => storage_path)
24
+ end
19
25
  end
20
26
 
21
- def each_datum
27
+ def each
22
28
  Dir.glob(File.join(path, "*")) do |d|
23
- yield Datum.new(d)
29
+ yield directory_hash(d)
30
+ end
31
+ end
32
+
33
+ def directory_hash(path)
34
+ data = {}
35
+ Dir.foreach(path) do |entry|
36
+ next if (entry == '..' || entry == '.')
37
+ full_path = File.join(path, entry)
38
+ if File.directory?(full_path)
39
+ data[entry.to_sym] = directory_hash(full_path)
40
+ else
41
+ data[entry.to_sym] = File.read(full_path).chomp
42
+ end
24
43
  end
44
+ return data
25
45
  end
26
46
  end
27
47
  end
data/lib/glean/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Glean
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
data/lib/glean.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'glean/version'
2
2
  require 'glean/dataset'
3
- require 'glean/datum'
4
3
 
5
4
  require 'git'
6
5
  # Add requires for other files you add to your project here, so
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glean
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -103,6 +103,7 @@ files:
103
103
  - .gitignore
104
104
  - Gemfile
105
105
  - Gemfile.lock
106
+ - README.md
106
107
  - README.rdoc
107
108
  - Rakefile
108
109
  - bin/glean
@@ -113,7 +114,6 @@ files:
113
114
  - glean.rdoc
114
115
  - lib/glean.rb
115
116
  - lib/glean/dataset.rb
116
- - lib/glean/datum.rb
117
117
  - lib/glean/version.rb
118
118
  - test/default_test.rb
119
119
  - test/test_helper.rb
data/lib/glean/datum.rb DELETED
@@ -1,13 +0,0 @@
1
- module Glean
2
- class Datum
3
- attr_reader :path
4
-
5
- def initialize(path)
6
- @path = path
7
- end
8
-
9
- def to_s
10
- File.basename(path)
11
- end
12
- end
13
- end