Module: MistralClient::Mixins::MistralObject
- Included in:
- ActionExecution, Environment, Execution, Task, Workflow
- Defined in:
- lib/mistral_client/mixins/mistral_object.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#ivars_from_response(resp) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength rubocop:disable Metrics/PerceivedComplexity.
- #list(params = {}) ⇒ Object
- #reload(id = @id) ⇒ Object
Class Method Details
.included(child) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/mistral_client/mixins/mistral_object.rb', line 4 def self.included(child) child.send(:attr_reader, :id) %w[UNICODE_FIELDS DATE_FIELDS JSON_FIELDS BOOL_FIELDS].each do |fields| next unless child.const_defined? fields child.send(:attr_reader, *child.const_get(fields)) end end |
Instance Method Details
#ivars_from_response(resp) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength rubocop:disable Metrics/PerceivedComplexity
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mistral_client/mixins/mistral_object.rb', line 33 def ivars_from_response(resp) klass = self.class @id = resp['id'] klass::UNICODE_FIELDS.each do |var| instance_variable_set("@#{var}", resp[var]) if resp[var] end klass::BOOL_FIELDS.each do |var| instance_variable_set("@#{var}", resp[var]) if resp.key? var end klass::DATE_FIELDS.each do |var| instance_variable_set("@#{var}", DateTime.parse(resp[var])) if resp[var] end klass::JSON_FIELDS.each do |var| instance_variable_set("@#{var}", JSON.parse(resp[var])) if resp[var] end end |
#list(params = {}) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/mistral_client/mixins/mistral_object.rb', line 20 def list(params = {}) resp = @server.get("#{self.class::PATH}?#{URI.encode_www_form(params)}") resp[self.class::PATH].map do |t| task = self.class.new(@server) task.ivars_from_response(t) task end end |
#reload(id = @id) ⇒ Object
14 15 16 17 18 |
# File 'lib/mistral_client/mixins/mistral_object.rb', line 14 def reload(id = @id) resp = @server.get("#{self.class::PATH}/#{id}") ivars_from_response(resp) self end |