Module: Typus::Orm::Mongoid::ClassMethods
Instance Method Summary
collapse
#adapter, #custom_attribute?, #read_model_config, #to_resource, #typus_actions_on, #typus_application, #typus_boolean, #typus_date_format, #typus_defaults_for, #typus_description, #typus_field_options_for, #typus_filters, #typus_options_for, #typus_scopes, #typus_search_fields, #typus_template, #virtual_fields
Instance Method Details
#association_attribute?(field) ⇒ Boolean
38
39
40
|
# File 'lib/typus/orm/mongoid/class_methods.rb', line 38
def association_attribute?(field)
reflect_on_association(field).macro if reflect_on_association(field)
end
|
#model_fields ⇒ Object
Model fields as an ActiveSupport::OrderedHash.
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/typus/orm/mongoid/class_methods.rb', line 44
def model_fields
hash = ActiveSupport::OrderedHash.new
fields.each do |key, value|
hash[key.to_sym] = value.options[:type].to_s.downcase.to_sym
end
rejections = [:_id, :_type]
hash.reject { |k, v| rejections.include?(k) }
end
|
#model_relationships ⇒ Object
Model relationships as an ActiveSupport::OrderedHash.
56
57
58
59
60
|
# File 'lib/typus/orm/mongoid/class_methods.rb', line 56
def model_relationships
ActiveSupport::OrderedHash.new.tap do |hash|
relations.values.map { |i| hash[i.name] = i.macro }
end
end
|
#selector_attribute?(field) ⇒ Boolean
34
35
36
|
# File 'lib/typus/orm/mongoid/class_methods.rb', line 34
def selector_attribute?(field)
:selector if typus_field_options_for(:selectors).include?(field)
end
|
#table_name ⇒ Object
10
11
12
|
# File 'lib/typus/orm/mongoid/class_methods.rb', line 10
def table_name
collection_name
end
|
#typus_fields_for(filter) ⇒ Object
For the moment return model fields.
26
27
28
|
# File 'lib/typus/orm/mongoid/class_methods.rb', line 26
def typus_fields_for(filter)
model_fields
end
|
#typus_order_by(order_field = nil, sort_order = nil) ⇒ Object
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/typus/orm/mongoid/class_methods.rb', line 14
def typus_order_by(order_field = nil, sort_order = nil)
if order_field.nil? || sort_order.nil?
order_array = typus_defaults_for(:order_by).map do |field|
field.include?('-') ? [field.delete('-'), :desc] : [field, :asc]
end
else
order_array = [[order_field, sort_order.downcase.to_sym]]
end
self.order_by(order_array)
end
|
#typus_user_id? ⇒ Boolean
62
63
64
|
# File 'lib/typus/orm/mongoid/class_methods.rb', line 62
def typus_user_id?
fields.keys.include?(Typus.user_foreign_key)
end
|
#virtual_attribute?(field) ⇒ Boolean
30
31
32
|
# File 'lib/typus/orm/mongoid/class_methods.rb', line 30
def virtual_attribute?(field)
:virtual if virtual_fields.include?(field.to_s)
end
|