Class: MarkMapper::Plugins::Associations::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mark_mapper/plugins/associations/base.rb

Direct Known Subclasses

ManyAssociation, SingleAssociation

Constant Summary collapse

AssociationOptions =

Options that should not be considered MarkLogic query options/criteria

[:as, :class, :class_name, :dependent, :extend, :foreign_key, :in, :polymorphic, :autosave, :touch, :counter_cache]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Base.


11
12
13
14
15
16
# File 'lib/mark_mapper/plugins/associations/base.rb', line 11

def initialize(name, options={}, &extension)
  @name, @options, @query_options, @original_options = name.to_sym, {}, {}, options
  options.symbolize_keys!
  options[:extend] = modularized_extensions(extension, options[:extend])
  separate_options_and_conditions
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


6
7
8
# File 'lib/mark_mapper/plugins/associations/base.rb', line 6

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options


6
7
8
# File 'lib/mark_mapper/plugins/associations/base.rb', line 6

def options
  @options
end

#query_optionsObject (readonly)

Returns the value of attribute query_options


6
7
8
# File 'lib/mark_mapper/plugins/associations/base.rb', line 6

def query_options
  @query_options
end

Instance Method Details

#asObject


54
55
56
# File 'lib/mark_mapper/plugins/associations/base.rb', line 54

def as
  @options[:as] || self.name
end

#as?Boolean

Returns:


30
31
32
# File 'lib/mark_mapper/plugins/associations/base.rb', line 30

def as?
  !!@options[:as]
end

#autosave?Boolean

Returns:

Raises:

  • (NotImplementedError)

71
72
73
# File 'lib/mark_mapper/plugins/associations/base.rb', line 71

def autosave?
  raise NotImplementedError
end

#class_nameObject


18
19
20
# File 'lib/mark_mapper/plugins/associations/base.rb', line 18

def class_name
  @class_name ||= options[:class_name] || name.to_s.camelize
end

#counter_cache?Boolean

Returns:


46
47
48
# File 'lib/mark_mapper/plugins/associations/base.rb', line 46

def counter_cache?
  !!@options[:counter_cache]
end

#embeddable?Boolean

Returns:


38
39
40
# File 'lib/mark_mapper/plugins/associations/base.rb', line 38

def embeddable?
  klass.embeddable?
end

#foreign_keyObject


58
59
60
# File 'lib/mark_mapper/plugins/associations/base.rb', line 58

def foreign_key
  @options[:foreign_key] || "#{name}_id"
end

#in_array?Boolean

Returns:


34
35
36
# File 'lib/mark_mapper/plugins/associations/base.rb', line 34

def in_array?
  !!@options[:in]
end

#ivarObject


62
63
64
# File 'lib/mark_mapper/plugins/associations/base.rb', line 62

def ivar
  @ivar ||= "@_#{name}"
end

#klassObject


22
23
24
# File 'lib/mark_mapper/plugins/associations/base.rb', line 22

def klass
  @klass ||= options[:class] || class_name.constantize
end

#polymorphic?Boolean

Returns:


26
27
28
# File 'lib/mark_mapper/plugins/associations/base.rb', line 26

def polymorphic?
  !!@options[:polymorphic]
end

#proxy_classObject

:nocov:

Raises:

  • (NotImplementedError)

67
68
69
# File 'lib/mark_mapper/plugins/associations/base.rb', line 67

def proxy_class
  raise NotImplementedError
end

#setup(model) ⇒ Object

:nocov:


76
77
# File 'lib/mark_mapper/plugins/associations/base.rb', line 76

def setup(model)
end

#touch?Boolean

Returns:


42
43
44
# File 'lib/mark_mapper/plugins/associations/base.rb', line 42

def touch?
  !!@options[:touch]
end

#type_key_nameObject


50
51
52
# File 'lib/mark_mapper/plugins/associations/base.rb', line 50

def type_key_name
  "_type"
end