Class: Padrino::Mounter
- Inherits:
-
Object
- Object
- Padrino::Mounter
- Defined in:
- lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb
Overview
Represents a particular mounted padrino application Stores the name of the application (app folder name) and url mount path
Defined Under Namespace
Classes: MounterException
Instance Attribute Summary collapse
-
#app_class ⇒ Object
Returns the value of attribute app_class.
-
#app_file ⇒ Object
Returns the value of attribute app_file.
-
#app_host ⇒ Object
Returns the value of attribute app_host.
-
#app_obj ⇒ Object
Returns the value of attribute app_obj.
-
#app_root ⇒ Object
Returns the value of attribute app_root.
-
#name ⇒ Object
Returns the value of attribute name.
-
#uri_root ⇒ Object
Returns the value of attribute uri_root.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Makes two Mounters equal if they have the same name and uri_root.
-
#app_constant ⇒ Padrino::Application
The class object for the app if defined, nil otherwise.
-
#host(mount_host) ⇒ Object
Registers the mounted application onto Padrino for the given host.
-
#initialize(name, options = {}) ⇒ Mounter
constructor
A new instance of Mounter.
-
#map_onto(router) ⇒ Padrino::Router
Maps Padrino application onto a Padrino::Router For use in constructing a Rack application.
-
#named_routes ⇒ Array
Returns the basic route information for each named route.
-
#routes ⇒ Object
Returns the route objects for the mounted application.
-
#to(mount_url) ⇒ Object
Registers the mounted application onto Padrino.
Constructor Details
#initialize(name, options = {}) ⇒ Mounter
Returns a new instance of Mounter.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 27 def initialize(name, ={}) @name = name.to_s @app_class = [:app_class] || @name.camelize @gem = [:gem] || @app_class.split("::").first.underscore @app_file = [:app_file] || locate_app_file @app_obj = [:app_obj] || app_constant || locate_app_object ensure_app_file! || ensure_app_object! @app_root = [:app_root] || File.dirname(@app_file) @uri_root = "/" Padrino::Reloader.exclude_constants << @app_class end |
Instance Attribute Details
#app_class ⇒ Object
Returns the value of attribute app_class.
14 15 16 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 14 def app_class @app_class end |
#app_file ⇒ Object
Returns the value of attribute app_file.
14 15 16 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 14 def app_file @app_file end |
#app_host ⇒ Object
Returns the value of attribute app_host.
14 15 16 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 14 def app_host @app_host end |
#app_obj ⇒ Object
Returns the value of attribute app_obj.
14 15 16 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 14 def app_obj @app_obj end |
#app_root ⇒ Object
Returns the value of attribute app_root.
14 15 16 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 14 def app_root @app_root end |
#name ⇒ Object
Returns the value of attribute name.
14 15 16 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 14 def name @name end |
#uri_root ⇒ Object
Returns the value of attribute uri_root.
14 15 16 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 14 def uri_root @uri_root end |
Instance Method Details
#==(other) ⇒ Object
Makes two Mounters equal if they have the same name and uri_root
123 124 125 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 123 def ==(other) other.is_a?(Mounter) && self.app_class == other.app_class && self.uri_root == other.uri_root end |
#app_constant ⇒ Padrino::Application
Returns the class object for the app if defined, nil otherwise.
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 131 def app_constant klass = Object for piece in app_class.split("::") piece = piece.to_sym if klass.const_defined?(piece) klass = klass.const_get(piece) else return end end klass end |
#host(mount_host) ⇒ Object
Registers the mounted application onto Padrino for the given host
65 66 67 68 69 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 65 def host(mount_host) @app_host = mount_host Padrino.insert_mounted_app(self) self end |
#map_onto(router) ⇒ Padrino::Router
Maps Padrino application onto a Padrino::Router For use in constructing a Rack application
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 82 def map_onto(router) app_data, app_obj = self, @app_obj app_obj.set :uri_root, app_data.uri_root app_obj.set :app_name, app_data.name app_obj.set :app_file, app_data.app_file unless ::File.exist?(app_obj.app_file) app_obj.set :root, app_data.app_root unless app_data.app_root.blank? app_obj.set :public_folder, Padrino.root('public', app_data.uri_root) unless File.exists?(app_obj.public_folder) app_obj.set :static, File.exist?(app_obj.public_folder) if app_obj.nil? app_obj.setup_application! # Initializes the app here with above settings. router.map(:to => app_obj, :path => app_data.uri_root, :host => app_data.app_host) end |
#named_routes ⇒ Array
Returns the basic route information for each named route
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 107 def named_routes app_obj.routes.map { |route| name_array = "(#{route.name.to_s.split("_").map { |piece| %Q[:#{piece}] }.join(", ")})" request_method = route.request_methods.first next if route.name.blank? || request_method == 'HEAD' original_path = route.original_path.is_a?(Regexp) ? route.original_path.inspect : route.original_path full_path = File.join(uri_root, original_path) OpenStruct.new(:verb => request_method, :identifier => route.name, :name => name_array, :path => full_path) }.compact end |
#routes ⇒ Object
Returns the route objects for the mounted application
97 98 99 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 97 def routes app_obj.routes end |
#to(mount_url) ⇒ Object
Registers the mounted application onto Padrino
48 49 50 51 52 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 48 def to(mount_url) @uri_root = mount_url Padrino.insert_mounted_app(self) self end |