Class: Features::Feature

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/features/feature.rb

Overview

If you want to add a feature, simply define a suitable symbol to Feature::LIST. If for example you want to define the “wiffle feature”, add :wiffle and you can subsequenctly do:

.features.wiffle?
.features.wiffle.destroy
.features.wiffle.create

Constant Summary collapse

LIST =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.class_to_sym(klass) ⇒ Object



47
48
49
# File 'lib/features/feature.rb', line 47

def self.class_to_sym(klass)
  klass.name.tableize.tableize[0..-10].to_sym
end

.dependant_featuresObject



73
74
75
# File 'lib/features/feature.rb', line 73

def self.dependant_features
  @dependant_features ||= []
end

.protected?Boolean



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

def self.protected?
  @protect || false
end

.required_featuresObject



66
67
68
# File 'lib/features/feature.rb', line 66

def self.required_features
  @required_features ||= []
end

.sym_to_class(sym) ⇒ Object



55
56
57
# File 'lib/features/feature.rb', line 55

def self.sym_to_class(sym)
  sym_to_name(sym).constantize
end

.sym_to_name(sym) ⇒ Object



51
52
53
# File 'lib/features/feature.rb', line 51

def self.sym_to_name(sym)
  "#{sym.to_s.camelize}Feature"
end

.to_symObject



43
44
45
# File 'lib/features/feature.rb', line 43

def self.to_sym
  @sym ||= Feature.class_to_sym(self)
end

Instance Method Details

#available?Boolean



23
24
25
# File 'lib/features/feature.rb', line 23

def available?
  feature_owner_instance.features.available?(to_sym)
end

#createObject



27
28
29
30
31
32
33
# File 'lib/features/feature.rb', line 27

def create
  if new_record?
    raise RequirementsError.new unless available?
    super
  end
  self
end

#dependant_featuresObject



76
77
78
# File 'lib/features/feature.rb', line 76

def dependant_features
  self.class.dependant_features
end

#matches?(sym) ⇒ Boolean



35
36
37
# File 'lib/features/feature.rb', line 35

def matches?(sym)
  to_sym == sym.to_sym
end

#protected?Boolean



62
63
64
# File 'lib/features/feature.rb', line 62

def protected?
  self.class.protected?
end

#required_featuresObject



69
70
71
# File 'lib/features/feature.rb', line 69

def required_features
  self.class.required_features
end

#to_symObject



39
40
41
# File 'lib/features/feature.rb', line 39

def to_sym
  @sym ||= Feature.class_to_sym(self.class)
end