Class: FeatureRelease

Inherits:
Object
  • Object
show all
Defined in:
lib/feature_release.rb,
lib/feature_release/feature.rb,
lib/feature_release/storage.rb,
lib/feature_release/version.rb

Defined Under Namespace

Classes: Feature, Storage

Constant Summary collapse

VERSION =
"0.0.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage = nil) ⇒ FeatureRelease

Returns a new instance of FeatureRelease.



9
10
11
12
13
14
15
# File 'lib/feature_release.rb', line 9

def initialize(storage=nil)
	@groups = {:all => lambda{|obj| true}}
	@features = Hash.new do |hash, missing_key|
	              hash[missing_key] = Feature.new(missing_key)
	            end
  set_storage(storage) if storage
end

Instance Attribute Details

#featuresObject (readonly)

Returns the value of attribute features.



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

def features
  @features
end

#groupsObject (readonly)

Returns the value of attribute groups.



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

def groups
  @groups
end

Instance Method Details

#activate_feature(feature, group) ⇒ Object



21
22
23
# File 'lib/feature_release.rb', line 21

def activate_feature(feature, group)
	@features[feature.to_sym].add_group(group)
end

#active?(feature, user) ⇒ Boolean

Returns:

  • (Boolean)


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

def active?(feature, user)
	return false if @features[feature.to_sym].groups.empty?
	@features[feature.to_sym].groups.all? {|group| groups[group].call(user)}
end

#deactivate_feature(feature, group) ⇒ Object



25
26
27
# File 'lib/feature_release.rb', line 25

def deactivate_feature(feature, group)
	@features[feature.to_sym].remove_group(group)
end

#define_group(name, &block) ⇒ Object



17
18
19
# File 'lib/feature_release.rb', line 17

def define_group(name, &block)
	@groups[name] = block
end

#persisted?(feature) ⇒ Boolean

Returns:

  • (Boolean)


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

def persisted?(feature)
  !(@storage.get(@features[feature.to_sym].name).nil?)
end

#saveObject



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

def save
  @features.each{|key, value|  @storage.save(value.name, value.to_string)}
end