Module: Upmin::Railties::ActiveRecord::ClassMethods
- Defined in:
- lib/upmin/railties/active_record.rb
Instance Method Summary collapse
-
#upmin_actions(*actions) ⇒ Object
@upmin_collections = [] ignored_collections self.reflect_on_all_associations.each do |reflection| @upmin_collections.name.to_sym << if reflection.collection? if reflection.is_a?(ActiveRecord::Reflection::ThroughReflection) # We need to figure out what collection to ignore.
- #upmin_associations(*associations) ⇒ Object
- #upmin_attributes(*attributes) ⇒ Object
- #upmin_collection_reflections ⇒ Object
- #upmin_color ⇒ Object
-
#upmin_methods(*methods) ⇒ Object
Alias for upmin_actions.
- #upmin_name(type = :plural) ⇒ Object
Instance Method Details
#upmin_actions(*actions) ⇒ Object
@upmin_collections = []
ignored_collections
self.reflect_on_all_associations.each do |reflection|
@upmin_collections.name.to_sym << if reflection.collection?
if reflection.is_a?(ActiveRecord::Reflection::ThroughReflection)
# We need to figure out what collection to ignore.
@upmin_collections.name.to_sym
end
end
return @upmin_collections
end
133 134 135 136 137 138 |
# File 'lib/upmin/railties/active_record.rb', line 133 def upmin_actions(*actions) if actions.any? @upmin_actions = actions.map{|a| a.to_sym} end return @upmin_actions end |
#upmin_associations(*associations) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/upmin/railties/active_record.rb', line 87 def upmin_associations(*associations) if associations.any? @upmin_associations = associations.map{|a| a.to_sym} end return @upmin_associations if defined?(@upmin_associations) # TODO(jon): Make this handle through relationships and ignore those. upmin_associations = [] ignored_associations = [] self.reflect_on_all_associations.each do |reflection| upmin_associations << reflection.name.to_sym if reflection.is_a?(::ActiveRecord::Reflection::ThroughReflection) ignored_associations << reflection.[:through] end end return @upmin_associations = upmin_associations - ignored_associations end |
#upmin_attributes(*attributes) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/upmin/railties/active_record.rb', line 66 def upmin_attributes(*attributes) if attributes.any? @upmin_attributes = attributes.map{|a| a.to_sym} end @upmin_attributes ||= attribute_names.map{|a| a.to_sym} return @upmin_attributes end |
#upmin_collection_reflections ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/upmin/railties/active_record.rb', line 105 def upmin_collection_reflections return @upmin_collection_reflections if defined?(@upmin_collection_reflections) collections = self.reflect_on_all_associations.select do |r| r.collection? end.map do |r| r.name end return @upmin_collection_reflections = collections end |
#upmin_color ⇒ Object
149 150 151 152 |
# File 'lib/upmin/railties/active_record.rb', line 149 def upmin_color return @upmin_color if defined?(@upmin_color) return @upmin_color = Upmin::Model.find(self.name).color end |
#upmin_methods(*methods) ⇒ Object
Alias for upmin_actions
82 83 84 |
# File 'lib/upmin/railties/active_record.rb', line 82 def upmin_methods(*methods) return upmin_actions(*methods) end |
#upmin_name(type = :plural) ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/upmin/railties/active_record.rb', line 141 def upmin_name(type = :plural) names = name.split(/(?=[A-Z])/) if type == :plural names[names.length-1] = names.last.pluralize end return names.join(" ") end |