Class: FinchAPI::BaseModel Abstract

Inherits:
Object
  • Object
show all
Extended by:
Converter
Defined in:
lib/finch-api/base_model.rb

Overview

This class is abstract.

Examples:

# `operation_support_matrix` is a `FinchAPI::Models::OperationSupportMatrix`
operation_support_matrix => {
  create: create,
  delete: delete,
  read: read
}

Direct Known Subclasses

Models::AccessTokenCreateParams, Models::AccountDisconnectParams, Models::AccountIntrospectParams, Models::AccountUpdateEvent::Data, Models::AccountUpdateEvent::Data::AuthenticationMethod, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Company, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Company::Accounts, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Company::Departments, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Company::Departments::Parent, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Company::Entity, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Company::Locations, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Directory, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Directory::Individuals, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Directory::Individuals::Manager, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Directory::Paging, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Employment, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Employment::Department, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Employment::Employment, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Employment::Income, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Employment::Location, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Employment::Manager, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Individual, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Individual::Emails, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Individual::PhoneNumbers, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Individual::Residence, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::PayGroup, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::PayStatement, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::PayStatement::Paging, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::PayStatement::PayStatements, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::PayStatement::PayStatements::Earnings, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::PayStatement::PayStatements::EmployeeDeductions, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::PayStatement::PayStatements::EmployerContributions, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::PayStatement::PayStatements::Taxes, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Payment, Models::AccountUpdateEvent::Data::AuthenticationMethod::SupportedFields::Payment::PayPeriod, Models::BaseWebhookEvent, Models::Connect::SessionNewParams, Models::Connect::SessionNewParams::Integration, Models::Connect::SessionNewResponse, Models::Connect::SessionReauthenticateParams, Models::Connect::SessionReauthenticateResponse, Models::CreateAccessTokenResponse, Models::DirectoryEvent::Data, Models::DisconnectResponse, Models::EmploymentEvent::Data, Models::HRIS::BenefitContribution, Models::HRIS::BenefitCreateParams, Models::HRIS::BenefitFeaturesAndOperations, Models::HRIS::BenefitFeaturesAndOperations::SupportedFeatures, Models::HRIS::BenefitListParams, Models::HRIS::BenefitListSupportedBenefitsParams, Models::HRIS::BenefitRetrieveParams, Models::HRIS::BenefitUpdateParams, Models::HRIS::Benefits::EnrolledIndividual, Models::HRIS::Benefits::EnrolledIndividual::Body, Models::HRIS::Benefits::IndividualBenefit, Models::HRIS::Benefits::IndividualBenefit::Body, Models::HRIS::Benefits::IndividualEnrollManyParams, Models::HRIS::Benefits::IndividualEnrollManyParams::Individual, Models::HRIS::Benefits::IndividualEnrollManyParams::Individual::Configuration, Models::HRIS::Benefits::IndividualEnrollManyParams::Individual::Configuration::CompanyContribution, Models::HRIS::Benefits::IndividualEnrollManyParams::Individual::Configuration::EmployeeDeduction, Models::HRIS::Benefits::IndividualEnrolledIDsParams, Models::HRIS::Benefits::IndividualEnrolledIDsResponse, Models::HRIS::Benefits::IndividualRetrieveManyBenefitsParams, Models::HRIS::Benefits::IndividualUnenrollManyParams, Models::HRIS::Benefits::UnenrolledIndividual, Models::HRIS::Benefits::UnenrolledIndividual::Body, Models::HRIS::BenefitsSupport, Models::HRIS::CompanyBenefit, Models::HRIS::CompanyRetrieveParams, Models::HRIS::CreateCompanyBenefitsResponse, Models::HRIS::DirectoryListIndividualsParams, Models::HRIS::DirectoryListParams, Models::HRIS::DocumentListParams, Models::HRIS::DocumentListResponse, Models::HRIS::DocumentResponse, Models::HRIS::DocumentRetreiveParams, Models::HRIS::EmploymentData, Models::HRIS::EmploymentData::CustomField, Models::HRIS::EmploymentData::Department, Models::HRIS::EmploymentData::Employment, Models::HRIS::EmploymentData::Manager, Models::HRIS::EmploymentDataResponse, Models::HRIS::EmploymentRetrieveManyParams, Models::HRIS::EmploymentRetrieveManyParams::Request, Models::HRIS::HRISCompany, Models::HRIS::HRISCompany::Account, Models::HRIS::HRISCompany::Department, Models::HRIS::HRISCompany::Department::Parent, Models::HRIS::HRISCompany::Entity, Models::HRIS::Individual, Models::HRIS::Individual::Email, Models::HRIS::Individual::PhoneNumber, Models::HRIS::IndividualInDirectory, Models::HRIS::IndividualInDirectory::Department, Models::HRIS::IndividualInDirectory::Manager, Models::HRIS::IndividualResponse, Models::HRIS::IndividualRetrieveManyParams, Models::HRIS::IndividualRetrieveManyParams::Options, Models::HRIS::IndividualRetrieveManyParams::Request, Models::HRIS::PayStatement, Models::HRIS::PayStatement::Earning, Models::HRIS::PayStatement::Earning::Attributes, Models::HRIS::PayStatement::Earning::Attributes::Metadata, Models::HRIS::PayStatement::EmployeeDeduction, Models::HRIS::PayStatement::EmployeeDeduction::Attributes, Models::HRIS::PayStatement::EmployeeDeduction::Attributes::Metadata, Models::HRIS::PayStatement::EmployerContribution, Models::HRIS::PayStatement::EmployerContribution::Attributes, Models::HRIS::PayStatement::EmployerContribution::Attributes::Metadata, Models::HRIS::PayStatement::Tax, Models::HRIS::PayStatement::Tax::Attributes, Models::HRIS::PayStatement::Tax::Attributes::Metadata, Models::HRIS::PayStatementResponse, Models::HRIS::PayStatementResponseBody, Models::HRIS::PayStatementRetrieveManyParams, Models::HRIS::PayStatementRetrieveManyParams::Request, Models::HRIS::Payment, Models::HRIS::Payment::PayPeriod, Models::HRIS::PaymentListParams, Models::HRIS::SupportPerBenefitType, Models::HRIS::SupportedBenefit, Models::HRIS::UpdateCompanyBenefitResponse, Models::HRIS::W42005, Models::HRIS::W42005::Data, Models::HRIS::W42020, Models::HRIS::W42020::Data, Models::Income, Models::IndividualEvent::Data, Models::Introspection, Models::Introspection::AuthenticationMethod, Models::Introspection::AuthenticationMethod::ConnectionStatus, Models::Introspection::ConnectionStatus, Models::JobCompletionEvent::Data, Models::Jobs::AutomatedAsyncJob, Models::Jobs::AutomatedAsyncJob::Params, Models::Jobs::AutomatedCreateParams, Models::Jobs::AutomatedCreateParams::Params, Models::Jobs::AutomatedCreateResponse, Models::Jobs::AutomatedListParams, Models::Jobs::AutomatedListResponse, Models::Jobs::AutomatedListResponse::Meta, Models::Jobs::AutomatedListResponse::Meta::Quotas, Models::Jobs::AutomatedListResponse::Meta::Quotas::DataSyncAll, Models::Jobs::AutomatedRetrieveParams, Models::Jobs::ManualAsyncJob, Models::Jobs::ManualRetrieveParams, Models::Location, Models::Money, Models::OperationSupportMatrix, Models::Paging, Models::PayStatementEvent::Data, Models::PaymentEvent::Data, Models::Payroll::PayGroupListParams, Models::Payroll::PayGroupListResponse, Models::Payroll::PayGroupRetrieveParams, Models::Payroll::PayGroupRetrieveResponse, Models::Provider, Models::Provider::AuthenticationMethod, Models::Provider::AuthenticationMethod::SupportedFields, Models::Provider::AuthenticationMethod::SupportedFields::Company, Models::Provider::AuthenticationMethod::SupportedFields::Company::Accounts, Models::Provider::AuthenticationMethod::SupportedFields::Company::Departments, Models::Provider::AuthenticationMethod::SupportedFields::Company::Departments::Parent, Models::Provider::AuthenticationMethod::SupportedFields::Company::Entity, Models::Provider::AuthenticationMethod::SupportedFields::Company::Locations, Models::Provider::AuthenticationMethod::SupportedFields::Directory, Models::Provider::AuthenticationMethod::SupportedFields::Directory::Individuals, Models::Provider::AuthenticationMethod::SupportedFields::Directory::Individuals::Manager, Models::Provider::AuthenticationMethod::SupportedFields::Directory::Paging, Models::Provider::AuthenticationMethod::SupportedFields::Employment, Models::Provider::AuthenticationMethod::SupportedFields::Employment::Department, Models::Provider::AuthenticationMethod::SupportedFields::Employment::Employment, Models::Provider::AuthenticationMethod::SupportedFields::Employment::Income, Models::Provider::AuthenticationMethod::SupportedFields::Employment::Location, Models::Provider::AuthenticationMethod::SupportedFields::Employment::Manager, Models::Provider::AuthenticationMethod::SupportedFields::Individual, Models::Provider::AuthenticationMethod::SupportedFields::Individual::Emails, Models::Provider::AuthenticationMethod::SupportedFields::Individual::PhoneNumbers, Models::Provider::AuthenticationMethod::SupportedFields::Individual::Residence, Models::Provider::AuthenticationMethod::SupportedFields::PayGroup, Models::Provider::AuthenticationMethod::SupportedFields::PayStatement, Models::Provider::AuthenticationMethod::SupportedFields::PayStatement::Paging, Models::Provider::AuthenticationMethod::SupportedFields::PayStatement::PayStatements, Models::Provider::AuthenticationMethod::SupportedFields::PayStatement::PayStatements::Earnings, Models::Provider::AuthenticationMethod::SupportedFields::PayStatement::PayStatements::EmployeeDeductions, Models::Provider::AuthenticationMethod::SupportedFields::PayStatement::PayStatements::EmployerContributions, Models::Provider::AuthenticationMethod::SupportedFields::PayStatement::PayStatements::Taxes, Models::Provider::AuthenticationMethod::SupportedFields::Payment, Models::Provider::AuthenticationMethod::SupportedFields::Payment::PayPeriod, Models::ProviderListParams, Models::RequestForwardingForwardParams, Models::RequestForwardingForwardResponse, Models::RequestForwardingForwardResponse::Request, Models::Sandbox::CompanyUpdateParams, Models::Sandbox::CompanyUpdateParams::Account, Models::Sandbox::CompanyUpdateParams::Department, Models::Sandbox::CompanyUpdateParams::Department::Parent, Models::Sandbox::CompanyUpdateParams::Entity, Models::Sandbox::CompanyUpdateResponse, Models::Sandbox::CompanyUpdateResponse::Account, Models::Sandbox::CompanyUpdateResponse::Department, Models::Sandbox::CompanyUpdateResponse::Department::Parent, Models::Sandbox::CompanyUpdateResponse::Entity, Models::Sandbox::ConnectionCreateParams, Models::Sandbox::ConnectionCreateResponse, Models::Sandbox::Connections::AccountCreateParams, Models::Sandbox::Connections::AccountCreateResponse, Models::Sandbox::Connections::AccountUpdateParams, Models::Sandbox::Connections::AccountUpdateResponse, Models::Sandbox::DirectoryCreateParams, Models::Sandbox::DirectoryCreateParams::Body, Models::Sandbox::DirectoryCreateParams::Body::CustomField, Models::Sandbox::DirectoryCreateParams::Body::Department, Models::Sandbox::DirectoryCreateParams::Body::Email, Models::Sandbox::DirectoryCreateParams::Body::Employment, Models::Sandbox::DirectoryCreateParams::Body::Manager, Models::Sandbox::DirectoryCreateParams::Body::PhoneNumber, Models::Sandbox::EmploymentUpdateParams, Models::Sandbox::EmploymentUpdateParams::CustomField, Models::Sandbox::EmploymentUpdateParams::Department, Models::Sandbox::EmploymentUpdateParams::Employment, Models::Sandbox::EmploymentUpdateParams::Manager, Models::Sandbox::EmploymentUpdateResponse, Models::Sandbox::EmploymentUpdateResponse::CustomField, Models::Sandbox::EmploymentUpdateResponse::Department, Models::Sandbox::EmploymentUpdateResponse::Employment, Models::Sandbox::EmploymentUpdateResponse::Manager, Models::Sandbox::IndividualUpdateParams, Models::Sandbox::IndividualUpdateParams::Email, Models::Sandbox::IndividualUpdateParams::PhoneNumber, Models::Sandbox::IndividualUpdateResponse, Models::Sandbox::IndividualUpdateResponse::Email, Models::Sandbox::IndividualUpdateResponse::PhoneNumber, Models::Sandbox::JobCreateParams, Models::Sandbox::JobCreateResponse, Models::Sandbox::Jobs::ConfigurationRetrieveParams, Models::Sandbox::Jobs::SandboxJobConfiguration, Models::Sandbox::PaymentCreateParams, Models::Sandbox::PaymentCreateParams::PayStatement, Models::Sandbox::PaymentCreateParams::PayStatement::Earning, Models::Sandbox::PaymentCreateParams::PayStatement::Earning::Attributes, Models::Sandbox::PaymentCreateParams::PayStatement::Earning::Attributes::Metadata, Models::Sandbox::PaymentCreateParams::PayStatement::EmployeeDeduction, Models::Sandbox::PaymentCreateParams::PayStatement::EmployeeDeduction::Attributes, Models::Sandbox::PaymentCreateParams::PayStatement::EmployeeDeduction::Attributes::Metadata, Models::Sandbox::PaymentCreateParams::PayStatement::EmployerContribution, Models::Sandbox::PaymentCreateParams::PayStatement::EmployerContribution::Attributes, Models::Sandbox::PaymentCreateParams::PayStatement::EmployerContribution::Attributes::Metadata, Models::Sandbox::PaymentCreateParams::PayStatement::Tax, Models::Sandbox::PaymentCreateParams::PayStatement::Tax::Attributes, Models::Sandbox::PaymentCreateParams::PayStatement::Tax::Attributes::Metadata, Models::Sandbox::PaymentCreateResponse, RequestOptions

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Converter

