Class: Thumbor::Cascade

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/thumbor/cascade.rb

Constant Summary collapse

FILTER_REGEX =
Regexp.new('^(.+)_filter$')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key = nil, image = nil) ⇒ Cascade

Returns a new instance of Cascade.



37
38
39
40
41
42
43
# File 'lib/thumbor/cascade.rb', line 37

def initialize(key = nil, image = nil)
  @key = key
  @image = image
  @options = {}
  @filters = []
  @crypto = Thumbor::CryptoURL.new @key
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/thumbor/cascade.rb', line 49

def method_missing(method, *args)
  if method =~ FILTER_REGEX
    @filters << "#{FILTER_REGEX.match(method)[1]}(#{escape_args(args).join(',')})"
    self
  else
    super
  end
end

Instance Attribute Details

#cryptoObject

Returns the value of attribute crypto.



11
12
13
# File 'lib/thumbor/cascade.rb', line 11

def crypto
  @crypto
end

#filtersObject

Returns the value of attribute filters.



11
12
13
# File 'lib/thumbor/cascade.rb', line 11

def filters
  @filters
end

#imageObject

Returns the value of attribute image.



11
12
13
# File 'lib/thumbor/cascade.rb', line 11

def image
  @image
end

#optionsObject

Returns the value of attribute options.



11
12
13
# File 'lib/thumbor/cascade.rb', line 11

def options
  @options
end

Instance Method Details

#generateObject



45
46
47
# File 'lib/thumbor/cascade.rb', line 45

def generate
  @crypto.generate prepare_options(@options).merge({ image: @image, filters: @filters })
end

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

Returns:

  • (Boolean)


58
59
60
# File 'lib/thumbor/cascade.rb', line 58

def respond_to_missing?(method, include_private = false)
  method =~ FILTER_REGEX || super
end