Class: Company::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/company/resource.rb

Overview

What every record shares: the node the platform answered it as. Built by the gem that read it, never by a caller.

Direct Known Subclasses

Business, Customer, Job, Lead, Line, Location, Quote, Technician, Visit, Window

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node: {}) ⇒ Resource

Returns a new instance of Resource.

Parameters:

  • node (Hash) (defaults to: {}) —

    record as the platform answered it, under either kind of key.



17
18
19
# File 'lib/company/resource.rb', line 17

def initialize(node: {})
  @node = node.with_indifferent_access
end

Class Method Details

.keys ⇒ Hash

The node keys the platform spells otherwise than the vocabulary, by the reader they answer: { phone: :phone_number } reads Business#phone off phone_number. A gem declares its own; a reader left out reads the key of its own name.

Returns:

  • (Hash) —

    reader-to-key exceptions, empty where every name is its key.



9
# File 'lib/company/resource.rb', line 9

def self.keys = {}

.node_keys ⇒ Array<Symbol>

The keys a platform is expected to answer a node with: each attribute the kind reads, through keys, so a gem asks its platform for exactly these and writes none by hand.

Returns:

  • (Array<Symbol>) —

    node keys, in the order the attributes are read.



14
# File 'lib/company/resource.rb', line 14

def self.node_keys = attributes.map { |name| keys.fetch name, name }

Instance Method Details

#id ⇒ String

Returns ID the platform files the record under.

Returns:

  • (String) —

    ID the platform files the record under.



22
# File 'lib/company/resource.rb', line 22

def id = attribute :id