Class: Forecasting::Models::ForecastRecord
- Defined in:
- lib/forecasting/models/forecast_record.rb
Direct Known Subclasses
Assignment, Client, Milestone, Person, Placeholder, Project, RepeatedAssignmentSet, Role
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.get(id, opts = {}) ⇒ Object
Retrieves an instance of the object by ID.
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
-
#fetch ⇒ Forecasting::Models::ForecastRecord
It loads a new record from your Harvest account.
- #path ⇒ Object
- #save ⇒ Object
-
#type ⇒ String
It returns the model type.
- #update ⇒ Object
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
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
#create ⇒ Object
9 10 11 |
# File 'lib/forecasting/models/forecast_record.rb', line 9 def create forecast_client.create(self) end |
#delete ⇒ Object
17 18 19 |
# File 'lib/forecasting/models/forecast_record.rb', line 17 def delete forecast_client.delete(self) end |
#fetch ⇒ Forecasting::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 |
#path ⇒ Object
34 35 36 |
# File 'lib/forecasting/models/forecast_record.rb', line 34 def path raise Forecasting::MethodNotImplemented end |
#save ⇒ Object
5 6 7 |
# File 'lib/forecasting/models/forecast_record.rb', line 5 def save id.nil? ? create : update end |
#type ⇒ String
It returns the model type
30 31 32 |
# File 'lib/forecasting/models/forecast_record.rb', line 30 def type self.class.name.split("::").last.downcase end |
#update ⇒ Object
13 14 15 |
# File 'lib/forecasting/models/forecast_record.rb', line 13 def update forecast_client.update(self) end |