Class: BazaModels::Model::Reflection

Inherits:
Object
  • Object
show all
Defined in:
lib/baza_models/model/reflection.rb

Instance Method Summary collapse

Constructor Details

#initialize(relationship) ⇒ Reflection

Returns a new instance of Reflection.



2
3
4
# File 'lib/baza_models/model/reflection.rb', line 2

def initialize(relationship)
  @relationship = relationship
end

Instance Method Details

#class_nameObject



6
7
8
# File 'lib/baza_models/model/reflection.rb', line 6

def class_name
  @relationship.fetch(:class_name)
end

#collection?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/baza_models/model/reflection.rb', line 10

def collection?
  @relationship.fetch(:type) == :has_many
end

#foreign_keyObject



14
15
16
# File 'lib/baza_models/model/reflection.rb', line 14

def foreign_key
  @relationship.fetch(:foreign_key).to_s
end

#klassObject



18
19
20
# File 'lib/baza_models/model/reflection.rb', line 18

def klass
  StringCases.constantize(class_name)
end

#nameObject



22
23
24
# File 'lib/baza_models/model/reflection.rb', line 22

def name
  @relationship.fetch(:relation_name)
end