Class: Trebuchet::Strategy::Multiple

Inherits:
Base
  • Object
show all
Defined in:
lib/trebuchet/strategy/multiple.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#feature

Instance Method Summary collapse

Methods inherited from Base

#feature_id, #inspect, #name, strategy_name

Constructor Details

#initialize(args) ⇒ Multiple

Returns a new instance of Multiple.



5
6
7
8
9
10
# File 'lib/trebuchet/strategy/multiple.rb', line 5

def initialize(args)
  @strategies = []
  args.each_slice(2) do |pair|
    @strategies << Trebuchet::Strategy.find(*pair)
  end
end

Instance Attribute Details

#strategiesObject (readonly)

Returns the value of attribute strategies.



3
4
5
# File 'lib/trebuchet/strategy/multiple.rb', line 3

def strategies
  @strategies
end

Instance Method Details

#as_json(options = {}) ⇒ Object



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

def as_json(options = {})
  @strategies
end

#exportObject



33
34
35
# File 'lib/trebuchet/strategy/multiple.rb', line 33

def export
  super :strategies => strategies.map(&:export)
end

#feature=(f) ⇒ Object

override setter so that @feature gets set on @strategies as well



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

def feature=(f)
  @feature = f
  @strategies.each {|s| s.feature = f}
end

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

Returns:

  • (Boolean)


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

def launch_at?(user, request = nil)
  !!(strategies.select{|s| !user.nil? || !s.needs_user?}.find { |s| s.launch_at?(user, request) })
  # !!(strategies.find { |s| s.launch_at?(user, request) })
end

#needs_user?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/trebuchet/strategy/multiple.rb', line 27

def needs_user?
  false # assume some of the strategies may not need user
  # could change this so it calls only the strategies that don't need a user when none is present
  # strategies.any? { |s| s.needs_user? }
end