Class: Forecasting::Models::ForecastRecord

Inherits:
Base
  • Object
show all
Defined in:
lib/forecasting/models/forecast_record.rb

Instance Attribute Summary

Attributes inherited from Base

#attributes, #forecast_client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

attributed, #initialize, modeled, #to_hash

Constructor Details

This class inherits a constructor from Forecasting::Models::Base

Class Method Details

.get(id, opts = {}) ⇒ Object

Retrieves an instance of the object by ID

Parameters:

  • id (Integer)

    the id of the object to retrieve

  • opts (Hash) (defaults to: {})

    options to pass along to the ‘Forecasting::Client` instance



43
44
45
46
47
48
# File 'lib/forecasting/models/forecast_record.rb', line 43

def self.get(id, opts = {})
  client = opts[:forecast_client] || Forecasting::Client.new(**opts)
  self.new({ 'id' => id }, opts).tap do |record|
    record.attributes = client.get(record.path)
  end
end

Instance Method Details

#createObject



9
10
11
# File 'lib/forecasting/models/forecast_record.rb', line 9

def create
  forecast_client.create(self)
end

#deleteObject



17
18
19
# File 'lib/forecasting/models/forecast_record.rb', line 17

def delete
  forecast_client.delete(self)
end

#fetchForecasting::Models::ForecastRecord

It loads a new record from your Harvest account. #



23
24
25
# File 'lib/forecasting/models/forecast_record.rb', line 23

def fetch
  self.class.new(forecast_client.get(path), forecast_client: forecast_client)
end

#pathObject



34
35
36
# File 'lib/forecasting/models/forecast_record.rb', line 34

def path
  raise Forecasting::MethodNotImplemented
end

#saveObject



5
6
7
# File 'lib/forecasting/models/forecast_record.rb', line 5

def save
  id.nil? ? create : update
end

#typeString

It returns the model type

Returns:

  • (String)


30
31
32
# File 'lib/forecasting/models/forecast_record.rb', line 30

def type
  self.class.name.split("::").last.downcase
end

#updateObject



13
14
15
# File 'lib/forecasting/models/forecast_record.rb', line 13

def update
  forecast_client.update(self)
end