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 collapse
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::Base
It loads a new record from your Harvest account.
-
#initialize(attrs, opts = {}) ⇒ ForecastRecord
constructor
A new instance of ForecastRecord.
- #save ⇒ Object
-
#type ⇒ String
It returns the model type.
- #update ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(attrs, opts = {}) ⇒ ForecastRecord
Returns a new instance of ForecastRecord.
7 8 9 10 |
# File 'lib/forecasting/models/forecast_record.rb', line 7 def initialize(attrs, opts = {}) @forecast_client = opts[:forecast_client] || Forecasting::Client.new(**opts) super(attrs) end |
Instance Attribute Details
#forecast_client ⇒ Forecasting::Model::Client (readonly)
5 6 7 |
# File 'lib/forecasting/models/forecast_record.rb', line 5 def forecast_client @forecast_client end |
Class Method Details
.get(id, opts = {}) ⇒ Object
Retrieves an instance of the object by ID
47 48 49 50 |
# File 'lib/forecasting/models/forecast_record.rb', line 47 def self.get(id, opts = {}) client = opts[:forecast_client] || Forecasting::Client.new(**opts) self.new({ 'id' => id }, opts).fetch end |
Instance Method Details
#create ⇒ Object
16 17 18 |
# File 'lib/forecasting/models/forecast_record.rb', line 16 def create forecast_client.create(self) end |
#delete ⇒ Object
24 25 26 |
# File 'lib/forecasting/models/forecast_record.rb', line 24 def delete forecast_client.delete(self) end |
#fetch ⇒ Forecasting::Models::Base
It loads a new record from your Harvest account.
31 32 33 |
# File 'lib/forecasting/models/forecast_record.rb', line 31 def fetch self.class.new(@forecast_client.get(path), forecast_client: @forecast_client) end |
#save ⇒ Object
12 13 14 |
# File 'lib/forecasting/models/forecast_record.rb', line 12 def save id.nil? ? create : update end |
#type ⇒ String
It returns the model type
38 39 40 |
# File 'lib/forecasting/models/forecast_record.rb', line 38 def type self.class.name.split("::").last.downcase end |
#update ⇒ Object
20 21 22 |
# File 'lib/forecasting/models/forecast_record.rb', line 20 def update forecast_client.update(self) end |