Class: Bormashino::Fetch
- Inherits:
-
Object
- Object
- Bormashino::Fetch
- Defined in:
- lib/bormashino/fetch.rb
Instance Attribute Summary collapse
-
#init ⇒ Object
Returns the value of attribute init.
-
#resolved_to ⇒ Object
Returns the value of attribute resolved_to.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
-
#initialize(resource:, resolved_to:, init: {}) ⇒ Fetch
constructor
A new instance of Fetch.
- #run ⇒ Object
Constructor Details
#initialize(resource:, resolved_to:, init: {}) ⇒ Fetch
Returns a new instance of Fetch.
8 9 10 11 12 |
# File 'lib/bormashino/fetch.rb', line 8 def initialize(resource:, resolved_to:, init: {}) @resource = resource @init = init @resolved_to = resolved_to end |
Instance Attribute Details
#init ⇒ Object
Returns the value of attribute init.
6 7 8 |
# File 'lib/bormashino/fetch.rb', line 6 def init @init end |
#resolved_to ⇒ Object
Returns the value of attribute resolved_to.
6 7 8 |
# File 'lib/bormashino/fetch.rb', line 6 def resolved_to @resolved_to end |
#resource ⇒ Object
Returns the value of attribute resource.
6 7 8 |
# File 'lib/bormashino/fetch.rb', line 6 def resource @resource end |
Instance Method Details
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bormashino/fetch.rb', line 14 def run raise 'No app is mounted' unless Bormashino::Server.mounted? # rubocop:disable Style::DocumentDynamicEvalDefinition JS.eval <<-ENDOFEVAL fetch( #{@resource.to_json}, #{@init.to_json} ).then((r) => { r.text().then((t) => { window.bormashino.request( 'post', #{@resolved_to.to_json}, 'status=' + r.status + '&payload=' + encodeURIComponent(t) ) }) }) ENDOFEVAL # rubocop:enable Style::DocumentDynamicEvalDefinition end |