Class: Ansr::Base

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
ArelMethods, Configurable, QueryMethods
Includes:
DummyAssociations, Model, Sanitization
Defined in:
lib/ansr/base.rb

Instance Method Summary collapse

Methods included from Configurable

config

Methods included from QueryMethods

all_filter_fields, all_sort_fields, ansr_qeury, as, as!, as_unscoping, as_value, as_value=, build_arel, build_facets, build_where, collapse_filters, collapse_wheres, facet, facet!, facet_unscoping, facet_values, facet_values=, field_name, filter, filter!, filter_name, filter_unscoping, filter_values, filter_values=, find, find_by_nosql, highlight, highlight!, highlight_unscoping, highlight_value, highlight_value=, spellcheck, spellcheck!, spellcheck_unscoping, spellcheck_value, spellcheck_value=

Methods included from ArelMethods

arel, arel_table

Constructor Details

#initialize(doc = {}, options = {}) ⇒ Base

Returns a new instance of Base.



14
15
16
17
# File 'lib/ansr/base.rb', line 14

def initialize doc={}, options={}
  super(filter_source_hash(doc), options)
  @source_doc = doc
end

Instance Method Details

#[](key) ⇒ Object



52
53
54
# File 'lib/ansr/base.rb', line 52

def [](key)
  @source_doc[key]
end

#columns(name = self.name) ⇒ Object



48
49
50
# File 'lib/ansr/base.rb', line 48

def columns(name=self.name)
  super(name)
end

#core_initialize(attributes = nil, options = {}) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Ansr::Base)

    the object that the method was called on



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ansr/base.rb', line 19

def core_initialize(attributes = nil, options = {})
  defaults = self.class.column_defaults.dup
  defaults.each { |k, v| defaults[k] = v.dup if v.duplicable? }

  @attributes   = self.class.initialize_attributes(defaults)
  @column_types_override = nil
  @column_types = self.class.column_types

  init_internals
  init_changed_attributes
  ensure_proper_type
  populate_with_current_scope_attributes

  # +options+ argument is only needed to make protected_attributes gem easier to hook.
  # Remove it when we drop support to this gem.
  init_attributes(attributes, options) if attributes

  yield self if block_given?
  run_callbacks :initialize unless _initialize_callbacks.empty?
end

#filter_source_hash(doc) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/ansr/base.rb', line 40

def filter_source_hash(doc)
  fields = self.class.model().table().fields()
  filtered = doc.select do |k,v|
    fields.include? k.to_sym 
  end
  filtered.with_indifferent_access
end