Class: Dragonfly::App
Instance Attribute Summary collapse
-
#analyser ⇒ Object
readonly
Returns the value of attribute analyser.
-
#encoder ⇒ Object
readonly
Returns the value of attribute encoder.
-
#generator ⇒ Object
readonly
Returns the value of attribute generator.
-
#job_definitions ⇒ Object
Returns the value of attribute job_definitions.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#processor ⇒ Object
readonly
Returns the value of attribute processor.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Class Method Summary collapse
Instance Method Summary collapse
- #analyser_methods ⇒ Object
- #define_macro(mod, macro_name) ⇒ Object
- #define_macro_on_include(mod, macro_name) ⇒ Object
- #define_url(&block) ⇒ Object
- #endpoint(job = nil, &block) ⇒ Object
- #generator_methods ⇒ Object
- #infer_mime_type_from_file_ext=(bool) ⇒ Object
-
#initialize(name) ⇒ App
constructor
A new instance of App.
- #inspect ⇒ Object
- #job(name, &block) ⇒ Object
- #job_class ⇒ Object
- #job_methods ⇒ Object
- #mime_type_for(format) ⇒ Object
- #new_job(content = nil, meta = {}) ⇒ Object
-
#processor_methods ⇒ Object
Reflection.
- #register_mime_type(format, mime_type) ⇒ Object
- #registered_mime_types ⇒ Object
- #remote_url_for(uid, opts = {}) ⇒ Object
- #response_headers ⇒ Object
- #store(object, opts = {}) ⇒ Object
- #url_for(job, opts = {}) ⇒ Object
-
#url_path_prefix=(thing) ⇒ Object
Deprecated methods.
- #url_suffix=(thing) ⇒ Object
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
#analyser ⇒ Object (readonly)
Returns the value of attribute analyser
56 57 58 |
# File 'lib/dragonfly/app.rb', line 56 def analyser @analyser end |
#encoder ⇒ Object (readonly)
Returns the value of attribute encoder
58 59 60 |
# File 'lib/dragonfly/app.rb', line 58 def encoder @encoder end |
#generator ⇒ Object (readonly)
Returns the value of attribute generator
59 60 61 |
# File 'lib/dragonfly/app.rb', line 59 def generator @generator end |
#job_definitions ⇒ Object
Returns the value of attribute job_definitions
64 65 66 |
# File 'lib/dragonfly/app.rb', line 64 def job_definitions @job_definitions end |
#name ⇒ Object (readonly)
Returns the value of attribute name
38 39 40 |
# File 'lib/dragonfly/app.rb', line 38 def name @name end |
#processor ⇒ Object (readonly)
Returns the value of attribute processor
57 58 59 |
# File 'lib/dragonfly/app.rb', line 57 def processor @processor end |
#server ⇒ Object (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_methods ⇒ Object
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_methods ⇒ Object
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
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 |
#inspect ⇒ Object
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_class ⇒ Object
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_methods ⇒ Object
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, ={}) job_class.new(self, content, ) end |
#processor_methods ⇒ Object
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_types ⇒ Object
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
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_headers ⇒ Object
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
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
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 |