coerce, dump, try_strict_coerce, type_info

Constructor Details

#initialize(data = {}) ⇒ BaseModel

Create a new instance of a model.

Parameters:



1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
# File 'lib/finch-api/base_model.rb', line 1193

def initialize(data = {})
  case FinchAPI::Util.coerce_hash(data)
  in Hash => coerced
    @data = coerced.to_h do |key, value|
      name = key.to_sym
      mapped = self.class.reverse_map.fetch(name, name)
      type = self.class.fields[mapped]&.fetch(:type)
      stored =
        case [type, value]
        in [Module, Hash] if type <= FinchAPI::BaseModel
          type.new(value)
        in [FinchAPI::ArrayOf, Array] | [FinchAPI::HashOf, Hash]
          type.coerce(value)
        else
          value
        end
      [name, stored]
    end
  else
    raise ArgumentError.new("Expected a #{Hash} or #{FinchAPI::BaseModel}, got #{data.inspect}")
  end
end

Class Method Details

.coerce(value) ⇒ FinchAPI::BaseModel, Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Returns:



1047
1048
1049
1050
1051
1052
1053
1054
# File 'lib/finch-api/base_model.rb', line 1047

def coerce(value)
  case FinchAPI::Util.coerce_hash(value)
  in Hash => coerced
    new(coerced)
  else
    value
  end
