Module: Flex::ClassProxy::ActiveModel

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

Instance Method Summary collapse

Instance Method Details

#add_callbacksObject

overrides the ModelSyncer#add_callbacks



29
30
31
# File 'lib/flex/class_proxy/active_model.rb', line 29

def add_callbacks
  # no callbacks to add, since it calls flex.sync on save and destroy
end

#default_mappingObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/flex/class_proxy/active_model.rb', line 9

def default_mapping
  props = { }
  context.attributes.each do |name, attr|
    options     = attr.send(:options)
    props[name] = case
                  when options.has_key?(:properties)
                    Utils.keyfy(:to_s, attr.send(:options)[:properties])
                  when options.has_key?(:not_analyzed) && options[:not_analyzed] ||
                       options.has_key?(:analyzed)     && !options[:analyzed]
                    { 'type' => 'string', 'index' => 'not_analyzed' }
                  when options[:type] == DateTime
                    { 'type' => 'date', 'format' => 'dateOptionalTime' }
                  else
                    next
                  end
  end
  props.empty? ? super :  super.deep_merge(index => {'mappings' => {type => {'properties' => props}}})
end

#init(*vars) ⇒ Object



5
6
7
# File 'lib/flex/class_proxy/active_model.rb', line 5

def init(*vars)
  variables.deep_merge! *vars
end