module Attachs::Attachment::Attributes
Attributes
attributes[R]
options[R]
original_attributes[R]
record[R]
record_attribute[R]
source[R]
value[R]
Public Class Methods
new(record, record_attribute, options={}, attributes={})
click to toggle source
# File lib/attachs/attachment/attributes.rb, line 8 def initialize(record, record_attribute, options={}, attributes={}) @record = record @record_attribute = record_attribute @options = options @original_attributes = @attributes = attributes.deep_symbolize_keys end
Public Instance Methods
basename()
click to toggle source
# File lib/attachs/attachment/attributes.rb, line 21 def basename if filename File.basename filename, extension end end
blank?()
click to toggle source
# File lib/attachs/attachment/attributes.rb, line 37 def blank? !present? end
changed?()
click to toggle source
# File lib/attachs/attachment/attributes.rb, line 45 def changed? @original_attributes != @attributes end
extension()
click to toggle source
# File lib/attachs/attachment/attributes.rb, line 27 def extension if filename File.extname filename end end
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/attachs/attachment/attributes.rb, line 95 def method_missing(name, *args, &block) if attributes.has_key?(name) attributes[name] else super end end
old_paths()
click to toggle source
# File lib/attachs/attachment/attributes.rb, line 87 def old_paths attributes[:old_paths] ||= [] end
paths()
click to toggle source
# File lib/attachs/attachment/attributes.rb, line 83 def paths attributes[:paths] ||= {} end
persisted?()
click to toggle source
# File lib/attachs/attachment/attributes.rb, line 41 def persisted? record.persisted? && paths.any? && uploaded_at end
position()
click to toggle source
# File lib/attachs/attachment/attributes.rb, line 59 def position if options[:multiple] attributes[:position] end end
position=(value)
click to toggle source
# File lib/attachs/attachment/attributes.rb, line 65 def position=(value) if options[:multiple] attributes[:position] = value write_record end end
present?()
click to toggle source
# File lib/attachs/attachment/attributes.rb, line 33 def present? filename.present? && content_type.present? && size.present? end
respond_to_missing?(name, include_private=false)
click to toggle source
Calls superclass method
# File lib/attachs/attachment/attributes.rb, line 91 def respond_to_missing?(name, include_private=false) attributes.has_key?(name) || super end
styles()
click to toggle source
# File lib/attachs/attachment/attributes.rb, line 72 def styles case value = options[:styles] when Proc value.call(record) || {} when Hash value else {} end end
type()
click to toggle source
# File lib/attachs/attachment/attributes.rb, line 49 def type if content_type if content_type.starts_with?('image/') 'image' else 'file' end end end
Private Instance Methods
raw_attributes()
click to toggle source
# File lib/attachs/attachment/attributes.rb, line 105 def raw_attributes if options[:multiple] collection = record.send(:read_attribute, record_attribute).reject do |hash| hash['id'] == id end collection << attributes else attributes end end