Class: Merge::Filestorage::IndividualCommonModelScopeDeserializer

Inherits:
Object
  • Object
show all
Defined in:
lib/merge_ruby_client/filestorage/types/individual_common_model_scope_deserializer.rb

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_name:, model_permissions: OMIT, field_permissions: OMIT, additional_properties: nil) ⇒ Merge::Filestorage::IndividualCommonModelScopeDeserializer

Parameters:



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/merge_ruby_client/filestorage/types/individual_common_model_scope_deserializer.rb', line 29

def initialize(model_name:, model_permissions: OMIT, field_permissions: OMIT, additional_properties: nil)
  @model_name = model_name
  @model_permissions = model_permissions if model_permissions != OMIT
  @field_permissions = field_permissions if field_permissions != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "model_name": model_name,
    "model_permissions": model_permissions,
    "field_permissions": field_permissions
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



17
18
19
# File 'lib/merge_ruby_client/filestorage/types/individual_common_model_scope_deserializer.rb', line 17

def additional_properties
  @additional_properties
end

#field_permissionsMerge::Filestorage::FieldPermissionDeserializer (readonly)



15
16
17
# File 'lib/merge_ruby_client/filestorage/types/individual_common_model_scope_deserializer.rb', line 15

def field_permissions
  @field_permissions
end

#model_nameString (readonly)

Returns:

  • (String)


11
12
13
# File 'lib/merge_ruby_client/filestorage/types/individual_common_model_scope_deserializer.rb', line 11

def model_name
  @model_name
end

#model_permissionsHash{String => Merge::Filestorage::ModelPermissionDeserializer} (readonly)



13
14
15
# File 'lib/merge_ruby_client/filestorage/types/individual_common_model_scope_deserializer.rb', line 13

def model_permissions
  @model_permissions
end

Class Method Details

.from_json(json_object:) ⇒ Merge::Filestorage::IndividualCommonModelScopeDeserializer

Deserialize a JSON object to an instance of

IndividualCommonModelScopeDeserializer

Parameters:

  • json_object (String)

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/merge_ruby_client/filestorage/types/individual_common_model_scope_deserializer.rb', line 48

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  model_name = parsed_json["model_name"]
  model_permissions = parsed_json["model_permissions"]&.transform_values do |value|
    value = value.to_json
    Merge::Filestorage::ModelPermissionDeserializer.from_json(json_object: value)
  end
  if parsed_json["field_permissions"].nil?
    field_permissions = nil
  else
    field_permissions = parsed_json["field_permissions"].to_json
    field_permissions = Merge::Filestorage::FieldPermissionDeserializer.from_json(json_object: field_permissions)
  end
  new(
    model_name: model_name,
    model_permissions: model_permissions,
    field_permissions: field_permissions,
    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.

Parameters:

  • obj (Object)

Returns:

  • (Void)


83
84
85
86
87
# File 'lib/merge_ruby_client/filestorage/types/individual_common_model_scope_deserializer.rb', line 83

def self.validate_raw(obj:)
  obj.model_name.is_a?(String) != false || raise("Passed value for field obj.model_name is not the expected type, validation failed.")
  obj.model_permissions&.is_a?(Hash) != false || raise("Passed value for field obj.model_permissions is not the expected type, validation failed.")
  obj.field_permissions.nil? || Merge::Filestorage::FieldPermissionDeserializer.validate_raw(obj: obj.field_permissions)
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of IndividualCommonModelScopeDeserializer to a JSON object

Returns:

  • (String)


73
74
75
# File 'lib/merge_ruby_client/filestorage/types/individual_common_model_scope_deserializer.rb', line 73

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