Class: Merge::Accounting::RemoteFieldClass

Inherits:
Object
  • Object
show all
Defined in:
lib/merge_ruby_client/accounting/types/remote_field_class.rb

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: OMIT, display_name: OMIT, remote_key_name: OMIT, description: OMIT, is_custom: OMIT, is_common_model_field: OMIT, is_required: OMIT, field_type: OMIT, field_format: OMIT, field_choices: OMIT, item_schema: OMIT, additional_properties: nil) ⇒ Merge::Accounting::RemoteFieldClass



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 55

def initialize(id: OMIT, display_name: OMIT, remote_key_name: OMIT, description: OMIT, is_custom: OMIT,
               is_common_model_field: OMIT, is_required: OMIT, field_type: OMIT, field_format: OMIT, field_choices: OMIT, item_schema: OMIT, additional_properties: nil)
  @id = id if id != OMIT
  @display_name = display_name if display_name != OMIT
  @remote_key_name = remote_key_name if remote_key_name != OMIT
  @description = description if description != OMIT
  @is_custom = is_custom if is_custom != OMIT
  @is_common_model_field = is_common_model_field if is_common_model_field != OMIT
  @is_required = is_required if is_required != OMIT
  @field_type = field_type if field_type != OMIT
  @field_format = field_format if field_format != OMIT
  @field_choices = field_choices if field_choices != OMIT
  @item_schema = item_schema if item_schema != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "id": id,
    "display_name": display_name,
    "remote_key_name": remote_key_name,
    "description": description,
    "is_custom": is_custom,
    "is_common_model_field": is_common_model_field,
    "is_required": is_required,
    "field_type": field_type,
    "field_format": field_format,
    "field_choices": field_choices,
    "item_schema": item_schema
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)



35
36
37
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 35

def additional_properties
  @additional_properties
end

#descriptionString (readonly)



19
20
21
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 19

def description
  @description
end

#display_nameString (readonly)



15
16
17
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 15

def display_name
  @display_name
end

#field_choicesArray<String> (readonly)



31
32
33
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 31

def field_choices
  @field_choices
end

#field_formatMerge::Accounting::FieldFormatEnum (readonly)



29
30
31
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 29

def field_format
  @field_format
end

#field_typeMerge::Accounting::FieldTypeEnum (readonly)



27
28
29
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 27

def field_type
  @field_type
end

#idString (readonly)



13
14
15
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 13

def id
  @id
end

#is_common_model_fieldBoolean (readonly)



23
24
25
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 23

def is_common_model_field
  @is_common_model_field
end

#is_customBoolean (readonly)



21
22
23
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 21

def is_custom
  @is_custom
end

#is_requiredBoolean (readonly)



25
26
27
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 25

def is_required
  @is_required
end

#item_schemaMerge::Accounting::ItemSchema (readonly)



33
34
35
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 33

def item_schema
  @item_schema
end

#remote_key_nameString (readonly)



17
18
19
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 17

def remote_key_name
  @remote_key_name
end

Class Method Details

.from_json(json_object:) ⇒ Merge::Accounting::RemoteFieldClass

Deserialize a JSON object to an instance of RemoteFieldClass



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
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 90

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  id = parsed_json["id"]
  display_name = parsed_json["display_name"]
  remote_key_name = parsed_json["remote_key_name"]
  description = parsed_json["description"]
  is_custom = parsed_json["is_custom"]
  is_common_model_field = parsed_json["is_common_model_field"]
  is_required = parsed_json["is_required"]
  field_type = parsed_json["field_type"]
  field_format = parsed_json["field_format"]
  field_choices = parsed_json["field_choices"]
  if parsed_json["item_schema"].nil?
    item_schema = nil
  else
    item_schema = parsed_json["item_schema"].to_json
    item_schema = Merge::Accounting::ItemSchema.from_json(json_object: item_schema)
  end
  new(
    id: id,
    display_name: display_name,
    remote_key_name: remote_key_name,
    description: description,
    is_custom: is_custom,
    is_common_model_field: is_common_model_field,
    is_required: is_required,
    field_type: field_type,
    field_format: field_format,
    field_choices: field_choices,
    item_schema: item_schema,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given

hash and check each fields type against the current object's property
definitions.


138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 138

def self.validate_raw(obj:)
  obj.id&.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  obj.display_name&.is_a?(String) != false || raise("Passed value for field obj.display_name is not the expected type, validation failed.")
  obj.remote_key_name&.is_a?(String) != false || raise("Passed value for field obj.remote_key_name is not the expected type, validation failed.")
  obj.description&.is_a?(String) != false || raise("Passed value for field obj.description is not the expected type, validation failed.")
  obj.is_custom&.is_a?(Boolean) != false || raise("Passed value for field obj.is_custom is not the expected type, validation failed.")
  obj.is_common_model_field&.is_a?(Boolean) != false || raise("Passed value for field obj.is_common_model_field is not the expected type, validation failed.")
  obj.is_required&.is_a?(Boolean) != false || raise("Passed value for field obj.is_required is not the expected type, validation failed.")
  obj.field_type&.is_a?(Merge::Accounting::FieldTypeEnum) != false || raise("Passed value for field obj.field_type is not the expected type, validation failed.")
  obj.field_format&.is_a?(Merge::Accounting::FieldFormatEnum) != false || raise("Passed value for field obj.field_format is not the expected type, validation failed.")
  obj.field_choices&.is_a?(Array) != false || raise("Passed value for field obj.field_choices is not the expected type, validation failed.")
  obj.item_schema.nil? || Merge::Accounting::ItemSchema.validate_raw(obj: obj.item_schema)
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of RemoteFieldClass to a JSON object



128
129
130
# File 'lib/merge_ruby_client/accounting/types/remote_field_class.rb', line 128

def to_json(*_args)
  @_field_set&.to_json
end