module Upmin::ActiveRecord::Model::ClassMethods
Public Instance Methods
associations()
click to toggle source
# File lib/upmin/active_record/model.rb, line 48 def associations return @associations if defined?(@associations) all = [] ignored = [] model_class.reflect_on_all_associations.each do |reflection| all << reflection.name.to_sym # We need to remove the ignored later because we don't know the order they come in. if reflection.is_a?(::ActiveRecord::Reflection::ThroughReflection) ignored << reflection.options[:through] end end return @associations = (all - ignored).uniq end
attribute_type(attribute)
click to toggle source
# File lib/upmin/active_record/model.rb, line 28 def attribute_type(attribute) adapter = model_class.columns_hash[attribute.to_s] if adapter if attribute.in? enum_attributes return :enum else return adapter.type end end return :unknown end
default_attributes()
click to toggle source
# File lib/upmin/active_record/model.rb, line 24 def default_attributes return model_class.attribute_names.map(&:to_sym) end
enum_attributes()
click to toggle source
# File lib/upmin/active_record/model.rb, line 40 def enum_attributes if model_class.respond_to? :defined_enums model_class.defined_enums.keys.map(&:to_sym) else [] end end
find(*args)
click to toggle source
NOTE - ANY method added here must be added to the bottom of Upmin::Model
. This ensures that an instance of the class was created, which in turn ensures that the correct module was included in the class.
# File lib/upmin/active_record/model.rb, line 20 def find(*args) return model_class.find(*args) end