Class: Mysqlexport::Writer
- Inherits:
-
Object
- Object
- Mysqlexport::Writer
- Defined in:
- lib/mysqlexport/writer.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#sql ⇒ Object
readonly
Returns the value of attribute sql.
Instance Method Summary collapse
- #filter_path(path) ⇒ Object
-
#initialize(options = {}) ⇒ Writer
constructor
A new instance of Writer.
- #to_path(path = config.output_path) ⇒ Object
- #to_s ⇒ Object
- #to_stdout ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Writer
Returns a new instance of Writer.
5 6 7 8 9 |
# File 'lib/mysqlexport/writer.rb', line 5 def initialize( = {}) validate!() @config = Mysqlexport::Config.new @client = @config.client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/mysqlexport/writer.rb', line 3 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/mysqlexport/writer.rb', line 3 def config @config end |
#sql ⇒ Object (readonly)
Returns the value of attribute sql.
3 4 5 |
# File 'lib/mysqlexport/writer.rb', line 3 def sql @sql end |
Instance Method Details
#filter_path(path) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/mysqlexport/writer.rb', line 16 def filter_path(path) path = ::Dir.pwd.to_s unless path.instance_of? ::String file_name = "/#{::Time.now.to_i}_mysqlexport.#{extension}" if ::File.directory?(path) file_name = "/#{config.table}.#{extension}" if ::File.directory?(path) && !config.table.nil? path += file_name.to_s path end |
#to_path(path = config.output_path) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/mysqlexport/writer.rb', line 24 def to_path(path = config.output_path) f = ::File.open(filter_path(path), "w") to_file f f.close nil end |
#to_s ⇒ Object
31 32 33 34 35 36 |
# File 'lib/mysqlexport/writer.rb', line 31 def to_s s = ::StringIO.new to_file s s.rewind s.read end |
#to_stdout ⇒ Object
11 12 13 14 |
# File 'lib/mysqlexport/writer.rb', line 11 def to_stdout to_file $stdout nil end |