Class: RareMap::Model

Inherits:
Object
  • Object
show all
Includes:
Errors
Defined in:
lib/rare_map/model.rb

Overview

RareMap::Model defines the details of an ActiveRecord model.

Author:

  • Wei-Ming Wu

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db_name, connection, table, group = 'default') ⇒ Model

Creates a Model.

Parameters:

  • db_name (String)

    the name of database

  • connection (Hash)

    the connection config of ActiveRecord

  • table (Table)

    the database table

  • group (String) (defaults to: 'default')

    the group name of this Model



29
30
31
32
# File 'lib/rare_map/model.rb', line 29

def initialize(db_name, connection, table, group = 'default')
  @db_name, @connection, @table, @group = db_name, connection, table, group
  @relations = []
end

Instance Attribute Details

#connectionHash (readonly)

Returns the connection config of this Model.

Returns:

  • (Hash)

    the connection config of this Model



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
42
43
44
45
46
47
# File 'lib/rare_map/model.rb', line 17

class Model
  include Errors
  attr_reader :db_name, :connection, :table, :group
  attr_accessor :relations
  
  # Creates a Model.
  #
  # @param db_name [String] the name of database
  # @param connection [Hash] the connection config of ActiveRecord
  # @param table [Table] the database table
  # @param group [String] the group name of this Model
  # @return [Model] a Model object
  def initialize(db_name, connection, table, group = 'default')
    @db_name, @connection, @table, @group = db_name, connection, table, group
    @relations = []
  end
  
  # Checks if this Model belongs to a group.
  #
  # @return [true, false] true if this Model contains a group, false otherwise
  def group?
    group != 'default'
  end
  
  # Returns the class name of this Model.
  #
  # @return [String] the class name of this Model
  def classify
    "#{table.name}".pluralize.classify
  end
end

#db_nameString (readonly)

Returns the name of the database.

Returns:

  • (String)

    the name of the database



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
42
43
44
45
46
47
# File 'lib/rare_map/model.rb', line 17

class Model
  include Errors
  attr_reader :db_name, :connection, :table, :group
  attr_accessor :relations
  
  # Creates a Model.
  #
  # @param db_name [String] the name of database
  # @param connection [Hash] the connection config of ActiveRecord
  # @param table [Table] the database table
  # @param group [String] the group name of this Model
  # @return [Model] a Model object
  def initialize(db_name, connection, table, group = 'default')
    @db_name, @connection, @table, @group = db_name, connection, table, group
    @relations = []
  end
  
  # Checks if this Model belongs to a group.
  #
  # @return [true, false] true if this Model contains a group, false otherwise
  def group?
    group != 'default'
  end
  
  # Returns the class name of this Model.
  #
  # @return [String] the class name of this Model
  def classify
    "#{table.name}".pluralize.classify
  end
end

#groupString (readonly)

Returns the group of this Model.

Returns:

  • (String)

    the group of this Model



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
42
43
44
45
46
47
# File 'lib/rare_map/model.rb', line 17

class Model
  include Errors
  attr_reader :db_name, :connection, :table, :group
  attr_accessor :relations
  
  # Creates a Model.
  #
  # @param db_name [String] the name of database
  # @param connection [Hash] the connection config of ActiveRecord
  # @param table [Table] the database table
  # @param group [String] the group name of this Model
  # @return [Model] a Model object
  def initialize(db_name, connection, table, group = 'default')
    @db_name, @connection, @table, @group = db_name, connection, table, group
    @relations = []
  end
  
  # Checks if this Model belongs to a group.
  #
  # @return [true, false] true if this Model contains a group, false otherwise
  def group?
    group != 'default'
  end
  
  # Returns the class name of this Model.
  #
  # @return [String] the class name of this Model
  def classify
    "#{table.name}".pluralize.classify
  end
end

#relationsArray

Returns an Array of Relation of this Model.

Returns:

  • (Array)

    an Array of Relation of this Model



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
42
43
44
45
46
47
# File 'lib/rare_map/model.rb', line 17

class Model
  include Errors
  attr_reader :db_name, :connection, :table, :group
  attr_accessor :relations
  
  # Creates a Model.
  #
  # @param db_name [String] the name of database
  # @param connection [Hash] the connection config of ActiveRecord
  # @param table [Table] the database table
  # @param group [String] the group name of this Model
  # @return [Model] a Model object
  def initialize(db_name, connection, table, group = 'default')
    @db_name, @connection, @table, @group = db_name, connection, table, group
    @relations = []
  end
  
  # Checks if this Model belongs to a group.
  #
  # @return [true, false] true if this Model contains a group, false otherwise
  def group?
    group != 'default'
  end
  
  # Returns the class name of this Model.
  #
  # @return [String] the class name of this Model
  def classify
    "#{table.name}".pluralize.classify
  end
end

#tableTable (readonly)

Returns the Table of this Model.

Returns:

  • (Table)

    the Table of this Model



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
42
43
44
45
46
47
# File 'lib/rare_map/model.rb', line 17

class Model
  include Errors
  attr_reader :db_name, :connection, :table, :group
  attr_accessor :relations
  
  # Creates a Model.
  #
  # @param db_name [String] the name of database
  # @param connection [Hash] the connection config of ActiveRecord
  # @param table [Table] the database table
  # @param group [String] the group name of this Model
  # @return [Model] a Model object
  def initialize(db_name, connection, table, group = 'default')
    @db_name, @connection, @table, @group = db_name, connection, table, group
    @relations = []
  end
  
  # Checks if this Model belongs to a group.
  #
  # @return [true, false] true if this Model contains a group, false otherwise
  def group?
    group != 'default'
  end
  
  # Returns the class name of this Model.
  #
  # @return [String] the class name of this Model
  def classify
    "#{table.name}".pluralize.classify
  end
end

Instance Method Details

#classifyString

Returns the class name of this Model.

Returns:

  • (String)

    the class name of this Model



44
45
46
# File 'lib/rare_map/model.rb', line 44

def classify
  "#{table.name}".pluralize.classify
end

#group?true, false

Checks if this Model belongs to a group.

Returns:

  • (true, false)

    true if this Model contains a group, false otherwise



37
38
39
# File 'lib/rare_map/model.rb', line 37

def group?
  group != 'default'
end