Class: Trebuchet::Strategy::CustomRequestAware

Inherits:
Custom
  • Object
show all
Defined in:
lib/trebuchet/strategy/custom_request_aware.rb

Constant Summary collapse

@@custom_request_aware_strategies =
{}

Instance Attribute Summary

Attributes inherited from Custom

#custom_name, #options

Attributes inherited from Base

#feature

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Custom

#as_json, #export, #needs_user?

Methods inherited from Base

#as_json, #export, #feature_id, #inspect, #name, #needs_user?, strategy_name

Constructor Details

#initialize(name, options = nil) ⇒ CustomRequestAware

Returns a new instance of CustomRequestAware.



4
5
6
7
8
# File 'lib/trebuchet/strategy/custom_request_aware.rb', line 4

def initialize(name, options = nil)
  @custom_name = name
  @options = options
  @block = @@custom_request_aware_strategies[name]
end

Class Method Details

.define(name, block) ⇒ Object



10
11
12
# File 'lib/trebuchet/strategy/custom_request_aware.rb', line 10

def self.define(name, block)
  @@custom_request_aware_strategies[name] = block
end

.exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/trebuchet/strategy/custom_request_aware.rb', line 14

def self.exists?(name)
  @@custom_request_aware_strategies.has_key?(name)
end

Instance Method Details

#launch_at?(user, request = nil) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/trebuchet/strategy/custom_request_aware.rb', line 18

def launch_at?(user, request = nil)
  request ||= {}
  !!(options ? @block.call(user, request, options) : @block.call(user, request))
end

#to_sObject



23
24
25
# File 'lib/trebuchet/strategy/custom_request_aware.rb', line 23

def to_s
  "#{custom_name} (custom_request_aware) #{options.inspect if options}"
end