Class: AdvancedBilling::Metafield

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

Overview

Metafield Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #get_additional_properties, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(id: SKIP, name: SKIP, scope: SKIP, data_count: SKIP, input_type: SKIP, enum: SKIP, additional_properties: {}) ⇒ Metafield

Returns a new instance of Metafield.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/advanced_billing/models/metafield.rb', line 74

def initialize(id: SKIP, name: SKIP, scope: SKIP, data_count: SKIP,
               input_type: SKIP, enum: SKIP, additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @id = id unless id == SKIP
  @name = name unless name == SKIP
  @scope = scope unless scope == SKIP
  @data_count = data_count unless data_count == SKIP
  @input_type = input_type unless input_type == SKIP
  @enum = enum unless enum == SKIP
end

Instance Attribute Details

#data_countInteger

The amount of subscriptions this metafield has been applied to in Advanced Billing.

Returns:

  • (Integer)


29
30
31
# File 'lib/advanced_billing/models/metafield.rb', line 29

def data_count
  @data_count
end

#enumObject

Indicates the type of metafield. A text metafield allows any string value. Dropdown and radio metafields have a set of values that can be selected. Defaults to ‘text’.

Returns:

  • (Object)


41
42
43
# File 'lib/advanced_billing/models/metafield.rb', line 41

def enum
  @enum
end

#idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def id
  @id
end

#input_typeMetafieldInput

Indicates the type of metafield. A text metafield allows any string value. Dropdown and radio metafields have a set of values that can be selected. Defaults to ‘text’.

Returns:



35
36
37
# File 'lib/advanced_billing/models/metafield.rb', line 35

def input_type
  @input_type
end

#nameString

TODO: Write general description for this method

Returns:

  • (String)


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

def name
  @name
end

#scopeMetafieldScope

Warning: When updating a metafield’s scope attribute, all scope attributes must be passed. Partially complete scope attributes will override the existing settings.

Returns:



24
25
26
# File 'lib/advanced_billing/models/metafield.rb', line 24

def scope
  @scope
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : SKIP
  name = hash.key?('name') ? hash['name'] : SKIP
  scope = MetafieldScope.from_hash(hash['scope']) if hash['scope']
  data_count = hash.key?('data_count') ? hash['data_count'] : SKIP
  input_type = hash.key?('input_type') ? hash['input_type'] : SKIP
  enum = hash.key?('enum') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:MetafieldEnum), hash['enum']
  ) : SKIP

  # Clean out expected properties from Hash.
  additional_properties = hash.reject { |k, _| names.value?(k) }

  # Create object from extracted values.
  Metafield.new(id: id,
                name: name,
                scope: scope,
                data_count: data_count,
                input_type: input_type,
                enum: enum,
                additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



44
45
46
47
48
49
50
51
52
53
# File 'lib/advanced_billing/models/metafield.rb', line 44

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['name'] = 'name'
  @_hash['scope'] = 'scope'
  @_hash['data_count'] = 'data_count'
  @_hash['input_type'] = 'input_type'
  @_hash['enum'] = 'enum'
  @_hash
end

.nullablesObject

An array for nullable fields



68
69
70
71
72
# File 'lib/advanced_billing/models/metafield.rb', line 68

def self.nullables
  %w[
    enum
  ]
end

.optionalsObject

An array for optional fields



56
57
58
59
60
61
62
63
64
65
# File 'lib/advanced_billing/models/metafield.rb', line 56

def self.optionals
  %w[
    id
    name
    scope
    data_count
    input_type
    enum
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Metafield | Hash)

    value against the validation is performed.



118
119
120
121
122
123
124
# File 'lib/advanced_billing/models/metafield.rb', line 118

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



135
136
137
138
139
140
# File 'lib/advanced_billing/models/metafield.rb', line 135

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id.inspect}, name: #{@name.inspect}, scope: #{@scope.inspect},"\
  " data_count: #{@data_count.inspect}, input_type: #{@input_type.inspect}, enum:"\
  " #{@enum.inspect}, additional_properties: #{get_additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



127
128
129
130
131
132
# File 'lib/advanced_billing/models/metafield.rb', line 127

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id}, name: #{@name}, scope: #{@scope}, data_count: #{@data_count},"\
  " input_type: #{@input_type}, enum: #{@enum}, additional_properties:"\
  " #{get_additional_properties}>"
end