Module: Flex::ClassProxy::ModelIndexer

Defined in:
lib/flex/class_proxy/model_indexer.rb

Defined Under Namespace

Modules: Types

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parent_associationObject (readonly)

Returns the value of attribute parent_association.



12
13
14
# File 'lib/flex/class_proxy/model_indexer.rb', line 12

def parent_association
  @parent_association
end

#parent_child_mapObject (readonly)

Returns the value of attribute parent_child_map.



12
13
14
# File 'lib/flex/class_proxy/model_indexer.rb', line 12

def parent_child_map
  @parent_child_map
end

Instance Method Details

#default_mappingObject



34
35
36
37
38
39
40
41
42
# File 'lib/flex/class_proxy/model_indexer.rb', line 34

def default_mapping
  default = {}.extend Struct::Mergeable
  if is_child?
    parent_child_map.each do |parent, child|
      default.deep_merge! index => {'mappings' => {child => {'_parent' => {'type' => parent}}}}
    end
  end
  default
end

#initObject



14
15
16
# File 'lib/flex/class_proxy/model_indexer.rb', line 14

def init
  variables.deep_merge! :type  => Utils.class_name_to_type(context.name)
end

#is_child?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/flex/class_proxy/model_indexer.rb', line 26

def is_child?
  !!@is_child
end

#is_parent?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/flex/class_proxy/model_indexer.rb', line 30

def is_parent?
  @is_parent ||= Types.parents.include?(type)
end

#parent(parent_association, map) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/flex/class_proxy/model_indexer.rb', line 18

def parent(parent_association, map)
  @parent_association = parent_association
  Types.parents      |= map.keys.map(&:to_s)
  self.type           = map.values.map(&:to_s)
  @parent_child_map   = map
  @is_child           = true
end