Class: Dragonfly::App

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

Instance Attribute Summary (collapse)

Configuration Summary

Configurable attributes

Configurable attributes for an object in general object can be configured either by using something like
  object.configure do |c|
    c.some_configurable_attribute = "some value"
    c.some_other_configurable_attribute = 42
    ...
  end
or
  object.some_configurable_attribute = "some value"

Configurable attributes for instances of Dragonfly::App

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Configurable

included

Constructor Details

- (App) initialize(name)

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

- (Object) analyser (readonly)

Returns the value of attribute analyser



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

def analyser
  @analyser
end

- (Object) encoder (readonly)

Returns the value of attribute encoder



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

def encoder
  @encoder
end

- (Object) generator (readonly)

Returns the value of attribute generator



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

def generator
  @generator
end

- (Object) job_definitions

Returns the value of attribute job_definitions



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

def job_definitions
  @job_definitions
end

- (Object) name (readonly)

Returns the value of attribute name



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

def name
  @name
end

- (Object) processor (readonly)

Returns the value of attribute processor



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

def processor
  @processor
end

- (Object) server (readonly)

Returns the value of attribute server



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

def server
  @server
end

Class Method Details

+ (Object) instance(name) 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

- (Object) analyser_methods



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

def analyser_methods
  analyser.analysis_method_names
end

- (Object) define_macro(mod, macro_name)



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

- (Object) define_macro_on_include(mod, macro_name)



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

- (Object) define_url(&block)



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

def define_url(&block)
  @url_proc = block
end

- (Object) endpoint(job = nil, &block)



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

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

- (Object) generator_methods



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

def generator_methods
  generator.functions.keys
end

- (Object) infer_mime_type_from_file_ext=(bool)

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

- (Object) inspect



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

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

- (Object) job(name, &block)



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

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

- (Object) job_class



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

- (Object) job_methods



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

def job_methods
  job_definitions.definition_names
end

- (Object) mime_type_for(format)



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

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

- (Object) new_job(content = nil, meta = {}) 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

- (Object) processor_methods

Reflection



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

def processor_methods
  processor.functions.keys
end

- (Object) register_mime_type(format, mime_type)



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

- (Object) registered_mime_types



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

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

- (Object) remote_url_for(uid, opts = {})

Raises:

  • (NotImplementedError)


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

- (Object) response_headers



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

def response_headers
  @response_headers ||= {}
end

- (Object) store(object, opts = {})



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

- (Object) url_for(job, opts = {})



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

- (Object) url_path_prefix=(thing)

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

- (Object) url_suffix=(thing)

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