Class: Cropio::Resource::Base
- Inherits:
-
Object
- Object
- Cropio::Resource::Base
- Includes:
- Attributes
- Defined in:
- lib/cropio/resource/base.rb
Overview
Represents ActiveRecord::Base-like model’s class with Cropio data selection and mutation.
Direct Known Subclasses
Cropio::Resources::AdditionalObject, Cropio::Resources::AgriWorkPlan, Cropio::Resources::AgriWorkPlanApplicationMixItem, Cropio::Resources::AgroOperation, Cropio::Resources::Alert, Cropio::Resources::AlertType, Cropio::Resources::ApplicationMixItem, Cropio::Resources::AutomaticAlert, Cropio::Resources::Avatar, Cropio::Resources::Chemical, Cropio::Resources::Counterparty, Cropio::Resources::Crop, Cropio::Resources::Fertilizer, Cropio::Resources::Field, Cropio::Resources::FieldGroup, Cropio::Resources::FieldScoutReport, Cropio::Resources::FieldScoutReportThreatMappingItem, Cropio::Resources::FieldShape, Cropio::Resources::FieldShapeLandParcelMappingItem, Cropio::Resources::FuelHourlyDataItem, Cropio::Resources::FuelMovement, Cropio::Resources::FuelPump, Cropio::Resources::FuelStation, Cropio::Resources::FuelTank, Cropio::Resources::FuelType, Cropio::Resources::GroupFolder, Cropio::Resources::GrowthScale, Cropio::Resources::GrowthStage, Cropio::Resources::GrowthStageGroup, Cropio::Resources::GrowthStageStructureMappingItem, Cropio::Resources::GrowthStagesPrediction, Cropio::Resources::HarvestWeighing, Cropio::Resources::HistoricalValue, Cropio::Resources::HistoryItem, Cropio::Resources::Implement, Cropio::Resources::ImplementRegionMappingItem, Cropio::Resources::InventoryHistoryItem, Cropio::Resources::LandDocument, Cropio::Resources::LandDocumentLandParcelMappingItem, Cropio::Resources::LandParcel, Cropio::Resources::Machine, Cropio::Resources::MachineGroup, Cropio::Resources::MachineRegion, Cropio::Resources::MachineRegionMappingItem, Cropio::Resources::MachineTask, Cropio::Resources::MachineTaskAgroOperationMappingItem, Cropio::Resources::MachineTaskFieldMappingItem, Cropio::Resources::MaintenancePlan, Cropio::Resources::MaintenancePlanRow, Cropio::Resources::MaintenancePlanRowSparePartMappingItem, Cropio::Resources::MaintenanceRecord, Cropio::Resources::MaintenanceRecordRow, Cropio::Resources::MaintenanceRecordRowSparePartMappingItem, Cropio::Resources::MaintenanceType, Cropio::Resources::MaintenanceTypeGroup, Cropio::Resources::Note, Cropio::Resources::Photo, Cropio::Resources::PlantThreat, Cropio::Resources::ProductivityEstimate, Cropio::Resources::ProductivityEstimateHistory, Cropio::Resources::ProductivityEstimatePeer, Cropio::Resources::ProtectedDocument, Cropio::Resources::SatelliteImage, Cropio::Resources::ScoutReportPoint, Cropio::Resources::ScoutReportPointGrowthStageStructure, Cropio::Resources::ScoutReportPointIssue, Cropio::Resources::ScoutReportPointIssuePlantPart, Cropio::Resources::ScoutReportPointMeasurement, Cropio::Resources::ScoutReportTemplate, Cropio::Resources::ScoutingTask, Cropio::Resources::ScoutingTaskPoint, Cropio::Resources::Seed, Cropio::Resources::SoilTest, Cropio::Resources::SoilTestSample, Cropio::Resources::SparePart, Cropio::Resources::SparePartManufacturer, Cropio::Resources::User, Cropio::Resources::UserRole, Cropio::Resources::UserRoleAssignment, Cropio::Resources::UserRolePermission, Cropio::Resources::Version, Cropio::Resources::WeatherHistoryItem, Cropio::Resources::WorkRecord, Cropio::Resources::WorkRecordMachineRegionMappingItem, Cropio::Resources::WorkType, Cropio::Resources::WorkTypeGroup
Constant Summary collapse
- PROXY =
Cropio::Connection::Proxy
- LIMIT =
1000
Class Method Summary collapse
-
.all ⇒ Object
Get all resources.
- .changes(from_time = nil, to_time = nil) ⇒ Object
-
.count ⇒ Object
Count all resources.
- .find(id) ⇒ Object
- .ids ⇒ Object
-
.resource_name ⇒ Object
Returns name of Resource.
-
.resources_name ⇒ Object
Return pluralized version of Resource’s name.
Instance Method Summary collapse
-
#destroy ⇒ Object
Remove this resource from Cropio.
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
-
#persisted? ⇒ Boolean
Returns persistance of the resource.
-
#save ⇒ Object
Saves current resource to Cropio.
Methods included from Attributes
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
11 12 13 |
# File 'lib/cropio/resource/base.rb', line 11 def initialize(attributes = {}) self.attributes = attributes end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Cropio::Resource::Attributes
Class Method Details
.all ⇒ Object
Get all resources.
26 27 28 |
# File 'lib/cropio/resource/base.rb', line 26 def self.all to_instances(get_all_chunks) end |
.changes(from_time = nil, to_time = nil) ⇒ Object
39 40 41 42 43 |
# File 'lib/cropio/resource/base.rb', line 39 def self.changes(from_time = nil, to_time = nil) from_time = to_datetime_if_string(from_time) to_time = to_datetime_if_string(to_time) to_instances(get_all_changes(from_time, to_time)) end |
.count ⇒ Object
Count all resources.
31 32 33 |
# File 'lib/cropio/resource/base.rb', line 31 def self.count all.count end |
.find(id) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/cropio/resource/base.rb', line 45 def self.find(id) obj = PROXY.get(resources_name, id: id).fetch('data', nil) return if obj.nil? to_instance(obj) end |
.ids ⇒ Object
35 36 37 |
# File 'lib/cropio/resource/base.rb', line 35 def self.ids get_all_ids end |
.resource_name ⇒ Object
Returns name of Resource
16 17 18 |
# File 'lib/cropio/resource/base.rb', line 16 def self.resource_name @resource_name ||= StringInflector.underscore(name.split('::').last) end |
.resources_name ⇒ Object
Return pluralized version of Resource’s name
21 22 23 |
# File 'lib/cropio/resource/base.rb', line 21 def self.resources_name @resources_name ||= StringInflector.pluralize(resource_name) end |
Instance Method Details
#destroy ⇒ Object
Remove this resource from Cropio.
72 73 74 75 76 77 78 79 80 |
# File 'lib/cropio/resource/base.rb', line 72 def destroy if persisted? PROXY.delete("#{resources_name}/#{id}") @persisted = false true else fail 'Cropio record is not persisted!' end end |
#persisted? ⇒ Boolean
Returns persistance of the resource. Resource is persisted if it is saved and not deleted, if this resource exists on Cropio servers.
56 57 58 |
# File 'lib/cropio/resource/base.rb', line 56 def persisted? !@persisted.nil? && (@persisted ||= false) end |