Class: Props::Deferment
- Inherits:
-
Object
- Object
- Props::Deferment
- Defined in:
- lib/props_template/extensions/deferment.rb
Instance Attribute Summary collapse
-
#deferred ⇒ Object
readonly
Returns the value of attribute deferred.
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
Instance Method Summary collapse
- #disable! ⇒ Object
- #handle(options) ⇒ Object
-
#initialize(base, deferred = []) ⇒ Deferment
constructor
A new instance of Deferment.
- #refine_options(options, item = nil) ⇒ Object
Constructor Details
#initialize(base, deferred = []) ⇒ Deferment
Returns a new instance of Deferment.
5 6 7 8 9 |
# File 'lib/props_template/extensions/deferment.rb', line 5 def initialize(base, deferred = []) @deferred = deferred @base = base @disabled = false end |
Instance Attribute Details
#deferred ⇒ Object (readonly)
Returns the value of attribute deferred.
3 4 5 |
# File 'lib/props_template/extensions/deferment.rb', line 3 def deferred @deferred end |
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
3 4 5 |
# File 'lib/props_template/extensions/deferment.rb', line 3 def disabled @disabled end |
Instance Method Details
#disable! ⇒ Object
11 12 13 |
# File 'lib/props_template/extensions/deferment.rb', line 11 def disable! @disabled = true end |
#handle(options) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/props_template/extensions/deferment.rb', line 37 def handle() return if ![:defer] type, rest = [:defer] placeholder = rest[:placeholder] success_action = rest[:success_action] fail_action = rest[:fail_action] if type.to_sym == :auto && [:key] key, val = [:key] placeholder = {} placeholder[key] = val end request_path = @base.context.controller.request.fullpath path = @base.traveled_path.join(".") uri = ::URI.parse(request_path) qry = ::URI.decode_www_form(uri.query || "") .reject { |x| x[0] == "props_at" } .push(["props_at", path]) uri.query = ::URI.encode_www_form(qry) deferral = { url: uri.to_s, path: path, type: type.to_s } # camelize for JS land deferral[:successAction] = success_action if success_action deferral[:failAction] = fail_action if fail_action @deferred.push(deferral) placeholder end |
#refine_options(options, item = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/props_template/extensions/deferment.rb', line 15 def (, item = nil) return if ![:defer] pass_opts = .clone type, rest = [*[:defer]] rest ||= { placeholder: {} } if item type = (Proc === type) ? type.call(item) : type end if type pass_opts[:defer] = [type, rest] else pass_opts.delete(:defer) end pass_opts end |