module Google::Apis::Core::JsonRepresentationSupport::JsonSupport

@private

Public Instance Methods

collection(name, options = {}) click to toggle source

Define a collection property

@param [String] name

Property name

@param [Hash] options

Calls superclass method
# File lib/google/apis/core/json_representation.rb, line 100
def collection(name, options = {})
  set_default_options(name, options)
  super(name, options)
end
getter_fn(name) click to toggle source

Returns a customized getter function for Representable. Allows indifferent hash/attribute access.

@param [String] name Property name @return [Proc]

# File lib/google/apis/core/json_representation.rb, line 38
def getter_fn(name)
  ivar_name = "@#{name}".to_sym
  lambda do |_|
    if respond_to?(:fetch)
      fetch(name, instance_variable_get(ivar_name))
    else
      instance_variable_get(ivar_name)
    end
  end
end
hash(name = nil, options = nil) click to toggle source

Define a hash property

@param [String] name

Property name

@param [Hash] options

Calls superclass method
# File lib/google/apis/core/json_representation.rb, line 110
def hash(name = nil, options = nil)
  return super() unless name # Allow Object.hash
  set_default_options(name, options)
  super(name, options)
end
if_fn(name) click to toggle source

Returns a customized function for Representable that checks whether or not an attribute should be serialized. Allows proper patch semantics by distinguishing between nil & unset values

@param [String] name Property name @return [Proc]

# File lib/google/apis/core/json_representation.rb, line 55
def if_fn(name)
  ivar_name = "@#{name}".to_sym
  lambda do |opts|
    if opts[:skip_undefined]
      if respond_to?(:key?)
        self.key?(name) || instance_variable_defined?(ivar_name)
      else
        instance_variable_defined?(ivar_name)
      end
    else
      true
    end
  end
end
property(name, options = {}) click to toggle source

Define a single value property

@param [String] name

Property name

@param [Hash] options

Calls superclass method
# File lib/google/apis/core/json_representation.rb, line 90
def property(name, options = {})
  set_default_options(name, options)
  super(name, options)
end
set_default_options(name, options) click to toggle source
# File lib/google/apis/core/json_representation.rb, line 70
def set_default_options(name, options)
  if options[:base64]
    options[:render_filter] = ->(value, _doc, *_args) { value.nil? ? nil : Base64.urlsafe_encode64(value) }
    options[:parse_filter] = ->(fragment, _doc, *_args) { Base64.urlsafe_decode64(fragment) }
  end
  if options[:type] == DateTime
    options[:render_filter] = ->(value, _doc, *_args) { value.nil? ? nil : value.is_a?(DateTime) ? value.rfc3339(3) : value.to_s }
    options[:parse_filter] = ->(fragment, _doc, *_args) { DateTime.parse(fragment) }
  end

  options[:render_nil] = true
  options[:getter] = getter_fn(name)
  options[:if] = if_fn(name)
end