Class: Rasti::DB::Relations::Base

Inherits:
Object
  • Object
show all
Includes:
Sequel::Inflections
Defined in:
lib/rasti/db/relations.rb

Direct Known Subclasses

ManyToMany, ManyToOne, OneToMany

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, source_collection_class, options = {}) ⇒ Base

Returns a new instance of Base.



36
37
38
39
40
# File 'lib/rasti/db/relations.rb', line 36

def initialize(name, source_collection_class, options={})
  @name = name
  @source_collection_class = source_collection_class
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



34
35
36
# File 'lib/rasti/db/relations.rb', line 34

def name
  @name
end

#source_collection_classObject (readonly)

Returns the value of attribute source_collection_class.



34
35
36
# File 'lib/rasti/db/relations.rb', line 34

def source_collection_class
  @source_collection_class
end

Instance Method Details

#many_to_many?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/rasti/db/relations.rb', line 54

def many_to_many?
  is_a? ManyToMany
end

#many_to_one?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/rasti/db/relations.rb', line 50

def many_to_one?
  is_a? ManyToOne
end

#one_to_many?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/rasti/db/relations.rb', line 46

def one_to_many?
  is_a? OneToMany
end

#target_collection_classObject



42
43
44
# File 'lib/rasti/db/relations.rb', line 42

def target_collection_class
  @target_collection_class ||= @options[:collection].is_a?(Class) ? @options[:collection] : Consty.get(@options[:collection] || camelize(pluralize(name)), source_collection_class)
end