Class: PerconaMigrator::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/percona_migrator/option.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value = nil) ⇒ Option

Constructor

Parameters:

  • name (String)
  • optional

    value [String]



22
23
24
25
# File 'lib/percona_migrator/option.rb', line 22

def initialize(name, value = nil)
  @name = name
  @value = value
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/percona_migrator/option.rb', line 3

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/percona_migrator/option.rb', line 3

def value
  @value
end

Class Method Details

.from_string(string) ⇒ Option

Builds an instance by parsing its name and value out of the given string. Note the string must conform to “–<arg>=<value>” format.

Parameters:

  • string (String)

Returns:



10
11
12
13
14
15
16
# File 'lib/percona_migrator/option.rb', line 10

def self.from_string(string)
  pair = string.split('=')
  name = pair[0][2..-1]
  value = pair[1]

  new(name, value)
end

Instance Method Details

#==(another_option) ⇒ Boolean Also known as: eql?

Compares two options

Parameters:

Returns:

  • (Boolean)


31
32
33
# File 'lib/percona_migrator/option.rb', line 31

def ==(another_option)
  name == another_option.name
end

#hashFixnum

Returns the option’s hash

Returns:

  • (Fixnum)


39
40
41
# File 'lib/percona_migrator/option.rb', line 39

def hash
  name.hash
end

#to_sString

Returns the option as string following the “–<name>=<value>” format

Returns:

  • (String)


46
47
48
# File 'lib/percona_migrator/option.rb', line 46

def to_s
  "--#{name}#{value_as_string}"
end