Class: Pageflow::Features

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pageflow/features.rb

Overview

A registry of [Feature} objects.

Since:

  • 0.9

Instance Method Summary collapse

Constructor Details

#initializeFeatures

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Features.

Since:

  • 0.9



9
10
11
12
13
# File 'lib/pageflow/features.rb', line 9

def initialize
  @features = {}
  @enabled_features = []
  @default_features = []
end

Instance Method Details

#each(&block) ⇒ Object

Since:

  • 0.9



88
89
90
# File 'lib/pageflow/features.rb', line 88

def each(&block)
  @features.values.each(&block)
end

#enable(names, config) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.9



64
65
66
67
68
69
70
71
72
# File 'lib/pageflow/features.rb', line 64

def enable(names, config)
  @enabled_features = names

  names.each do |name|
    raise(ArgumentError, "Cannot enable unknown feature #{name}.") unless @features.key?(name)

    @features[name].enable(config)
  end
end

#enable_all(config) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.9



75
76
77
# File 'lib/pageflow/features.rb', line 75

def enable_all(config)
  enable(@features.keys, config)
end

#enable_by_default(name) ⇒ Object

Enable a feature by default for all accounts. The feature can still be disabled via the web interface.

Since:

  • 0.10



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

def enable_by_default(name)
  @default_features << name
end

#enabled?(name) ⇒ Boolean

Check if a feature has been enabled.

Parameters:

  • name (String)

    Name of the feature

Returns:

  • (Boolean)

Since:

  • 0.9



46
47
48
# File 'lib/pageflow/features.rb', line 46

def enabled?(name)
  @enabled_features.include?(name)
end

#enabled_by_default?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 0.9



59
60
61
# File 'lib/pageflow/features.rb', line 59

def enabled_by_default?(name)
  @default_features.include?(name)
end

#lint!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.9



80
81
82
83
84
85
86
# File 'lib/pageflow/features.rb', line 80

def lint!
  @default_features.each do |name|
    unless @features.key?(name)
      raise(ArgumentError, "Cannot enable unknown feature #{name} by default.")
    end
  end
end

#register(feature) ⇒ Object #register(feature) {|config| ... } ⇒ Object #register(feature) ⇒ Object

Register a feature that can be enabled for accounts of entries. If the first parameter is a string, a block can be passed to provide the enable method. If only a string is passed, enabling the feature is no-op.

Overloads:

  • #register(feature) ⇒ Object

    Parameters:

  • #register(feature) {|config| ... } ⇒ Object

    Parameters:

    • feature (String)

    Yield Parameters:

  • #register(feature) ⇒ Object

    Parameters:

    • feature (String)

Since:

  • 0.9



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pageflow/features.rb', line 30

def register(feature, &block)
  if feature.is_a?(String)
    return register(Feature.new(feature, &block))
  end

  if @features.key?(feature.name)
    raise(ArgumentError, "Feature #{feature.name} is already registered.")
  end

  @features[feature.name] = feature
end