Class: Schemaker::BaseModel

Inherits:
Object
  • Object
show all
Defined in:
lib/schemaker/models/base_model.rb

Direct Known Subclasses

JoinModel, ObjectModel, SubjectModel

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(models, my_class) ⇒ BaseModel

Returns a new instance of BaseModel.

Parameters:

  • each (Schema::Models)

    model needs to have access to the collection of models it may need to create relations with

  • each (Class)

    model must have a reference to the Class it aims to configure!

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
# File 'lib/schemaker/models/base_model.rb', line 15

def initialize models, my_class
  raise ArgumentError, "The first argument must be a Schema::Models instance" if !models.is_a?(Schemaker::Models)
  raise ArgumentError, "The second argument must be the Class that is to be configured" if !my_class.is_a?(Class)

  @models   = models     
  @my_class = my_class 
  @logs = []         
end

Instance Attribute Details

#logsObject (readonly)

can be used to later check which relationships were set up



11
12
13
# File 'lib/schemaker/models/base_model.rb', line 11

def logs
  @logs
end

#modelsObject

Returns the value of attribute models.



10
11
12
# File 'lib/schemaker/models/base_model.rb', line 10

def models
  @models
end

#my_classObject

Returns the value of attribute my_class.



10
11
12
# File 'lib/schemaker/models/base_model.rb', line 10

def my_class
  @my_class
end

Class Method Details

.model_typesObject



37
38
39
# File 'lib/schemaker/models/base_model.rb', line 37

def self.model_types
  [:object, :subject, :join]
end

Instance Method Details

#clazz_nameString Also known as: my_class_name

The class name of the Class to be configured

Returns:

  • (String)

    class name



32
33
34
# File 'lib/schemaker/models/base_model.rb', line 32

def clazz_name
  my_class.to_s
end

#configureObject

The models :subject and :object must both be configured with a has_many relationship to the join model which the has_many :through references



26
27
28
# File 'lib/schemaker/models/base_model.rb', line 26

def configure
  create_has_many :join, class_name_option(join_class)
end