Class: Conductor::Http::Models::BaseModel
- Inherits:
-
Object
- Object
- Conductor::Http::Models::BaseModel
- Defined in:
- lib/conductor/http/models/base_model.rb
Overview
Base class for all Conductor model objects Implements the SWAGGER_TYPES pattern from Python SDK
Direct Known Subclasses
AuthenticationConfig, AuthorizationRequest, BulkResponse, CacheConfig, ConductorApplication, ConductorUser, CreateOrUpdateApplicationRequest, CreateOrUpdateRoleRequest, EventHandler, EventHandlerAction, GenerateTokenRequest, Group, Integration, IntegrationApi, IntegrationApiUpdate, IntegrationUpdate, Permission, PollData, PromptTemplate, PromptTemplateTestRequest, RerunWorkflowRequest, Role, SaveScheduleRequest, SchemaDef, SearchResult, SkipTaskRequest, StartWorkflow, StartWorkflowRequest, SubWorkflowParams, SubjectRef, TagObject, TargetRef, Task, TaskDef, TaskDetails, TaskExecLog, TaskResult, TaskSummary, Token, UpsertGroupRequest, UpsertUserRequest, Workflow, WorkflowDef, WorkflowRun, WorkflowSchedule, WorkflowStateUpdate, WorkflowSummary, WorkflowTask, WorkflowTestRequest, WorkflowTestTaskResult, Orkes::Models::AccessKey, Orkes::Models::CreatedAccessKey, Orkes::Models::GrantedPermission
Class Method Summary collapse
- .attribute_map ⇒ Object
- .deserialize_model(value, type) ⇒ Object
-
.deserialize_value(value, type) ⇒ Object
Deserialize a value based on type string.
- .find_model_class(type) ⇒ Object
-
.from_hash(hash) ⇒ Object
Build model from hash (deserialization).
-
.from_json(json_string) ⇒ Object
Build model from JSON string.
- .parse_datetime(value) ⇒ Object
-
.swagger_types ⇒ Object
Class method to define swagger types and attribute mappings.
Instance Method Summary collapse
-
#to_h ⇒ Object
(also: #to_hash)
Convert model to hash using ATTRIBUTE_MAP for JSON keys.
-
#to_json(*_args) ⇒ Object
Convert model to JSON string.
Class Method Details
.attribute_map ⇒ Object
17 18 19 |
# File 'lib/conductor/http/models/base_model.rb', line 17 def self.attribute_map self::ATTRIBUTE_MAP end |
.deserialize_model(value, type) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/conductor/http/models/base_model.rb', line 137 def self.deserialize_model(value, type) # If value is not a Hash (e.g., a string expression), return as-is return value unless value.is_a?(Hash) # Try to find the model class klass = find_model_class(type) return value unless klass # If it's already the right type, return it return value if value.is_a?(klass) # Deserialize hash to model klass.respond_to?(:from_hash) ? klass.from_hash(value) : value end |
.deserialize_value(value, type) ⇒ Object
Deserialize a value based on type string
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/conductor/http/models/base_model.rb', line 85 def self.deserialize_value(value, type) return nil if value.nil? return value if type.nil? # Handle array types: "Array<Type>" if type.start_with?('Array<') inner_type = type[6..-2] # Extract Type from Array<Type> return value.map { |v| deserialize_value(v, inner_type) } end # Handle hash types: "Hash<String, Type>" or "Hash{String => Type}" if type.start_with?('Hash<', 'Hash{') # Extract value type from Hash<K, V> or Hash{K => V} match = type.match(/Hash[<{].*,\s*(.+)[>}]/) value_type = match[1] if match return value.transform_values { |v| deserialize_value(v, value_type) } end # Handle primitive types case type when 'String' value.to_s when 'Integer' value.to_i when 'Float' value.to_f when 'Boolean', 'BOOLEAN' value.to_s.downcase == 'true' when 'DateTime' parse_datetime(value) when 'Date' Date.parse(value.to_s) when 'Time' Time.parse(value.to_s) when 'Object' value else # Model class - convert to proper class deserialize_model(value, type) end end |
.find_model_class(type) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/conductor/http/models/base_model.rb', line 152 def self.find_model_class(type) # Try to find class in Conductor::Http::Models namespace const_name = type.split('::').last Conductor::Http::Models.const_get(const_name) if Conductor::Http::Models.const_defined?(const_name) rescue NameError nil end |
.from_hash(hash) ⇒ Object
Build model from hash (deserialization)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/conductor/http/models/base_model.rb', line 42 def self.from_hash(hash) return nil unless hash # If it's not a Hash (e.g., a string expression like "${workflow.input.foo}"), # return it as-is rather than trying to deserialize return hash unless hash.is_a?(Hash) instance = new attribute_map.each do |attr, json_key| json_key_str = json_key.to_s next unless hash.key?(json_key_str) || hash.key?(json_key.to_sym) value = hash[json_key_str] || hash[json_key.to_sym] type = swagger_types[attr] instance.send("#{attr}=", deserialize_value(value, type)) end instance end |
.from_json(json_string) ⇒ Object
Build model from JSON string
62 63 64 |
# File 'lib/conductor/http/models/base_model.rb', line 62 def self.from_json(json_string) from_hash(JSON.parse(json_string)) end |
.parse_datetime(value) ⇒ Object
127 128 129 130 131 132 133 134 135 |
# File 'lib/conductor/http/models/base_model.rb', line 127 def self.parse_datetime(value) return value if value.is_a?(DateTime) || value.is_a?(Time) # Try ISO8601 first DateTime.iso8601(value.to_s) rescue ArgumentError # Fall back to regular parsing DateTime.parse(value.to_s) end |
.swagger_types ⇒ Object
Class method to define swagger types and attribute mappings
13 14 15 |
# File 'lib/conductor/http/models/base_model.rb', line 13 def self.swagger_types self::SWAGGER_TYPES end |
Instance Method Details
#to_h ⇒ Object Also known as: to_hash
Convert model to hash using ATTRIBUTE_MAP for JSON keys
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/conductor/http/models/base_model.rb', line 22 def to_h hash = {} self.class.attribute_map.each do |attr, json_key| value = send(attr) next if value.nil? hash[json_key.to_s] = serialize_value(value) end hash end |
#to_json(*_args) ⇒ Object
Convert model to JSON string
37 38 39 |
# File 'lib/conductor/http/models/base_model.rb', line 37 def to_json(*_args) JSON.generate(to_h) end |