Module: Sequencescape::Api::Rails::Resourced

Defined in:
lib/sequencescape-api/rails.rb

Overview

Including this module into your Rails model indicates that the model is associated with a remote resource. This then means that your model table needs a string ‘uuid’ column and that when you perform a save the remote resource will also be saved if it can or needs to be. The remote resource is exposed through ‘remote_resource` which you are advised to use `delegate` to hand off to.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/sequencescape-api/rails.rb', line 57

def self.included(base)
  base.class_eval do
    attr_protected :remote_resource, :uuid
    validates_presence_of :uuid, :allow_blank => false
    before_save :save_remote_resource
  end
end

Instance Method Details

#remote_resource=(resource) ⇒ Object



65
66
67
68
# File 'lib/sequencescape-api/rails.rb', line 65

def remote_resource=(resource)
  @remote_resource = resource
  self[:uuid] = @remote_resource.uuid
end