Class: Mysqlexport::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/mysqlexport/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_specified_options = {}) ⇒ Config

Returns a new instance of Config.



5
6
7
# File 'lib/mysqlexport/config.rb', line 5

def initialize(user_specified_options = {})
  @user_specified_options = user_specified_options.symbolize_keys
end

Instance Attribute Details

#user_specified_optionsObject (readonly)

Returns the value of attribute user_specified_options.



3
4
5
# File 'lib/mysqlexport/config.rb', line 3

def user_specified_options
  @user_specified_options
end

Instance Method Details

#clientObject

client options



69
70
71
72
73
74
# File 'lib/mysqlexport/config.rb', line 69

def client
  return @client if @client.is_a? ::Mysql2::Client

  @client = ::Mysql2::Client.new(host: host, port: port, username: username,
                                 password: password, database: database, socket: socket)
end

#col_sepObject



51
52
53
# File 'lib/mysqlexport/config.rb', line 51

def col_sep
  user_specified_options[:col_sep]
end

#csv_headingObject



59
60
61
# File 'lib/mysqlexport/config.rb', line 59

def csv_heading
  user_specified_options[:csv_heading].to_s.downcase != "false"
end

#databaseObject



26
27
28
# File 'lib/mysqlexport/config.rb', line 26

def database
  user_specified_options[:database] || active_record_connection.try(:current_database)
end

#executeObject



34
35
36
# File 'lib/mysqlexport/config.rb', line 34

def execute
  user_specified_options[:execute] || "select * from #{table}"
end

#force_quotesObject

csv options



47
48
49
# File 'lib/mysqlexport/config.rb', line 47

def force_quotes
  user_specified_options[:force_quotes].to_s.downcase == "true" || nil
end

#hostObject

database options



10
11
12
# File 'lib/mysqlexport/config.rb', line 10

def host
  user_specified_options[:host] || active_record_config.try(:[], :host)
end

#output_pathObject



42
43
44
# File 'lib/mysqlexport/config.rb', line 42

def output_path
  user_specified_options[:output_path]
end

#passwordObject



22
23
24
# File 'lib/mysqlexport/config.rb', line 22

def password
  user_specified_options[:password] || active_record_config.try(:[], :password)
end

#portObject



14
15
16
# File 'lib/mysqlexport/config.rb', line 14

def port
  user_specified_options[:port] || active_record_config.try(:[], :port)
end

#prettyObject

json options



64
65
66
# File 'lib/mysqlexport/config.rb', line 64

def pretty
  user_specified_options[:pretty].to_s.downcase == "true" || nil
end

#row_sepObject



55
56
57
# File 'lib/mysqlexport/config.rb', line 55

def row_sep
  user_specified_options[:row_sep]
end

#socketObject



30
31
32
# File 'lib/mysqlexport/config.rb', line 30

def socket
  user_specified_options[:socket] || active_record_config.try(:[], :socket)
end

#tableObject



38
39
40
# File 'lib/mysqlexport/config.rb', line 38

def table
  user_specified_options[:table]
end

#usernameObject



18
19
20
# File 'lib/mysqlexport/config.rb', line 18

def username
  user_specified_options[:username] || active_record_config.try(:[], :username)
end