Class: RareMap::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/rare_map/column.rb

Overview

RareMap::Column defines a column of a database table.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, opts = {}) ⇒ Column

Creates a Column.

Parameters:

  • name (String)

    the name of column

  • type (String)

    the type of column



22
23
24
25
26
# File 'lib/rare_map/column.rb', line 22

def initialize(name, type, opts = {})
  @name = name
  @type = type
  @unique = opts[:unique] == true
end

Instance Attribute Details

#nameString (readonly)

Returns the name of this Column.

Returns:

  • (String)

    the name of this Column



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rare_map/column.rb', line 12

class Column
  attr_reader :name, :type
  attr_accessor :unique
  attr_accessor :ref_table
  
  # Creates a Column.
  #
  # @param name [String] the name of column
  # @param type [String] the type of column
  # @return [Column] a Column object
  def initialize(name, type, opts = {})
    @name = name
    @type = type
    @unique = opts[:unique] == true
  end
  
  # Checks if this Column is unique.
  #
  # @return [true, false] true if it's unique, false otherwise 
  def unique?
    @unique
  end
  
  # Checks if this Column is a foreign key.
  #
  # @return [true, false] true if it's a foreign key, false otherwise 
  def foreign_key?
    @ref_table ? true : false
  end
end

#ref_tableString

Returns the reference table of this Column.

Returns:

  • (String)

    the reference table of this Column



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rare_map/column.rb', line 12

class Column
  attr_reader :name, :type
  attr_accessor :unique
  attr_accessor :ref_table
  
  # Creates a Column.
  #
  # @param name [String] the name of column
  # @param type [String] the type of column
  # @return [Column] a Column object
  def initialize(name, type, opts = {})
    @name = name
    @type = type
    @unique = opts[:unique] == true
  end
  
  # Checks if this Column is unique.
  #
  # @return [true, false] true if it's unique, false otherwise 
  def unique?
    @unique
  end
  
  # Checks if this Column is a foreign key.
  #
  # @return [true, false] true if it's a foreign key, false otherwise 
  def foreign_key?
    @ref_table ? true : false
  end
end

#typeString (readonly)

Returns the type of this Column.

Returns:

  • (String)

    the type of this Column



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rare_map/column.rb', line 12

class Column
  attr_reader :name, :type
  attr_accessor :unique
  attr_accessor :ref_table
  
  # Creates a Column.
  #
  # @param name [String] the name of column
  # @param type [String] the type of column
  # @return [Column] a Column object
  def initialize(name, type, opts = {})
    @name = name
    @type = type
    @unique = opts[:unique] == true
  end
  
  # Checks if this Column is unique.
  #
  # @return [true, false] true if it's unique, false otherwise 
  def unique?
    @unique
  end
  
  # Checks if this Column is a foreign key.
  #
  # @return [true, false] true if it's a foreign key, false otherwise 
  def foreign_key?
    @ref_table ? true : false
  end
end

#uniquetrue, false

Returns the uniqueness of this Column.

Returns:

  • (true, false)

    the uniqueness of this Column



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rare_map/column.rb', line 12

class Column
  attr_reader :name, :type
  attr_accessor :unique
  attr_accessor :ref_table
  
  # Creates a Column.
  #
  # @param name [String] the name of column
  # @param type [String] the type of column
  # @return [Column] a Column object
  def initialize(name, type, opts = {})
    @name = name
    @type = type
    @unique = opts[:unique] == true
  end
  
  # Checks if this Column is unique.
  #
  # @return [true, false] true if it's unique, false otherwise 
  def unique?
    @unique
  end
  
  # Checks if this Column is a foreign key.
  #
  # @return [true, false] true if it's a foreign key, false otherwise 
  def foreign_key?
    @ref_table ? true : false
  end
end

Instance Method Details

#foreign_key?true, false

Checks if this Column is a foreign key.

Returns:

  • (true, false)

    true if it’s a foreign key, false otherwise



38
39
40
# File 'lib/rare_map/column.rb', line 38

def foreign_key?
  @ref_table ? true : false
end

#unique?true, false

Checks if this Column is unique.

Returns:

  • (true, false)

    true if it’s unique, false otherwise



31
32
33
# File 'lib/rare_map/column.rb', line 31

def unique?
  @unique
end