Class: Relaxo::Model::Properties::BelongsTo

Inherits:
Object
  • Object
show all
Defined in:
lib/relaxo/model/properties/composite.rb

Direct Known Subclasses

HasOne

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ BelongsTo

Returns a new instance of BelongsTo.



71
72
73
# File 'lib/relaxo/model/properties/composite.rb', line 71

def initialize(klass)
	@klass = klass
end

Class Method Details

.[](*klasses) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/relaxo/model/properties/composite.rb', line 63

def self.[] *klasses
	if klasses.size == 1
		self.new(klasses[0])
	else
		Polymorphic.new(klasses)
	end
end

Instance Method Details

#convert_from_primative(dataset, path) ⇒ Object



81
82
83
# File 'lib/relaxo/model/properties/composite.rb', line 81

def convert_from_primative(dataset, path)
	@klass.fetch(dataset, path)
end

#convert_to_primative(document) ⇒ Object

Raises:

  • (ArgumentError)


75
76
77
78
79
# File 'lib/relaxo/model/properties/composite.rb', line 75

def convert_to_primative(document)
	raise ArgumentError.new("Document must be saved before adding to relationship") unless document.persisted?
	
	document.paths.first
end