Class: Sequel::Plugins::Paperclip::Interpolations

Inherits:
Object
  • Object
show all
Defined in:
lib/sequel_paperclip/interpolations.rb

Class Method Summary collapse

Class Method Details

.basename(attachment, model, style) ⇒ Object



50
51
52
# File 'lib/sequel_paperclip/interpolations.rb', line 50

def self.basename(attachment, model, style)
  model.send("#{attachment.name}_basename")
end

.extname(attachment, model, style) ⇒ Object



54
55
56
# File 'lib/sequel_paperclip/interpolations.rb', line 54

def self.extname(attachment, model, style)
  model.send("#{attachment.name}_extname")
end

.filename(attachment, model, style) ⇒ Object



42
43
44
# File 'lib/sequel_paperclip/interpolations.rb', line 42

def self.filename(attachment, model, style)
  model.send("#{attachment.name}_filename")
end

.filesize(attachment, model, style) ⇒ Object



46
47
48
# File 'lib/sequel_paperclip/interpolations.rb', line 46

def self.filesize(attachment, model, style)
  model.send("#{attachment.name}_filesize")
end

.format(attachment, model, style) ⇒ Object



38
39
40
# File 'lib/sequel_paperclip/interpolations.rb', line 38

def self.format(attachment, model, style)
  attachment.options[:styles][style][:format]
end

.host(attachment, model, style) ⇒ Object



26
27
28
# File 'lib/sequel_paperclip/interpolations.rb', line 26

def self.host(attachment, model, style)
  "/system"
end

.id(attachment, model, style) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
# File 'lib/sequel_paperclip/interpolations.rb', line 17

def self.id(attachment, model, style)
  raise ArgumentError, "record has no id" unless model.id
  model.id
end

.interpolate(string, attachment, model, style) ⇒ Object



11
12
13
14
15
# File 'lib/sequel_paperclip/interpolations.rb', line 11

def self.interpolate(string, attachment, model, style)
  string.gsub(/:\w+:/i) do |tag|
    send(tag[1..-2], attachment, model, style)
  end
end

.model(attachment, model, style) ⇒ Object



22
23
24
# File 'lib/sequel_paperclip/interpolations.rb', line 22

def self.model(attachment, model, style)
  model.class.to_s.underscore.pluralize
end

.path(attachment, model, style) ⇒ Object



30
31
32
# File 'lib/sequel_paperclip/interpolations.rb', line 30

def self.path(attachment, model, style)
  "#{Rails.root}/public/system"
end

.rails_env(attachment, model, style) ⇒ Object



62
63
64
# File 'lib/sequel_paperclip/interpolations.rb', line 62

def self.rails_env(attachment, model, style)
  Rails.env
end

.rails_root(attachment, model, style) ⇒ Object



58
59
60
# File 'lib/sequel_paperclip/interpolations.rb', line 58

def self.rails_root(attachment, model, style)
  Rails.root
end

.set(name, &block) ⇒ Object



5
6
7
8
9
# File 'lib/sequel_paperclip/interpolations.rb', line 5

def self.set(name, &block)
  (class << self; self; end).instance_eval do
    define_method(name, &block)
  end
end

.style(attachment, model, style) ⇒ Object



34
35
36
# File 'lib/sequel_paperclip/interpolations.rb', line 34

def self.style(attachment, model, style)
  style
end