end

.defaultsHash{Symbol=>Proc}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash{Symbol=>Proc})


908
# File 'lib/finch-api/base_model.rb', line 908

def defaults = (@defaults ||= {})

.dump(value) ⇒ Hash{Object=>Object}, Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Returns:

  • (Hash{Object=>Object}, Object)


1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
# File 'lib/finch-api/base_model.rb', line 1061

def dump(value)
  unless (coerced = FinchAPI::Util.coerce_hash(value)).is_a?(Hash)
    return value
  end

  values = coerced.filter_map do |key, val|
    name = key.to_sym
    case (field = known_fields[name])
    in nil
      [name, val]
    else
      mode, type_fn, api_name = field.fetch_values(:mode, :type_fn, :key)
      case mode
      in :coerce
        next
      else
        target = type_fn.call
        [api_name, FinchAPI::Converter.dump(target, val)]
      end
    end
  end.to_h

  defaults.each do |key, val|
    next if values.key?(key)

    values[key] = val
  end

  values
end

.fieldsHash{Symbol=>Hash{Symbol=>Object}}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash{Symbol=>Hash{Symbol=>Object}})


899
900
901
902
903
# File 'lib/finch-api/base_model.rb', line 899

def fields
  known_fields.transform_values do |field|
    {**field.except(:type_fn), type: field.fetch(:type_fn).call}
  end
