Class: MiniPaperclip::Interpolator

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_paperclip/interpolator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attachment, config) ⇒ Interpolator

Returns a new instance of Interpolator.



7
8
9
10
# File 'lib/mini_paperclip/interpolator.rb', line 7

def initialize(attachment, config)
  @attachment = attachment
  @config = config
end

Instance Attribute Details

#attachmentObject (readonly)

Returns the value of attribute attachment.



5
6
7
# File 'lib/mini_paperclip/interpolator.rb', line 5

def attachment
  @attachment
end

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/mini_paperclip/interpolator.rb', line 5

def config
  @config
end

Instance Method Details

#interpolate(template, style) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/mini_paperclip/interpolator.rb', line 12

def interpolate(template, style)
  template.dup.tap do |t|
    @config.interpolates&.each do |matcher, block|
      t.gsub!(matcher) { instance_exec(style, &block) }
    end
  end
end