lynx 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of lynx might be problematic. Click here for more details.

data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Lynx
2
2
 
3
- TODO
3
+ Ruby command line wrapper for MySQL.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,7 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO
21
+ Coming soon...
22
22
 
23
23
  ## Contributing
24
24
 
@@ -4,12 +4,28 @@ require 'lynx/command'
4
4
  require 'lynx/pipe'
5
5
  require 'lynx/d_s_l'
6
6
 
7
+ require 'erb'
8
+ require 'yaml'
9
+
7
10
  module Lynx
8
11
  class << self
9
12
  def config(options)
10
13
  Lynx::DSL.new(options)
11
14
  end
12
15
 
16
+ def rails(env = nil)
17
+ if defined?(Rails)
18
+ env ||= Rails.env
19
+ hash = Rails.configuration.database_configuration
20
+ elsif File.exists?('config/database.yml')
21
+ hash = YAML::load(ERB.new(IO.read('config/database.yml')).result)
22
+ else
23
+ raise RuntimeError, 'unable to find configuration file'
24
+ end
25
+
26
+ config(hash[env.to_s])
27
+ end
28
+
13
29
  def append(*args)
14
30
  Pipe::Append.new(*args)
15
31
  end
@@ -43,7 +43,7 @@ module Lynx
43
43
  instruct(:no_data){ '--no-data' }
44
44
  instruct(:skip_triggers){ '--skip-triggers' }
45
45
  instruct(:compact){ '--compact' }
46
- instruct(:ignore){ |c,table| "--ignore-table=#{table}" }
46
+ instruct(:ignore){ |c,table| "--ignore-table=#{c.config.database}.#{table}" }
47
47
  instruct(:no_create_info){ '--no-create-info' }
48
48
 
49
49
  def to_s
@@ -10,19 +10,23 @@ module Lynx
10
10
  end
11
11
 
12
12
  [:username, :password, :host, :database].each do |method|
13
- define_method(method){ @config[method] }
13
+ define_method(method){ self[method] }
14
14
  end
15
15
 
16
16
  def mysql
17
- @mysql ||= @config[:mysql] || detect(MYSQL)
17
+ @mysql ||= self[:mysql] || detect(MYSQL)
18
18
  end
19
19
 
20
20
  def dump
21
- @dump ||= @config[:dump] || detect(DUMP)
21
+ @dump ||= self[:dump] || detect(DUMP)
22
22
  end
23
23
 
24
24
  private
25
25
 
26
+ def [](key)
27
+ @config[key.to_sym] || @config[key.to_s]
28
+ end
29
+
26
30
  def detect(commands)
27
31
  commands.detect{ |c| system("which #{c}") }
28
32
  end
@@ -4,3 +4,4 @@ require 'lynx/pipe/write'
4
4
  require 'lynx/pipe/get'
5
5
  require 'lynx/pipe/debug'
6
6
  require 'lynx/pipe/import'
7
+ require 'lynx/pipe/run'
@@ -3,12 +3,13 @@ require 'lynx/pipe/basic'
3
3
  module Lynx
4
4
  module Pipe
5
5
  class Debug < Basic
6
- def initialize(pipe = nil)
6
+ def initialize(pipe = nil, io = STDOUT)
7
7
  @pipe = pipe
8
+ @io = io
8
9
  end
9
10
 
10
11
  def perform(command)
11
- puts "[Lynx] #{command}"
12
+ @io.puts "[Lynx] #{filter(command)}"
12
13
 
13
14
  @pipe.perform(command) if has_pipe?
14
15
  end
@@ -21,6 +22,10 @@ module Lynx
21
22
 
22
23
  private
23
24
 
25
+ def filter(command)
26
+ command.to_s.gsub(/--password=.*?\s/, '--password=[FILTERED]')
27
+ end
28
+
24
29
  def has_pipe?
25
30
  !!@pipe
26
31
  end
@@ -4,7 +4,7 @@ module Lynx
4
4
  module Pipe
5
5
  class Run < Basic
6
6
  def perform(command)
7
- system(command)
7
+ system(command.to_s)
8
8
  end
9
9
  end
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module Lynx
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -8,9 +8,9 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Lynx::VERSION
9
9
  gem.authors = ["Pan Thomakos"]
10
10
  gem.email = ["pan.thomakos@gmail.com"]
11
- gem.description = %q{MySQL command line wrapper for Ruby.}
12
- gem.summary = %q{MySQL command line wrapper for Ruby.}
13
- gem.homepage = ""
11
+ gem.description = %q{Ruby command line wrapper for MySQL.}
12
+ gem.summary = %q{Ruby command line wrapper for MySQL.}
13
+ gem.homepage = "https://www.github.com/panthomakos/lynx"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -16,6 +16,10 @@ describe Lynx::Config do
16
16
  end
17
17
  end
18
18
 
19
+ it 'recognizes string parameters' do
20
+ assert_equal 'lqsym', Lynx::Config.new('mysql' => 'lqsym').mysql
21
+ end
22
+
19
23
  it 'knows the dump command' do
20
24
  Kernel.stub(:system, true) do
21
25
  assert_equal 'mysqldump', config.dump
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lynx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,7 +27,7 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
- description: MySQL command line wrapper for Ruby.
30
+ description: Ruby command line wrapper for MySQL.
31
31
  email:
32
32
  - pan.thomakos@gmail.com
33
33
  executables: []
@@ -62,7 +62,7 @@ files:
62
62
  - test/lib/lynx/pipe/append_test.rb
63
63
  - test/lib/lynx/pipe/get_test.rb
64
64
  - test/lib/lynx/pipe/write_test.rb
65
- homepage: ''
65
+ homepage: https://www.github.com/panthomakos/lynx
66
66
  licenses: []
67
67
  post_install_message:
68
68
  rdoc_options: []
@@ -85,7 +85,7 @@ rubyforge_project:
85
85
  rubygems_version: 1.8.23
86
86
  signing_key:
87
87
  specification_version: 3
88
- summary: MySQL command line wrapper for Ruby.
88
+ summary: Ruby command line wrapper for MySQL.
89
89
  test_files:
90
90
  - test/lib/lynx/command/basic_test.rb
91
91
  - test/lib/lynx/command/dump_test.rb