Class: SimplyCouch::HasAttachment::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/simply_couch/has_attachment.rb

Overview

Proxy object returned by attachment getters (e.g. ‘image.file`). Mimics the Paperclip::Attachment API that views expect.

Instance Method Summary collapse

Constructor Details

#initialize(record, name) ⇒ Proxy

Returns a new instance of Proxy.



47
48
49
50
# File 'lib/simply_couch/has_attachment.rb', line 47

def initialize(record, name)
  @record = record
  @name = name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Delegate anything else to the record



77
78
79
80
81
82
83
# File 'lib/simply_couch/has_attachment.rb', line 77

def method_missing(method, *args, &block)
  if @record.respond_to?(method, true)
    @record.send(method, *args, &block)
  else
    super
  end
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/simply_couch/has_attachment.rb', line 56

def blank?
  !present?
end

#content_typeObject



68
69
70
# File 'lib/simply_couch/has_attachment.rb', line 68

def content_type
  @record.send(:"#{@name}_content_type")
end

#original_filenameObject



64
65
66
# File 'lib/simply_couch/has_attachment.rb', line 64

def original_filename
  @record.send(:"#{@name}_file_name")
end

#present?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/simply_couch/has_attachment.rb', line 52

def present?
  @record.send(:"#{@name}_file_name").present?
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/simply_couch/has_attachment.rb', line 85

def respond_to_missing?(method, include_private = false)
  @record.respond_to?(method, include_private) || super
end

#sizeObject



72
73
74
# File 'lib/simply_couch/has_attachment.rb', line 72

def size
  @record.send(:"#{@name}_file_size")
end

#url(style = nil) ⇒ Object



60
61
62
# File 'lib/simply_couch/has_attachment.rb', line 60

def url(style = nil)
  @record.send(:"#{@name}_url", style)
end