class Featuring::Persistence::Transaction

public

Persist multiple feature flag values for an object at once.

class User < ActiveRecord::Base
  extend Featuring::Persistence::ActiveRecord

  extend Featuring::Declarable
  feature :feature_1
  feature :feature_2
end

User.find(1).features.transaction do |features|
  features.enable :feature_1
  features.disable :feature_2
end

User.find(1).features.feature_1?
=> true

User.find(1).features.feature_2?
=> false

Attributes

values[R]

Public Class Methods

new(features) click to toggle source
# File lib/featuring/persistence/transaction.rb, line 31
def initialize(features)
  @features = features
  @values = {}
end

Public Instance Methods

disable(feature) click to toggle source
public

Disable a feature flag.

See ‘Featuring::Persistence::Adapter::Methods#disable`.

# File lib/featuring/persistence/transaction.rb, line 64
def disable(feature)
  @values[feature.to_sym] = false
end
enable(feature) click to toggle source
public

Enable a feature flag.

See ‘Featuring::Persistence::Adapter::Methods#enable`.

# File lib/featuring/persistence/transaction.rb, line 56
def enable(feature)
  @values[feature.to_sym] = true
end
persist(feature, *args) click to toggle source
public

Persist the default or computed value for a feature flag within a transaction.

See ‘Featuring::Persistence::Adapter::Methods#persist`.

# File lib/featuring/persistence/transaction.rb, line 40
def persist(feature, *args)
  @values[feature.to_sym] = @features.fetch_feature_flag_value(feature, *args, raw: true)
end
reset(feature) click to toggle source
public

Reset a feature flag.

See ‘Featuring::Persistence::Adapter::Methods#reset`.

# File lib/featuring/persistence/transaction.rb, line 72
def reset(feature)
  @values.delete(feature.to_sym)
end
set(feature, value) click to toggle source
public

Set the value for a feature flag within a transaction.

See ‘Featuring::Persistence::Adapter::Methods#set`.

# File lib/featuring/persistence/transaction.rb, line 48
def set(feature, value)
  @values[feature.to_sym] = !!value
end