class MarkMapper::Plugins::Associations::Base
Constants
- AssociationOptions
Options that should not be considered MarkLogic query options/criteria
Attributes
name[R]
options[R]
query_options[R]
Public Class Methods
new(name, options={}, &extension)
click to toggle source
# 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
Public Instance Methods
as()
click to toggle source
# File lib/mark_mapper/plugins/associations/base.rb, line 54 def as @options[:as] || self.name end
as?()
click to toggle source
# File lib/mark_mapper/plugins/associations/base.rb, line 30 def as? !!@options[:as] end
autosave?()
click to toggle source
# File lib/mark_mapper/plugins/associations/base.rb, line 71 def autosave? raise NotImplementedError end
class_name()
click to toggle source
# 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?()
click to toggle source
# File lib/mark_mapper/plugins/associations/base.rb, line 46 def counter_cache? !!@options[:counter_cache] end
embeddable?()
click to toggle source
# File lib/mark_mapper/plugins/associations/base.rb, line 38 def embeddable? klass.embeddable? end
foreign_key()
click to toggle source
# File lib/mark_mapper/plugins/associations/base.rb, line 58 def foreign_key @options[:foreign_key] || "#{name}_id" end
in_array?()
click to toggle source
# File lib/mark_mapper/plugins/associations/base.rb, line 34 def in_array? !!@options[:in] end
ivar()
click to toggle source
# File lib/mark_mapper/plugins/associations/base.rb, line 62 def ivar @ivar ||= "@_#{name}" end
klass()
click to toggle source
# File lib/mark_mapper/plugins/associations/base.rb, line 22 def klass @klass ||= options[:class] || class_name.constantize end
polymorphic?()
click to toggle source
# File lib/mark_mapper/plugins/associations/base.rb, line 26 def polymorphic? !!@options[:polymorphic] end
proxy_class()
click to toggle source
:nocov:
# File lib/mark_mapper/plugins/associations/base.rb, line 67 def proxy_class raise NotImplementedError end
setup(model)
click to toggle source
:nocov:
# File lib/mark_mapper/plugins/associations/base.rb, line 76 def setup(model) end
touch?()
click to toggle source
# File lib/mark_mapper/plugins/associations/base.rb, line 42 def touch? !!@options[:touch] end
type_key_name()
click to toggle source
# File lib/mark_mapper/plugins/associations/base.rb, line 50 def type_key_name "_type" end
Private Instance Methods
modularized_extensions(*extensions)
click to toggle source
# File lib/mark_mapper/plugins/associations/base.rb, line 90 def modularized_extensions(*extensions) extensions.flatten.compact.map do |extension| Proc === extension ? Module.new(&extension) : extension end end
separate_options_and_conditions()
click to toggle source
# File lib/mark_mapper/plugins/associations/base.rb, line 80 def separate_options_and_conditions @original_options.each_pair do |key, value| if AssociationOptions.include?(key) @options[key] = value else @query_options[key] = value end end end