open_geo_db 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,24 +1,35 @@
1
1
  # OpenGeoDb
2
2
 
3
- TODO: Write a gem description
3
+ A simple Gem for creating and destroying MySQL databases containing data
4
+ from the "OpenGeoDB" project (http://opengeodb.giswiki.org/wiki/OpenGeoDB).
4
5
 
5
6
  ## Installation
6
7
 
7
8
  Add this line to your application's Gemfile:
8
9
 
9
- gem 'open_geo_db'
10
+ ```ruby
11
+ gem("open_geo_db")
12
+ ```
10
13
 
11
14
  And then execute:
12
15
 
13
- $ bundle
16
+ ```bash
17
+ $ bundle
18
+ ```
14
19
 
15
20
  Or install it yourself as:
16
21
 
17
- $ gem install open_geo_db
22
+ ```bash
23
+ $ gem install open_geo_db
24
+ ```
18
25
 
19
26
  ## Usage
20
27
 
21
- TODO: Write usage instructions here
28
+ For detailed usage run:
29
+
30
+ ```bash
31
+ $ bundle exec open_geo_db --help
32
+ ```
22
33
 
23
34
  ## Contributing
24
35
 
@@ -5,54 +5,39 @@ module OpenGeoDb
5
5
  class CLI
6
6
  include Mixlib::CLI
7
7
 
8
- option(:action,
9
- :required => true,
10
- :short => "-a ACTION",
11
- :long => "--action ACTION",
12
- :proc => Proc.new { |l| l.to_sym },
13
- :description => "Action to do (`create` or `destroy`)")
8
+ DEFAULT_CONFIG = {"open_geo_db" =>
9
+ {"database" => "open_geo_db", "username" => "root", "password" => ""}}
14
10
 
15
- option(:config,
16
- :default => "open_geo_db.yml",
17
- :short => "-c CONFIG",
18
- :long => "--config CONFIG",
19
- :description => "The configuration file to use (default `open_geo_db.yml`)")
11
+ def self.action_option(name, description)
12
+ option(name, :short => "-#{name.to_s[0].chr} config", :long => "--#{name} CONFIG",
13
+ :description => description)
14
+ end
15
+
16
+ action_option(:create, "Create database with config file CONFIG")
17
+ action_option(:destroy, "Destroy database with config file CONFIG")
18
+ action_option(:generate, "Generate config file CONFIG")
20
19
 
21
- option(:help,
22
- :boolean => true,
23
- :on => :tail,
24
- :short => "-h",
25
- :long => "--help",
26
- :description => "Show this message",
27
- :show_options => true,
28
- :exit => 0)
20
+ option(:help, :boolean => true, :on => :tail, :short => "-h", :long => "--help",
21
+ :description => "Show this message", :show_options => true, :exit => 0)
29
22
 
30
23
  def run
31
24
  parse_options
32
-
33
- if File.exist?(config[:config])
34
- yaml = YAML.load_file(config[:config])["open_geo_db"]
35
- @database = yaml["database"]
36
- @username = yaml["username"]
37
- @password = "-p#{yaml["password"]}" if yaml["password"] and yaml["password"].any?
38
- end
39
- @database ||= "open_geo_db"
40
- @username ||= "root"
41
-
42
- action = config[:action]
43
-
44
- case action
45
- when :create then create
46
- when :destroy then destroy
47
- else
48
- puts("Unknown action `#{action}`. For usage see `open_geo_db --help`")
49
- exit 1
50
- end
25
+ send(config.keys.first)
51
26
  end
52
27
 
53
28
  private
54
29
 
30
+ def load_config
31
+ config_file = config.values.first
32
+ puts("Using config file #{config_file}")
33
+ yaml = YAML.load_file(config_file)["open_geo_db"]
34
+ @database = yaml["database"]
35
+ @username = yaml["username"]
36
+ @password = "-p#{yaml["password"]}" if yaml["password"] and yaml["password"].any?
37
+ end
38
+
55
39
  def create
40
+ load_config
56
41
  sh("mysqladmin -u#{@username} #{@password} create #{@database}")
57
42
  %w(opengeodb-begin DE DEhier AT AThier CH CHhier opengeodb-end).each do |basename|
58
43
  file = File.join(File.dirname(__FILE__), %w(.. .. vendor sql), "#{basename}.sql")
@@ -61,9 +46,16 @@ module OpenGeoDb
61
46
  end
62
47
 
63
48
  def destroy
49
+ load_config
64
50
  sh("mysqladmin -u#{@username} #{@password} drop -f #{@database}")
65
51
  end
66
52
 
53
+ def generate
54
+ config_file = config.values.first
55
+ puts("Writing config to #{config_file}")
56
+ File.open(config_file, "w") { |f| f.write(DEFAULT_CONFIG.to_yaml) }
57
+ end
58
+
67
59
  def sh(command)
68
60
  puts(command)
69
61
  %x{#{command}}
@@ -1,3 +1,3 @@
1
1
  module OpenGeoDb
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_geo_db
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kostiantyn Kahanskyi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-04 00:00:00 Z
18
+ date: 2012-01-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: mixlib-cli
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  requirements: []
106
106
 
107
107
  rubyforge_project:
108
- rubygems_version: 1.8.11
108
+ rubygems_version: 1.8.15
109
109
  signing_key:
110
110
  specification_version: 3
111
111
  summary: Create and destroy OpenGeoDb databases