Class: PrestoCore::Slice
- Inherits:
-
Object
- Object
- PrestoCore::Slice
- Includes:
- Utils
- Defined in:
- lib/presto/core/slice.rb
Constant Summary
Constant Summary
Constants included from Utils
Utils::PATH_MODIFIERS, Utils::STATUS__NOT_FOUND, Utils::STATUS__OK, Utils::STATUS__PERMANENT_REDIRECT, Utils::STATUS__REDIRECT, Utils::STATUS__RESTRICTED, Utils::STATUS__SERVER_ERROR
Instance Attribute Summary (collapse)
-
- (Object) canonical
readonly
Returns the value of attribute canonical.
-
- (Object) controllers
readonly
Returns the value of attribute controllers.
-
- (Object) http
readonly
Returns the value of attribute http.
-
- (Object) root
readonly
Returns the value of attribute root.
-
- (Object) view
readonly
Returns the value of attribute view.
Instance Method Summary (collapse)
- - (Object) add_controllers(*controllers)
- - (Boolean) configurable?
-
- (Object) ctrl
set controller settings at slice level.
-
- (Object) initialize(namespace = nil, *paths) {|slice| ... }
constructor
creating an app slice from given namespace.
- - (Object) lock
Methods included from Utils
build_path, #extract_controllers, is_controller?, normalize_path, rootify_url
Constructor Details
- (Object) initialize(namespace = nil, *paths) {|slice| ... }
creating an app slice from given namespace. this will select all controllers in given namespace and update their slice, setting it to one initialized here.
given block will receive slice object as first arg and will can configure it. controllers under slice will use slice's setup beside own internal setup.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/presto/core/slice.rb', line 31 def initialize namespace = nil, *paths, &proc @controllers = [] extract_controllers namespace if namespace @root = rootify(paths.shift).freeze @canonical = paths.map { |p| rootify(p) }.freeze @http = ::PrestoHTTP::Slice.new self @view = ::PrestoView::Slice.new self # configuring slice if block given self.instance_exec(self, &proc) if proc if @controllers.size > 0 helpers = ctrl.helpers @controllers.each do |controller| controller.ctrl.slice self helpers.each_pair { |h, p| controller.ctrl.helper h, &(p||lambda {}) } end map_controllers end end |
Instance Attribute Details
- (Object) canonical (readonly)
Returns the value of attribute canonical
6 7 8 |
# File 'lib/presto/core/slice.rb', line 6 def canonical @canonical end |
- (Object) controllers (readonly)
Returns the value of attribute controllers
6 7 8 |
# File 'lib/presto/core/slice.rb', line 6 def controllers @controllers end |
- (Object) http (readonly)
Returns the value of attribute http
6 7 8 |
# File 'lib/presto/core/slice.rb', line 6 def http @http end |
- (Object) root (readonly)
Returns the value of attribute root
6 7 8 |
# File 'lib/presto/core/slice.rb', line 6 def root @root end |
- (Object) view (readonly)
Returns the value of attribute view
6 7 8 |
# File 'lib/presto/core/slice.rb', line 6 def view @view end |
Instance Method Details
- (Object) add_controllers(*controllers)
69 70 71 72 73 |
# File 'lib/presto/core/slice.rb', line 69 def add_controllers *controllers controllers.each { |c| c.ctrl.slice self } @controllers.concat controllers map_controllers end |
- (Boolean) configurable?
79 80 81 |
# File 'lib/presto/core/slice.rb', line 79 def configurable? @locked.nil? end |
- (Object) ctrl
set controller settings at slice level
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/presto/core/slice.rb', line 57 def ctrl @ctrl_proxy ||= Class.new do def self.helper *helpers, &proc helpers.each { |h| helpers()[h] = proc } end def self.helpers @helpers ||= {} end end end |
- (Object) lock
75 76 77 |
# File 'lib/presto/core/slice.rb', line 75 def lock @locked = true end |