end

.known_fieldsHash{Symbol=>Hash{Symbol=>Object}}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Assumes superclass fields are totally defined before fields are accessed /

defined on subclasses.

Returns:

  • (Hash{Symbol=>Hash{Symbol=>Object}})


885
886
887
# File 'lib/finch-api/base_model.rb', line 885

def known_fields
  @known_fields ||= (self < FinchAPI::BaseModel ? superclass.known_fields.dup : {})
end

.optional(name_sym, type_info, spec = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • name_sym (Symbol)
  • type_info (Hash{Symbol=>Object}, Proc, FinchAPI::Converter, Class)
  • spec (Hash{Symbol=>Object}) (defaults to: {})

    .

    @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const

    @option spec [Proc] :enum

    @option spec [Proc] :union

    @option spec [Boolean] :“nil?”



999
1000
1001
# File 'lib/finch-api/base_model.rb', line 999

def optional(name_sym, type_info, spec = {})
  add_field(name_sym, required: false, type_info: type_info, spec: spec)
end

.required(name_sym, type_info, spec = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • name_sym (Symbol)
  • type_info (Hash{Symbol=>Object}, Proc, FinchAPI::Converter, Class)
  • spec (Hash{Symbol=>Object}) (defaults to: {})

    .

    @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const

    @option spec [Proc] :enum

    @option spec [Proc] :union

    @option spec [Boolean] :“nil?”



980
981
982
# File 'lib/finch-api/base_model.rb', line 980

def required(name_sym, type_info, spec = {})
  add_field(name_sym, required: true, type_info: type_info, spec: spec)
end

.reverse_mapHash{Symbol=>Symbol}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash{Symbol=>Symbol})


892
893
894
# File 'lib/finch-api/base_model.rb', line 892

def reverse_map
  @reverse_map ||= (self < FinchAPI::BaseModel ? superclass.reverse_map.dup : {})
end

.try_strict_coerce(value) ⇒ Array(true, Object, nil), Array(false, Boolean, Integer)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • value (Object)

Returns:

  • (Array(true, Object, nil), Array(false, Boolean, Integer))


1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
# File 'lib/finch-api/base_model.rb', line 1097

def try_strict_coerce(value)
  case value
  in Hash | FinchAPI::BaseModel
    value = value.to_h
  else
    return [false, false, 0]
  end

  keys = value.keys.to_set
  great_success = true
  tally = 0
  acc = {}

  known_fields.each_value do |field|
    mode, required, type_fn, api_name = field.fetch_values(:mode, :required, :type_fn, :key)
    keys.delete(api_name)

    case [required && mode != :dump, value.key?(api_name)]
    in [_, true]
      target = type_fn.call
      item = value.fetch(api_name)
      case FinchAPI::Converter.try_strict_coerce(target, item)
      in [true, coerced, score]
        tally += score
        acc[api_name] = coerced
      in [false, true, score]
        great_success = false
        tally += score
        acc[api_name] = item
      in [false, false, _]
        great_success &&= item.nil?
      end
    in [true, false]
      great_success = false
    in [false, false]
      nil
    end
  end

  keys.each do |key|
    acc[key] = value.fetch(key)
  end

  great_success ? [true, new(acc), tally] : [false, true, tally]
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (Object)

Returns:

  • (Boolean)


1032
1033
1034
1035
1036
1037
1038
1039
# File 'lib/finch-api/base_model.rb', line 1032

def ==(other)
  case other
  in FinchAPI::BaseModel
    self.class.fields == other.class.fields && @data == other.to_h
  else
    false
  end
end

#[](key) ⇒ Object?

Returns the raw value associated with the given key, if found. Otherwise, nil is

returned.

It is valid to lookup keys that are not in the API spec, for example to access
undocumented features. This method does not parse response data into
higher-level types. Lookup by anything other than a Symbol is an ArgumentError.

Parameters:

  • key (Symbol)

Returns:

  • (Object, nil)


1154
1155
1156
1157
1158
1159
1160
# File 'lib/finch-api/base_model.rb', line 1154

def [](key)
  unless key.instance_of?(Symbol)
    raise ArgumentError.new("Expected symbol key for lookup, got #{key.inspect}")
  end

  @data[key]
end

#deconstruct_keys(keys) ⇒ Hash{Symbol=>Object}

Parameters:

  • keys (Array<Symbol>, nil)

Returns:

  • (Hash{Symbol=>Object})


1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
# File 'lib/finch-api/base_model.rb', line 1179

def deconstruct_keys(keys)
  (keys || self.class.known_fields.keys).filter_map do |k|
    unless self.class.known_fields.key?(k)
      next
    end

    [k, method(k).call]
  end
  .to_h
end

#inspectString

Returns:

  • (String)


1220
1221
1222
1223
1224
# File 'lib/finch-api/base_model.rb', line 1220

def inspect
  "#<#{self.class.name}:0x#{object_id.to_s(16)} #{deconstruct_keys(nil).map do |k, v|
    "#{k}=#{v.inspect}"
  end.join(' ')}>"
end

#to_hHash{Symbol=>Object} Also known as: to_hash

Returns a Hash of the data underlying this object. O(1)

Keys are Symbols and values are the raw values from the response. The return
value indicates which values were ever set on the object. i.e. there will be a
key in this hash if they ever were, even if the set value was nil.

This method is not recursive. The returned value is shared by the object, so it
should not be mutated.

Returns:

  • (Hash{Symbol=>Object})


1172
# File 'lib/finch-api/base_model.rb', line 1172

def to_h = @data

#to_sString

Returns:

  • (String)


1217
# File 'lib/finch-api/base_model.rb', line 1217

def to_s = @data.to_s