Class: AdvancedBilling::CustomFieldValueChange

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/advanced_billing/models/custom_field_value_change.rb

Overview

CustomFieldValueChange Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(event_type:, metafield_name:, metafield_id:, old_value:, new_value:, resource_type:, resource_id:, additional_properties: {}) ⇒ CustomFieldValueChange

Returns a new instance of CustomFieldValueChange.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/advanced_billing/models/custom_field_value_change.rb', line 66

def initialize(event_type:, metafield_name:, metafield_id:, old_value:,
               new_value:, resource_type:, resource_id:,
               additional_properties: {})
  @event_type = event_type
  @metafield_name = metafield_name
  @metafield_id = metafield_id
  @old_value = old_value
  @new_value = new_value
  @resource_type = resource_type
  @resource_id = resource_id

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#event_typeString

TODO: Write general description for this method

Returns:

  • (String)


14
15
16
# File 'lib/advanced_billing/models/custom_field_value_change.rb', line 14

def event_type
  @event_type
end

#metafield_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


22
23
24
# File 'lib/advanced_billing/models/custom_field_value_change.rb', line 22

def metafield_id
  @metafield_id
end

#metafield_nameString

TODO: Write general description for this method

Returns:

  • (String)


18
19
20
# File 'lib/advanced_billing/models/custom_field_value_change.rb', line 18

def metafield_name
  @metafield_name
end

#new_valueString

TODO: Write general description for this method

Returns:

  • (String)


30
31
32
# File 'lib/advanced_billing/models/custom_field_value_change.rb', line 30

def new_value
  @new_value
end

#old_valueString

TODO: Write general description for this method

Returns:

  • (String)


26
27
28
# File 'lib/advanced_billing/models/custom_field_value_change.rb', line 26

def old_value
  @old_value
end

#resource_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


38
39
40
# File 'lib/advanced_billing/models/custom_field_value_change.rb', line 38

def resource_id
  @resource_id
end

#resource_typeString

TODO: Write general description for this method

Returns:

  • (String)


34
35
36
# File 'lib/advanced_billing/models/custom_field_value_change.rb', line 34

def resource_type
  @resource_type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



84
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
# File 'lib/advanced_billing/models/custom_field_value_change.rb', line 84

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  event_type = hash.key?('event_type') ? hash['event_type'] : nil
  metafield_name =
    hash.key?('metafield_name') ? hash['metafield_name'] : nil
  metafield_id = hash.key?('metafield_id') ? hash['metafield_id'] : nil
  old_value = hash.key?('old_value') ? hash['old_value'] : nil
  new_value = hash.key?('new_value') ? hash['new_value'] : nil
  resource_type = hash.key?('resource_type') ? hash['resource_type'] : nil
  resource_id = hash.key?('resource_id') ? hash['resource_id'] : nil

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.
  CustomFieldValueChange.new(event_type: event_type,
                             metafield_name: metafield_name,
                             metafield_id: metafield_id,
                             old_value: old_value,
                             new_value: new_value,
                             resource_type: resource_type,
                             resource_id: resource_id,
                             additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/advanced_billing/models/custom_field_value_change.rb', line 41

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['event_type'] = 'event_type'
  @_hash['metafield_name'] = 'metafield_name'
  @_hash['metafield_id'] = 'metafield_id'
  @_hash['old_value'] = 'old_value'
  @_hash['new_value'] = 'new_value'
  @_hash['resource_type'] = 'resource_type'
  @_hash['resource_id'] = 'resource_id'
  @_hash
end

.nullablesObject

An array for nullable fields



59
60
61
62
63
64
# File 'lib/advanced_billing/models/custom_field_value_change.rb', line 59

def self.nullables
  %w[
    old_value
    new_value
  ]
end

.optionalsObject

An array for optional fields



54
55
56
# File 'lib/advanced_billing/models/custom_field_value_change.rb', line 54

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/advanced_billing/models/custom_field_value_change.rb', line 113

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.event_type,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.metafield_name,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.metafield_id,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.old_value,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.new_value,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.resource_type,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.resource_id,
                              ->(val) { val.instance_of? Integer })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['event_type'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['metafield_name'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['metafield_id'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['old_value'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['new_value'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['resource_type'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['resource_id'],
                            ->(val) { val.instance_of? Integer })
  )
end