Module: Ooor::FieldMethods::ClassMethods

Defined in:
lib/ooor/field_methods.rb

Instance Method Summary collapse

Instance Method Details

#all_fieldsObject



27
28
29
# File 'lib/ooor/field_methods.rb', line 27

def all_fields
  fields.merge(polymorphic_m2o_associations).merge(many2many_associations).merge(one2many_associations).merge(many2one_associations)
end

#define_nested_attributes_method(meth) ⇒ Object

this is used by fields_for in ActionView FormHelper



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ooor/field_methods.rb', line 39

def define_nested_attributes_method(meth)
  unless self.respond_to?(meth)
    self.instance_eval do
      define_method "#{meth}_attributes=" do |*args|
        self.send :method_missing, *[meth, *args]
      end
      define_method "#{meth}_attributes" do |*args|
        self.send :method_missing, *[meth, *args]
      end
    end
  end
end

#fast_fields(options) ⇒ Object



31
32
33
34
35
36
# File 'lib/ooor/field_methods.rb', line 31

def fast_fields(options)
  fields = all_fields
  fields.keys.select do |k|
    fields[k]["type"] != "binary" && (options[:include_functions] || !fields[k]["function"])
  end
end

#reload_fields_definition(force = false, context = connection.web_session) ⇒ Object



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

def reload_fields_definition(force=false, context=connection.web_session)
  if force || !fields
    @t.fields = {}
    @columns_hash = {}
    fields_get = rpc_execute("fields_get", false, context)
    fields_get.each { |k, field| reload_field_definition(k, field) }
    @t.associations_keys = many2one_associations.keys + one2many_associations.keys + many2many_associations.keys + polymorphic_m2o_associations.keys
    (fields.keys + associations_keys).each do |meth| #generates method handlers for auto-completion tools
      define_field_method(meth)
    end
    one2many_associations.keys.each do |meth|
      define_nested_attributes_method(meth)
    end
    logger.debug "#{fields.size} fields loaded in model #{self.name}"
    Ooor.model_registry.set_template(connection.config, @t)
  end
end