Class: Schemaker::Models::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)


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

def initialize models, my_class
  raise ArgumentError, "The first argument must be a Schema::Models instance, was #{models}" if !models.is_a?(Schemaker::Models)
  raise ArgumentError, "The second argument must be the Class that is to be configured, was #{my_class}" 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



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

def logs
  @logs
end

#modelsObject

Returns the value of attribute models.



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

def models
  @models
end

#my_classObject

Returns the value of attribute my_class.



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

def my_class
  @my_class
end

Class Method Details

.model_typesObject



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

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



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

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



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

def configure
  create_has_many :join, class_name_option(join_class)
end