Class: Flagship::Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/flagship/feature.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, enabled, context, tags = {}) ⇒ Feature



4
5
6
7
8
9
# File 'lib/flagship/feature.rb', line 4

def initialize(key, enabled, context, tags = {})
  @key = key
  @enabled = enabled
  @context = context
  @tags = tags
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



2
3
4
# File 'lib/flagship/feature.rb', line 2

def key
  @key
end

#tagsObject (readonly)

Returns the value of attribute tags.



2
3
4
# File 'lib/flagship/feature.rb', line 2

def tags
  @tags
end

Instance Method Details

#disabled?Boolean



30
31
32
# File 'lib/flagship/feature.rb', line 30

def disabled?
  !enabled?
end

#enabled?Boolean



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/flagship/feature.rb', line 11

def enabled?
  env = ENV['FLAGSHIP_' + key.to_s.upcase]

  if env
    case env.downcase
    when '1', 'true'
      return true
    when '0', 'false', ''
      return false
    end
  end

  if @enabled.respond_to?(:call)
    !!@enabled.call(@context)
  else
    !!@enabled
  end
end

#extend_feature(feature) ⇒ Object



34
35
36
# File 'lib/flagship/feature.rb', line 34

def extend_feature(feature)
  self.class.new(@key, @enabled, @context, feature.tags.merge(@tags))
end