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

#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



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

def analyser
  @analyser
end

#encoderObject (readonly)

Returns the value of attribute encoder



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

def encoder
  @encoder
end

#generatorObject (readonly)

Returns the value of attribute generator



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

def generator
  @generator
end

#job_definitionsObject

Returns the value of attribute job_definitions



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

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



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

def processor
  @processor
end

#serverObject (readonly)

Returns the value of attribute server



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

def server
  @server
end

Class Method Details

.instance(name) ⇒ Object



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



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

def analyser_methods
  analyser.analysis_method_names
end

#define_macro(mod, macro_name) ⇒ Object



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

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



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

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



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

def define_url(&block)
  @url_proc = block
end

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



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

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

#generator_methodsObject



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

def generator_methods
  generator.functions.keys
end

#infer_mime_type_from_file_ext=(bool) ⇒ Object

Raises:

  • (NoMethodError)


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

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



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

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

#job(name, &block) ⇒ Object



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

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

#job_classObject



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

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



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

def job_methods
  job_definitions.definition_names
end

#mime_type_for(format) ⇒ Object



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

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

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



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

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

#processor_methodsObject

Reflection



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

def processor_methods
  processor.functions.keys
end

#register_mime_type(format, mime_type) ⇒ Object



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

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

#registered_mime_typesObject



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

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

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

Raises:

  • (NotImplementedError)


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

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



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

def response_headers
  @response_headers ||= {}
end

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



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

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



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

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)


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

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)


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

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