Class: OFFS

Inherits:
Object
  • Object
show all
Defined in:
lib/offs.rb,
lib/offs/flags.rb,
lib/offs/version.rb,
lib/offs/exceptions.rb,
lib/offs/permutations.rb

Defined Under Namespace

Classes: AlreadyInitializedError, FeatureDisabled, Flags, Permutations, UndefinedFlagError

Constant Summary collapse

VERSION =
"2.0.2"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flag, flag_status_checker: nil) ⇒ OFFS

Returns a new instance of OFFS.



29
30
31
32
# File 'lib/offs.rb', line 29

def initialize(flag, flag_status_checker: nil)
  self.flag_status_checker = flag_status_checker || Flags.instance
  self.flag = flag
end

Class Method Details

.if_you_do_not_want_to(flag, flag_status_checker: nil, &block) ⇒ Object



17
18
19
20
21
# File 'lib/offs.rb', line 17

def if_you_do_not_want_to(flag, flag_status_checker: nil, &block)
  so_you_want_to(flag, flag_status_checker: flag_status_checker) do |you|
    you.may_still_need_to(&block)
  end
end

.if_you_would_like_to(flag, flag_status_checker: nil, &block) ⇒ Object



11
12
13
14
15
# File 'lib/offs.rb', line 11

def if_you_would_like_to(flag, flag_status_checker: nil, &block)
  so_you_want_to(flag, flag_status_checker: flag_status_checker) do |you|
    you.would_like_to(&block)
  end
end

.raise_error_unless_we(flag, flag_status_checker: nil) ⇒ Object



23
24
25
26
# File 'lib/offs.rb', line 23

def raise_error_unless_we(flag, flag_status_checker: nil)
  new(flag, flag_status_checker: flag_status_checker) \
    .raise_error_unless_we
end

.so_you_want_to(flag, flag_status_checker: nil, &block) ⇒ Object



7
8
9
# File 'lib/offs.rb', line 7

def so_you_want_to(flag, flag_status_checker: nil, &block)
  new(flag, flag_status_checker: flag_status_checker).so_you_want_to(&block)
end

Instance Method Details

#may_still_need_to(&block) ⇒ Object



43
44
45
# File 'lib/offs.rb', line 43

def may_still_need_to(&block)
  when_flag(false, &block)
end

#raise_error_unless_weObject



47
48
49
50
51
52
53
# File 'lib/offs.rb', line 47

def raise_error_unless_we
  unless flag_enabled?
    raise FeatureDisabled,
      "Attempted to access code that is only available when the '#{flag}' " \
      + "feature is enabled, and it is currenlty disabled."
  end
end

#so_you_want_to(&block) ⇒ Object



34
35
36
37
# File 'lib/offs.rb', line 34

def so_you_want_to(&block)
  block.call(self)
  return result
end

#would_like_to(&block) ⇒ Object



39
40
41
# File 'lib/offs.rb', line 39

def would_like_to(&block)
  when_flag(true, &block)
end