Class: Sheriff::FeatureSet

Inherits:
Object
  • Object
show all
Defined in:
lib/sheriff/errors.rb,
lib/sheriff/feature_set.rb

Defined Under Namespace

Classes: AlreadyDefinedError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ FeatureSet

Returns a new instance of FeatureSet.



8
9
10
11
# File 'lib/sheriff/feature_set.rb', line 8

def initialize(name)
  @name = name
  @jurisdiction = Sheriff::Jurisdiction.new()
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



6
7
8
# File 'lib/sheriff/feature_set.rb', line 6

def context
  @context
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/sheriff/feature_set.rb', line 5

def name
  @name
end

Class Method Details

.allObject



45
46
47
# File 'lib/sheriff/feature_set.rb', line 45

def self.all
  Sheriff.defined_feature_sets
end

.define(feature_set_name) {|new_feature_set| ... } ⇒ Object

Yields:

  • (new_feature_set)


27
28
29
30
31
32
33
34
35
# File 'lib/sheriff/feature_set.rb', line 27

def self.define(feature_set_name)
  if self.defined? feature_set_name
    raise Sheriff::FeatureSet::AlreadyDefinedError.new("Feature Set #{feature_set_name} already defined")
  end

  new_feature_set = Sheriff::FeatureSet.new(feature_set_name)
  Sheriff.defined_feature_sets << new_feature_set
  yield(new_feature_set) if block_given?
end

.defined?(feature_set_name) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/sheriff/feature_set.rb', line 37

def self.defined?(feature_set_name)
  Sheriff.defined_feature_sets.map(&:name).include?(feature_set_name)
end

.find(name) ⇒ Object



41
42
43
# File 'lib/sheriff/feature_set.rb', line 41

def self.find(name)
  Sheriff.defined_feature_sets.select {|fs| fs.name == name}.first
end

Instance Method Details

#hide(*args) ⇒ Object



13
14
15
# File 'lib/sheriff/feature_set.rb', line 13

def hide(*args)
  @jurisdiction.hide *args
end

#show(*args) ⇒ Object



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

def show(*args)
  @jurisdiction.show *args
end

#visible?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/sheriff/feature_set.rb', line 21

def visible?
  caller.first.match /`(.+)'$/
  context_method = $1
  @jurisdiction.can? context_method.to_sym, @context
end