Class: Core::Service::Request

Inherits:
Object
  • Object
show all
Extended by:
Initializable
Includes:
Benchmarking, References, EndpointHandling
Defined in:
app/api/core/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Initializable

extended, initialized_attr_reader, initialized_delegate

Methods included from EndpointHandling

included, #instance, #model

Methods included from Benchmarking

#benchmark, registered

Constructor Details

#initialize(identifier, *args, &block) ⇒ Request


129
130
131
132
133
# File 'app/api/core/service.rb', line 129

def initialize(identifier, *args, &block)
  @identifier, @started_at = identifier, Time.now
  super(*args, &block)
  @ability = Core::Abilities.create(self)
end

Instance Attribute Details

#abilityObject (readonly)

Returns the value of attribute ability


124
125
126
# File 'app/api/core/service.rb', line 124

def ability
  @ability
end

#file=(value) ⇒ Object (writeonly)

Sets the attribute file


123
124
125
# File 'app/api/core/service.rb', line 123

def file=(value)
  @file = value
end

#filename=(value) ⇒ Object (writeonly)

Sets the attribute filename


123
124
125
# File 'app/api/core/service.rb', line 123

def filename=(value)
  @filename = value
end

#identifierObject (readonly)

Returns the value of attribute identifier


127
128
129
# File 'app/api/core/service.rb', line 127

def identifier
  @identifier
end

#io=(value) ⇒ Object (writeonly)

Sets the attribute io


123
124
125
# File 'app/api/core/service.rb', line 123

def io=(value)
  @io = value
end

#started_atObject (readonly)

Returns the value of attribute started_at


127
128
129
# File 'app/api/core/service.rb', line 127

def started_at
  @started_at
end

Instance Method Details

#attributes(_object = nil) ⇒ Object


159
160
161
# File 'app/api/core/service.rb', line 159

def attributes(_object = nil)
  io.map_parameters_to_attributes(json, nil)
end

#authentication_codeObject


139
140
141
142
143
144
# File 'app/api/core/service.rb', line 139

def authentication_code
  # The WTSISignOn service has been retired. However previously the code
  # supported supplying the API key in this cookie, so this has been left
  # for compatibility purposes
  @service.request.cookies['api_key'] || @service.request.cookies['WTSISignOn']
end

#authorisation_codeObject


135
136
137
# File 'app/api/core/service.rb', line 135

def authorisation_code
  @service.request.env['HTTP_X_SEQUENCESCAPE_CLIENT_ID']
end

#create!(instance_attributes = attributes) ⇒ Object


163
164
165
166
167
168
# File 'app/api/core/service.rb', line 163

def create!(instance_attributes = attributes)
  ActiveRecord::Base.transaction do
    record = target.create!(instance_attributes)
    ::Core::Io::Registry.instance.lookup_for_object(record).eager_loading_for(record.class).include_uuid.find(record.id)
  end
end

#push(value) ⇒ Object

Safe way to push a particular value on to the request target stack. Ensures that the original value is reset when the block is exitted.


152
153
154
155
156
157
# File 'app/api/core/service.rb', line 152

def push(value)
  target_before, @target = @target, value
  yield
ensure
  @target = target_before
end

#response(&block) ⇒ Object


146
147
148
# File 'app/api/core/service.rb', line 146

def response(&block)
  ::Core::Service::Response.new(self, &block)
end

#update!(instance_attributes = attributes) ⇒ Object


170
171
172
173
174
# File 'app/api/core/service.rb', line 170

def update!(instance_attributes = attributes)
  ActiveRecord::Base.transaction do
    target.tap { |o| o.update!(instance_attributes) }
  end
end