Class: RareMap::Model
Overview
RareMap::Model defines the details of an ActiveRecord model.
Instance Attribute Summary collapse
-
#connection ⇒ Hash
readonly
The connection config of this Model.
-
#db_name ⇒ String
readonly
The name of the database.
-
#group ⇒ String
readonly
The group of this Model.
-
#relations ⇒ Array
An Array of Relation of this Model.
-
#table ⇒ Table
readonly
The Table of this Model.
Instance Method Summary collapse
-
#classify ⇒ String
Returns the class name of this Model.
-
#group? ⇒ true, false
Checks if this Model belongs to a group.
-
#initialize(db_name, connection, table, group = 'default') ⇒ Model
constructor
Creates a Model.
Constructor Details
#initialize(db_name, connection, table, group = 'default') ⇒ Model
Creates a 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
#connection ⇒ Hash (readonly)
Returns 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_name ⇒ String (readonly)
Returns 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 |
#group ⇒ String (readonly)
Returns 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 |
#relations ⇒ Array
Returns 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 |
#table ⇒ Table (readonly)
Returns 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
#classify ⇒ String
Returns 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.
37 38 39 |
# File 'lib/rare_map/model.rb', line 37 def group? group != 'default' end |