Class: Dragonfly::App

Inherits:
Object show all
Defined in:
lib/dragonfly/app.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApp

Returns a new instance of App.



26
27
28
29
30
31
32
33
34
# File 'lib/dragonfly/app.rb', line 26

def initialize
  @analyser, @processor, @encoder, @generator = Analyser.new, Processor.new, Encoder.new, Generator.new
  [@analyser, @processor, @encoder, @generator].each do |obj|
    obj.use_same_log_as(self)
    obj.use_as_fallback_config(self)
  end
  @server = Server.new(self)
  @job_definitions = JobDefinitions.new
end

Instance Attribute Details

#analyserObject (readonly)

Returns the value of attribute analyser



52
53
54
# File 'lib/dragonfly/app.rb', line 52

def analyser
  @analyser
end

#encoderObject (readonly)

Returns the value of attribute encoder



54
55
56
# File 'lib/dragonfly/app.rb', line 54

def encoder
  @encoder
end

#generatorObject (readonly)

Returns the value of attribute generator



55
56
57
# File 'lib/dragonfly/app.rb', line 55

def generator
  @generator
end

#job_definitionsObject

Returns the value of attribute job_definitions



60
61
62
# File 'lib/dragonfly/app.rb', line 60

def job_definitions
  @job_definitions
end

#processorObject (readonly)

Returns the value of attribute processor



53
54
55
# File 'lib/dragonfly/app.rb', line 53

def processor
  @processor
end

#serverObject (readonly)

Returns the value of attribute server



56
57
58
# File 'lib/dragonfly/app.rb', line 56

def server
  @server
end

Class Method Details

.instance(name) ⇒ Object



12
13
14
# File 'lib/dragonfly/app.rb', line 12

def instance(name)
  apps[name] ||= new
end

Instance Method Details

#define_macro(mod, macro_name) ⇒ Object



125
126
127
128
129
# File 'lib/dragonfly/app.rb', line 125

def define_macro(mod, macro_name)
  already_extended = (class << mod; self; end).included_modules.include?(ActiveModelExtensions)
  mod.extend(ActiveModelExtensions) unless already_extended
  mod.register_dragonfly_app(macro_name, self)
end

#define_macro_on_include(mod, macro_name) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/dragonfly/app.rb', line 131

def define_macro_on_include(mod, macro_name)
  app = self
  (class << mod; self; end).class_eval do
    alias included_without_dragonfly included
    define_method :included_with_dragonfly do |mod|
      included_without_dragonfly(mod)
      app.define_macro(mod, macro_name)
    end
    alias included included_with_dragonfly
  end
end

#define_url(&block) ⇒ Object



106
107
108
# File 'lib/dragonfly/app.rb', line 106

def define_url(&block)
  @url_proc = block
end

#endpoint(job = nil, &block) ⇒ Object



67
68
69
# File 'lib/dragonfly/app.rb', line 67

def endpoint(job=nil, &block)
  block ? RoutedEndpoint.new(self, &block) : JobEndpoint.new(job)
end

#infer_mime_type_from_file_ext=(bool) ⇒ Object

Raises:

  • (NoMethodError)


154
155
156
# File 'lib/dragonfly/app.rb', line 154

def infer_mime_type_from_file_ext=(bool)
  raise NoMethodError, "infer_mime_type_from_file_ext is deprecated - please use trust_file_extensions = #{bool.inspect} instead"
end

#job(name, &block) ⇒ Object



71
72
73
# File 'lib/dragonfly/app.rb', line 71

def job(name, &block)
  job_definitions.add(name, &block)
end

#job_classObject



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/dragonfly/app.rb', line 76

def job_class
  @job_class ||= begin
    app = self
    Class.new(Job).class_eval do
      include app.analyser.analysis_methods
      include app.job_definitions
      include Job::OverrideInstanceMethods
      self
    end
  end
end

#mime_type_for(format) ⇒ Object



102
103
104
# File 'lib/dragonfly/app.rb', line 102

def mime_type_for(format)
  registered_mime_types[file_ext_string(format)]
end

#new_job(content = nil, meta = {}) ⇒ Object



62
63
64
# File 'lib/dragonfly/app.rb', line 62

def new_job(content=nil, meta={})
  job_class.new(self, content, meta)
end

#register_mime_type(format, mime_type) ⇒ Object



93
94
95
# File 'lib/dragonfly/app.rb', line 93

def register_mime_type(format, mime_type)
  registered_mime_types[file_ext_string(format)] = mime_type
end

#registered_mime_typesObject



98
99
100
# File 'lib/dragonfly/app.rb', line 98

def registered_mime_types
  @registered_mime_types ||= Rack::Mime::MIME_TYPES.dup
end

#remote_url_for(uid, opts = {}) ⇒ Object

Raises:

  • (NotImplementedError)


119
120
121
122
123
# File 'lib/dragonfly/app.rb', line 119

def remote_url_for(uid, opts={})
  datastore.url_for(uid, opts)
rescue NoMethodError => e
  raise NotImplementedError, "The datastore doesn't support serving content directly - #{datastore.inspect}"
end

#store(object, opts = {}) ⇒ Object



88
89
90
91
# File 'lib/dragonfly/app.rb', line 88

def store(object, opts={})
  temp_object = object.is_a?(TempObject) ? object : TempObject.new(object)
  datastore.store(temp_object, opts)
end

#url_for(job, opts = {}) ⇒ Object



111
112
113
114
115
116
117
# File 'lib/dragonfly/app.rb', line 111

def url_for(job, opts={})
  if @url_proc
    @url_proc.call(self, job, opts)
  else
    server.url_for(job, opts)
  end
end

#url_path_prefix=(thing) ⇒ Object

Deprecated methods

Raises:

  • (NoMethodError)


144
145
146
# File 'lib/dragonfly/app.rb', line 144

def url_path_prefix=(thing)
  raise NoMethodError, "url_path_prefix is deprecated - please use url_format, e.g. url_format = '/media/:job/:basename.:format' - see docs for more details"
end

#url_suffix=(thing) ⇒ Object

Raises:

  • (NoMethodError)


149
150
151
# File 'lib/dragonfly/app.rb', line 149

def url_suffix=(thing)
  raise NoMethodError, "url_suffix is deprecated - please use url_format, e.g. url_format = '/media/:job/:basename.:format' - see docs for more details"
end