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



53
54
55
56
57
58
59
# File 'lib/sequencescape-api/rails.rb', line 53

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



61
62
63
64
# File 'lib/sequencescape-api/rails.rb', line 61

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