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
- #extract_deferment_type(options, item) ⇒ Object
- #handle(options, type, key, val) ⇒ Object
-
#initialize(base, deferred = []) ⇒ Deferment
constructor
A new instance of Deferment.
- #refine_options(options, item = nil) ⇒ Object
Constructor Details
#initialize(base, deferred = []) ⇒ 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 |
#extract_deferment_type(options, item) ⇒ Object
19 20 21 22 |
# File 'lib/props_template/extensions/deferment.rb', line 19 def extract_deferment_type(, item) type, _ = [*[:defer]] (Proc === type) ? type.call(item) : type end |
#handle(options, type, key, val) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 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 |
# File 'lib/props_template/extensions/deferment.rb', line 24 def handle(, type, key, val) return if ![:defer] _, rest = [*[:defer]] rest ||= { placeholder: {} } placeholder = rest[:placeholder] success_action = rest[:success_action] fail_action = rest[:fail_action] if type.to_sym == :auto && key && val 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 |
# File 'lib/props_template/extensions/deferment.rb', line 15 def (, item = nil) .clone end |