4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/features/active_record_extension.rb', line 4
def has_features(&block)
builder = FeatureTreeBuilder.new(self)
builder.instance_eval(&block)
builder.build
has_many :features, :class_name => 'Features::Feature', :dependent => :destroy do
def available?(feature_name)
@owner.features?(*Feature.sym_to_class(feature_name).required_features.map(&:to_sym))
end
Feature::LIST.each do |f|
define_method "#{f}?" do
any? { |feature| feature.matches?(f) }
end
define_method "#{f}" do
instance = detect { |feature| feature.matches?(f) }
instance ||= Feature.sym_to_class(f).new(@owner.class.name.underscore.to_sym => @owner)
end
end
end
include Features::ActiveRecordExtension::InstanceMethods
alias_method_chain :update_attributes, :features
alias_method_chain :update_attributes!, :features
end
|