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) ⇒ Request

Returns a new instance of Request.



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

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

Instance Attribute Details

#abilityObject (readonly)

Returns the value of attribute ability.



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

def ability
  @ability
end

#file=(value) ⇒ Object (writeonly)

Sets the attribute file

Parameters:

  • value

    the value to set the attribute file to.



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

def file=(value)
  @file = value
end

#filename=(value) ⇒ Object (writeonly)

Sets the attribute filename

Parameters:

  • value

    the value to set the attribute filename to.



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

def filename=(value)
  @filename = value
end

#identifierObject (readonly)

Returns the value of attribute identifier.



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

def identifier
  @identifier
end

#io=(value) ⇒ Object (writeonly)

Sets the attribute io

Parameters:

  • value

    the value to set the attribute io to.



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

def io=(value)
  @io = value
end

#started_atObject (readonly)

Returns the value of attribute started_at.



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

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
169
170
171
172
173
# 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

#responseObject



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

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

#update!(instance_attributes = attributes) ⇒ Object



175
176
177
# File 'app/api/core/service.rb', line 175

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