Module: Imgix::ModelExtensions::ClassMethods

Defined in:
lib/imgix/model_extensions.rb

Instance Method Summary collapse

Instance Method Details

#has_imgix_attachment(name, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/imgix/model_extensions.rb', line 12

def has_imgix_attachment(name, options = {})
  include InstanceMethods

  imgix_config.base_url(options.delete(:base_url))
  imgix_config.protocol(options.delete(:protocol))
  imgix_config.subdomain(options.delete(:subdomain))

  define_method(name) do |*args|
    a = Imgix::Attachment.new(name, self, options)
  end

  # simple helper method to use instead of having to use
  # the name provided
  define_method("imgix_attachment") do ||
    self.send(name)
  end

  # Define how the setter of our attachment works
  # define_method "#{name}=" do |file|
  #   attachment_for(name).assign(file)
  # end

  # Determine if the attachment is valid
  # define_method "#{name}?" do
  #   attachment_for(name).file?
  # end
end

#imgix_configObject



8
9
10
# File 'lib/imgix/model_extensions.rb', line 8

def imgix_config
  @imgix_config ||= Imgix::Config.new
end