Module: TimePilot::Features

Defined in:
lib/time_pilot/time_pilot.rb

Overview

Including this module makes a class a TimePilot class

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



54
55
56
# File 'lib/time_pilot/time_pilot.rb', line 54

def self.included(base)
  base.send :extend, ClassMethods
end

Instance Method Details

#pilot_disable_feature(feature_name) ⇒ Object



78
79
80
81
82
# File 'lib/time_pilot/time_pilot.rb', line 78

def pilot_disable_feature(feature_name)
  key_name = "#{feature_name}:#{self.class.to_s.underscore}_ids"
  TimePilot.redis.srem? TimePilot.key(key_name), id
  instance_variable_set("@#{feature_name}_enabled", false)
end

#pilot_enable_feature(feature_name) ⇒ Object



72
73
74
75
76
# File 'lib/time_pilot/time_pilot.rb', line 72

def pilot_enable_feature(feature_name)
  key_name = "#{feature_name}:#{self.class.to_s.underscore}_ids"
  TimePilot.redis.sadd? TimePilot.key(key_name), id
  instance_variable_set("@#{feature_name}_enabled", true)
end

#pilot_feature_enabled?(feature_name) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
87
88
89
90
# File 'lib/time_pilot/time_pilot.rb', line 84

def pilot_feature_enabled?(feature_name)
  unless instance_variable_defined?("@#{feature_name}_enabled")
    instance_variable_set("@#{feature_name}_enabled",
                          pilot_member_in_any_group?(feature_name))
  end
  instance_variable_get("@#{feature_name}_enabled")
end

#pilot_member_in_any_group?(feature_name) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
95
96
97
98
99
100
101
# File 'lib/time_pilot/time_pilot.rb', line 92

def pilot_member_in_any_group?(feature_name)
  TimePilot.redis.pipelined do |pipeline|
    self.class.time_pilot_groups.each do |group|
      pipeline.sismember(
        TimePilot.key("#{feature_name}:#{group}_ids"),
        send(pilot_method_for_group(group))
      )
    end
  end.include? true
end

#pilot_method_for_group(group_name) ⇒ Object



103
104
105
# File 'lib/time_pilot/time_pilot.rb', line 103

def pilot_method_for_group(group_name)
  group_name.to_s == self.class.to_s.underscore ? 'id' : group_name + '_id'
end