Module: ActiveRemote::Persistence::ClassMethods
- Defined in:
- lib/active_remote/persistence.rb
Instance Method Summary collapse
- 
  
    
      #create(attributes)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Creates a remote record through the service. 
- 
  
    
      #create!(attributes)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Creates a remote record through the service and if successful, returns the newly created record. 
- 
  
    
      #instantiate(new_attributes = {}, options = {})  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Instantiate a record with the given remote attributes. 
- 
  
    
      #readonly!  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Mark the class as readonly. 
- 
  
    
      #readonly?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Returns true if the class is marked as readonly; otherwise, returns false. 
Instance Method Details
#create(attributes) ⇒ Object
Creates a remote record through the service.
The service will run any validations and if any of them fail, will return the record error messages indicating what went wrong.
The newly created record is returned if it was successfully saved or not.
| 30 31 32 33 34 | # File 'lib/active_remote/persistence.rb', line 30 def create(attributes) remote = self.new(attributes) remote.save remote end | 
#create!(attributes) ⇒ Object
Creates a remote record through the service and if successful, returns the newly created record.
The service will run any validations and if any of them fail, will raise an ActiveRemote::RemoteRecordNotSaved exception.
| 42 43 44 45 46 | # File 'lib/active_remote/persistence.rb', line 42 def create!(attributes) remote = self.new(attributes) remote.save! remote end | 
#instantiate(new_attributes = {}, options = {}) ⇒ Object
Instantiate a record with the given remote attributes. Generally used when retrieving records that already exist, so @new_record is set to false.
| 51 52 53 54 55 56 57 | # File 'lib/active_remote/persistence.rb', line 51 def instantiate(new_attributes = {}, = {}) attributes = self.build_from_rpc(new_attributes) new_object = self.allocate.init_with(attributes) new_object.readonly! if [:readonly] new_object end | 
#readonly! ⇒ Object
Mark the class as readonly. Overrides instance-level readonly, making any instance of this class readonly.
| 61 62 63 | # File 'lib/active_remote/persistence.rb', line 61 def readonly! @readonly = true end | 
#readonly? ⇒ Boolean
Returns true if the class is marked as readonly; otherwise, returns false.
| 66 67 68 | # File 'lib/active_remote/persistence.rb', line 66 def readonly? @readonly end |