Module: Bulldog::HasAttachment::ClassMethods
- Defined in:
- lib/bulldog/has_attachment.rb
Instance Method Summary collapse
- #attachment_reflections ⇒ Object
- #define_attachment_accessors(name) ⇒ Object
- #define_attachment_attribute_methods(name) ⇒ Object
Instance Method Details
#attachment_reflections ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/bulldog/has_attachment.rb', line 179 def ||= begin hash = {} superhash = superclass. superhash.map do |name, reflection| hash[name] = reflection.clone end hash end end |
#define_attachment_accessors(name) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/bulldog/has_attachment.rb', line 191 def (name) module_eval " def \#{name}\n _attachment_for(:\#{name})\n end\n\n def \#{name}=(value)\n assign_attachment(:\#{name}, value)\n end\n\n def \#{name}?\n _attachment_for(:\#{name}).present?\n end\n EOS\nend\n", __FILE__, __LINE__ |
#define_attachment_attribute_methods(name) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/bulldog/has_attachment.rb', line 207 def (name) # HACK: Without this, methods defined via # #attribute_method_suffix (e.g., #ATTACHMENT_changed?) won't # be defined unless the attachment is assigned first. # ActiveRecord appears to give us no other way without # defining an after_initialize, which is slow. attribute_method_suffixes.each do |suffix| next unless suffix[0] == ?_ # skip =, ?. class_eval " def \#{name}\#{suffix}(*args, &block)\n attribute\#{suffix}('\#{name}', *args, &block)\n end\n EOS\n end\nend\n" |