Class: Sapling::Memory::Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/sapling/memory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFeature

Returns a new instance of Feature.



7
8
9
10
# File 'lib/sapling/memory.rb', line 7

def initialize
  @users={}
  self.percentage = 0
end

Instance Attribute Details

#percentageObject

Returns the value of attribute percentage.



5
6
7
# File 'lib/sapling/memory.rb', line 5

def percentage
  @percentage
end

#usersObject

Returns the value of attribute users.



5
6
7
# File 'lib/sapling/memory.rb', line 5

def users
  @users
end

Instance Method Details

#activate_percentage(percentage) ⇒ Object



34
35
36
# File 'lib/sapling/memory.rb', line 34

def activate_percentage(percentage)
  @percentage=percentage
end

#activate_user(user) ⇒ Object



26
27
28
# File 'lib/sapling/memory.rb', line 26

def activate_user(user)
  users[user.id]=true
end

#active?(options = {}) ⇒ Boolean

see Sapling::API::Client

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/sapling/memory.rb', line 13

def active?(options={})
  options = Util.normalized_options(options)
  individually_active?(options[:user]) || percentage_active?(options)
end

#deactivate_percentageObject



38
39
40
# File 'lib/sapling/memory.rb', line 38

def deactivate_percentage
  @percentage=0
end

#deactivate_user(user) ⇒ Object



30
31
32
# File 'lib/sapling/memory.rb', line 30

def deactivate_user(user)
  users.delete(user.id)
end

#individually_active?(user) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/sapling/memory.rb', line 22

def individually_active?(user)
  user && users[user.id]
end

#percentage_active?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/sapling/memory.rb', line 18

def percentage_active?(options={})
  (Util.modded_context_id(options)) < percentage
end