Class: CarrierWave::Uploader::Versions::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave/uploader/versions.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Builder

Returns a new instance of Builder.



7
8
9
10
11
12
# File 'lib/carrierwave/uploader/versions.rb', line 7

def initialize(name)
  @name = name
  @options = {}
  @blocks = []
  @klass = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/carrierwave/uploader/versions.rb', line 73

def method_missing(name, *args)
  super
rescue NoMethodError => e
  raise e.exception "    \#{e.message}\n    If you're trying to configure a version, do it inside a block like `version(:thumb) { self.\#{name} \#{args.map(&:inspect).join(', ')} }`.\n  ERROR\nend\n"

Instance Method Details

#build(superclass) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/carrierwave/uploader/versions.rb', line 20

def build(superclass)
  return @klass if @klass
  @klass = Class.new(superclass)
  superclass.const_set("VersionUploader#{@name.to_s.camelize}", @klass)

  @klass.version_names += [@name]
  @klass.versions = {}
  @klass.processors = []
  @klass.version_options = @options
  @klass.class_eval "    # Define the enable_processing method for versions so they get the\n    # value from the parent class unless explicitly overwritten\n    def self.enable_processing(value=nil)\n      self.enable_processing = value if value\n      if defined?(@enable_processing) && !@enable_processing.nil?\n        @enable_processing\n      else\n        superclass.enable_processing\n      end\n    end\n\n    # Regardless of what is set in the parent uploader, do not enforce the\n    # move_to_cache config option on versions because it moves the original\n    # file to the version's target file.\n    #\n    # If you want to enforce this setting on versions, override this method\n    # in each version:\n    #\n    # version :thumb do\n    #   def move_to_cache\n    #     true\n    #   end\n    # end\n    #\n    def move_to_cache\n      false\n    end\n\n    # Need to rely on the parent version's identifier, as versions don't have its own one.\n    def identifier\n      parent_version.identifier\n    end\n  RUBY\n  @blocks.each { |block| @klass.class_eval(&block) }\n  @klass\nend\n", __FILE__, __LINE__ + 1

#configure(options, &block) ⇒ Object



14
15
16
17
18
# File 'lib/carrierwave/uploader/versions.rb', line 14

def configure(options, &block)
  @options.merge!(options)
  @blocks << block if block
  @klass = nil
end

#deep_dupObject



67
68
69
70
71
# File 'lib/carrierwave/uploader/versions.rb', line 67

def deep_dup
  other = dup
  other.instance_variable_set(:@blocks, @blocks.dup)
  other
end

#respond_to_missing?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/carrierwave/uploader/versions.rb', line 82

def respond_to_missing?(*)
  super
end