Module: Embedson::Model

Defined in:
lib/embedson/model.rb,
lib/embedson/model/embeds_builder.rb,
lib/embedson/model/method_builder.rb,
lib/embedson/model/embedded_builder.rb

Overview

Public: Defines embeds_one and embedded_in methods.

Examples

class Emb
  extend Embedson::Model
end

Defined Under Namespace

Classes: EmbeddedBuilder, EmbedsBuilder, MethodBuilder

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(mod) ⇒ Object



53
54
55
# File 'lib/embedson/model.rb', line 53

def self.extended(mod)
  attr_reader :embedson_relations
end

Instance Method Details

#embedded_in(name, options = {}) ⇒ Object

Public: Creates methods to manage parent class.

name - Name of relation where parent object will be stored. options - The hash options used to define custom class name and field name

in parent class (default: {}):
:class_name - Name of class where current object will be embedded.
:inverse_of - Name of field where parent class will keep current object.

Examples

embedded_in :parent, class_name: Test, inverse_of: :virt

embedded_in :parent

Returns nothing



47
48
49
50
51
# File 'lib/embedson/model.rb', line 47

def embedded_in(name, options = {})
  @embedson_relations ||= []
  @embedson_relations << name
  MethodBuilder.new(self, name, options).embedded
end

#embeds_one(name, options = {}) ⇒ Object

Public: Creates methods to manage embedded class.

name - Name of of relation. options - The Hash options used to define custom column name, class name

and field name in embedded class (default: {}):
:class_name - Name of class which will be ebedded.
:column_name - Name of column where Hash representation will be stored.
:inverse_of - Name of field where related class will store current object.
:hash_method - Method name which returns hash representation os saved object. Default :to_h

Examples

embeds_one :virt, class_name: Virt, column_name: :data, inverse_of: :parent

embeds_one :virt

Returns nothing



28
29
30
# File 'lib/embedson/model.rb', line 28

def embeds_one(name, options = {})
  MethodBuilder.new(self, name, options).embeds
end