Class: Eaco::Cucumber::ActiveRecord::User::Designators::User

Inherits:
Designator
  • Object
show all
Defined in:
lib/eaco/cucumber/active_record/user/designators/user.rb

Overview

The simplest Designator. It resolves actors by their unique ID, such as an autoincrementing ID in a relational database.

The ID is available as the Designator#value. If the Designator is instantiated with a live instance (see Designator#initialize) then it is re-used and a query to the database is avoided.

The designator string representation for user 42 is “user:42”.

Instance Attribute Summary

Attributes inherited from Designator

#instance, #value

Instance Method Summary collapse

Methods inherited from Designator

#as_json, configure!, designator_name, harvest, id, #initialize, #inspect, #label, label, make, parse, resolve, search, #type

Constructor Details

This class inherits a constructor from Eaco::Designator

Instance Method Details

#describeString

This Designator description

Returns:


23
24
25
# File 'lib/eaco/cucumber/active_record/user/designators/user.rb', line 23

def describe(*)
  "User '%s'" % [target_user.name]
end

#resolveArray

Returns:


32
33
34
# File 'lib/eaco/cucumber/active_record/user/designators/user.rb', line 32

def resolve
  [target_user]
end

#target_userUser (private)

Looks up this user by ID, and memoizes it using the Designator#instance= accessor.

Returns:

  • (User)

    this very user.


43
44
45
# File 'lib/eaco/cucumber/active_record/user/designators/user.rb', line 43

def target_user
  self.instance ||= ActiveRecord::User.find(self.value)
end