module Bhf::Mongoid::Document::ClassMethods

Public Instance Methods

bhf_attribute_method?(column_name) click to toggle source
# File lib/bhf/mongoid/document.rb, line 76
def bhf_attribute_method?(column_name)
  attribute_method?(column_name)
end
bhf_embedded?() click to toggle source
# File lib/bhf/mongoid/document.rb, line 157
def bhf_embedded?
  embedded?
end
bhf_find_embed(parent_id, ref_id) click to toggle source
# File lib/bhf/mongoid/document.rb, line 141
def bhf_find_embed(parent_id, ref_id)
  get_embedded_parent parent_id do |parent, meta|
    key_name = if meta.inverse_of?
      meta.inverse_of
    else
      meta.inverse_foreign_key.pluralize
    end.to_s
    relation = parent.send(key_name)
    if parent.relations[key_name].macro == :embeds_one
      relation
    else
      relation.find(ref_id)
    end
  end
end
bhf_new_embed(parent_id, params = nil) click to toggle source
# File lib/bhf/mongoid/document.rb, line 126
def bhf_new_embed(parent_id, params = nil)
  get_embedded_parent parent_id do |parent, meta|
    key_name = if meta.inverse_of?
      meta.inverse_of
    else
      meta.inverse_foreign_key.pluralize
    end.to_s
    if parent.relations[key_name] and parent.relations[key_name].macro == :embeds_one
      parent.send("build_#{key_name}", params)
    else
      parent.send(key_name).build(params)
    end
  end
end
bhf_primary_key() click to toggle source
# File lib/bhf/mongoid/document.rb, line 80
def bhf_primary_key
  '_id'
end
columns_hash() click to toggle source
# File lib/bhf/mongoid/document.rb, line 57
def columns_hash
  c = {}
  fields.each_pair do |key, meta|
    next if meta.options[:metadata]
    next if key == '_type'
    c[key] = Field.new(meta)
  end
  c
end
get_embedded_parent(parent_id, &block) click to toggle source
# File lib/bhf/mongoid/document.rb, line 113
def get_embedded_parent(parent_id, &block)
  relations.each do |key, meta|
    next unless meta.macro == :embedded_in
    parent = meta.class_name.constantize
    parent = parent.find(parent_id) rescue nil

    if parent
      return block.call(parent, meta) if block_given?
      return parent
    end
  end
end
order(a) click to toggle source
# File lib/bhf/mongoid/document.rb, line 84
def order(a)
  order_by(a)
end
reflections() click to toggle source
# File lib/bhf/mongoid/document.rb, line 67
def reflections
  c = {}
  relations.each do |key, meta|
    next if meta.macro == :embedded_in
    c[key] = Reflection.new(meta)
  end
  c
end
reorder(a) click to toggle source
# File lib/bhf/mongoid/document.rb, line 88
def reorder(a)
  order_by(a)
end