Class: Features::ActiveRecordExtension::FeatureTreeBuilder
- Inherits:
-
Object
- Object
- Features::ActiveRecordExtension::FeatureTreeBuilder
- Defined in:
- lib/features/active_record_extension.rb
Instance Method Summary collapse
- #build ⇒ Object
- #feature(name, options = {}) ⇒ Object
-
#initialize(owner_class) ⇒ FeatureTreeBuilder
constructor
A new instance of FeatureTreeBuilder.
- #resolve_dependencies ⇒ Object
Constructor Details
#initialize(owner_class) ⇒ FeatureTreeBuilder
Returns a new instance of FeatureTreeBuilder.
87 88 89 90 |
# File 'lib/features/active_record_extension.rb', line 87 def initialize(owner_class) @owner_class = owner_class @definitions = Hash.new end |
Instance Method Details
#build ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/features/active_record_extension.rb', line 107 def build resolve_dependencies #defines the feature classes @definitions.each do |name, | new_feature = Object.const_set(Feature.sym_to_name(name), Class.new(Feature)) new_feature.feature_owner = @owner_class end #sets the feature classes options @definitions.each do |name, | new_feature = Feature.sym_to_class(name) new_feature.protect! if [:protected] new_feature.required_features = [:requires].map {|f| Feature.sym_to_class(f)} new_feature.dependant_features = [:dependants].map {|f| Feature.sym_to_class(f)} Feature::LIST << name end end |
#feature(name, options = {}) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/features/active_record_extension.rb', line 92 def feature(name, = {}) raise("Feature name '#{name}' is too long. Max 28 characters please...") if name.to_s.size > 28 = .reverse_merge({:requires => [], :dependants => [], :protected => false}) [:requires] = [*[:requires]].uniq @definitions[name.to_sym] = end |
#resolve_dependencies ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/features/active_record_extension.rb', line 99 def resolve_dependencies @definitions.each do |name, | [:requires].each do |required_feature_name| @definitions[required_feature_name][:dependants] << name end end end |