Class: Dragonfly::App

Inherits:
Object show all
Extended by:
Forwardable
Includes:
Configurable
Defined in:
lib/dragonfly/app.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Configurable

included

Constructor Details

#initialize(name) ⇒ App

Returns a new instance of App


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

def initialize(name)
  @name = name
  @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


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

def analyser
  @analyser
end

#encoderObject (readonly)

Returns the value of attribute encoder


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

def encoder
  @encoder
end

#generatorObject (readonly)

Returns the value of attribute generator


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

def generator
  @generator
end

#job_definitionsObject

Returns the value of attribute job_definitions


65
66
67
# File 'lib/dragonfly/app.rb', line 65

def job_definitions
  @job_definitions
end

#nameObject (readonly)

Returns the value of attribute name


38
39
40
# File 'lib/dragonfly/app.rb', line 38

def name
  @name
end

#processorObject (readonly)

Returns the value of attribute processor


58
59
60
# File 'lib/dragonfly/app.rb', line 58

def processor
  @processor
end

#serverObject (readonly)

Returns the value of attribute server


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

def server
  @server
end

Class Method Details

.instance(name) ⇒ Object Also known as: []


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

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

Instance Method Details

#analyser_methodsObject


163
164
165
# File 'lib/dragonfly/app.rb', line 163

def analyser_methods
  analyser.analysis_method_names
end

#define_macro(mod, macro_name) ⇒ Object


135
136
137
138
139
# File 'lib/dragonfly/app.rb', line 135

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


141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/dragonfly/app.rb', line 141

def define_macro_on_include(mod, macro_name)
  app = self
  name = self.name
  (class << mod; self; end).class_eval do
    alias_method "included_without_dragonfly_#{name}_#{macro_name}", :included
    define_method "included_with_dragonfly_#{name}_#{macro_name}" do |mod|
      send "included_without_dragonfly_#{name}_#{macro_name}", mod
      app.define_macro(mod, macro_name)
    end
    alias_method :included, "included_with_dragonfly_#{name}_#{macro_name}"
  end
end

#define_url(&block) ⇒ Object


116
117
118
# File 'lib/dragonfly/app.rb', line 116

def define_url(&block)
  @url_proc = block
end

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


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

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

#generator_methodsObject


159
160
161
# File 'lib/dragonfly/app.rb', line 159

def generator_methods
  generator.functions.keys
end

#infer_mime_type_from_file_ext=(bool) ⇒ Object

Raises:

  • (NoMethodError)

186
187
188
# File 'lib/dragonfly/app.rb', line 186

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

#inspectObject


171
172
173
# File 'lib/dragonfly/app.rb', line 171

def inspect
  "<#{self.class.name} name=#{name.inspect} >"
end

#job(name, &block) ⇒ Object


76
77
78
# File 'lib/dragonfly/app.rb', line 76

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

#job_classObject


81
82
83
84
85
86
87
88
89
90
91
# File 'lib/dragonfly/app.rb', line 81

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

#job_methodsObject


167
168
169
# File 'lib/dragonfly/app.rb', line 167

def job_methods
  job_definitions.definition_names
end

#mime_type_for(format) ⇒ Object


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

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

#new_job(content = nil, meta = {}) ⇒ Object Also known as: create


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

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

#processor_methodsObject

Reflection


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

def processor_methods
  processor.functions.keys
end

#register_mime_type(format, mime_type) ⇒ Object


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

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

#registered_mime_typesObject


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

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

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


129
130
131
132
133
# File 'lib/dragonfly/app.rb', line 129

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

#response_headersObject


111
112
113
# File 'lib/dragonfly/app.rb', line 111

def response_headers
  @response_headers ||= {}
end

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


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

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

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


121
122
123
124
125
126
127
# File 'lib/dragonfly/app.rb', line 121

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)

176
177
178
# File 'lib/dragonfly/app.rb', line 176

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)

181
182
183
# File 'lib/dragonfly/app.rb', line 181

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