Class: RgGen::Core::Builder::FeatureRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/rggen/core/builder/feature_registry.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_feature, factory) ⇒ FeatureRegistry

Returns a new instance of FeatureRegistry.



7
8
9
10
11
12
# File 'lib/rggen/core/builder/feature_registry.rb', line 7

def initialize(base_feature, factory)
  @base_feature = base_feature
  @factory = factory
  @feature_entries = {}
  @enabled_features = {}
end

Instance Method Details

#build_factoriesObject



89
90
91
92
93
94
95
# File 'lib/rggen/core/builder/feature_registry.rb', line 89

def build_factories
  target_features =
    (@enabled_features.empty? && @feature_entries || @enabled_features).keys
  @feature_entries
    .slice(*target_features)
    .transform_values(&method(:build_factory))
end

#define_feature(name, context = nil, &body) ⇒ Object



14
15
16
# File 'lib/rggen/core/builder/feature_registry.rb', line 14

def define_feature(name, context = nil, &body)
  create_new_entry(:general, name, context, &body)
end

#define_list_feature(list_name, context = nil, &body) ⇒ Object



22
23
24
# File 'lib/rggen/core/builder/feature_registry.rb', line 22

def define_list_feature(list_name, context = nil, &body)
  create_new_entry(:list, list_name, context, &body)
end

#define_list_item_feature(list_name, feature_name, context = nil, &body) ⇒ Object



26
27
28
# File 'lib/rggen/core/builder/feature_registry.rb', line 26

def define_list_item_feature(list_name, feature_name, context = nil, &body)
  list_item_entry(list_name).define_feature(feature_name, context, &body)
end

#define_simple_feature(name, context = nil, &body) ⇒ Object



18
19
20
# File 'lib/rggen/core/builder/feature_registry.rb', line 18

def define_simple_feature(name, context = nil, &body)
  create_new_entry(:simple, name, context, &body)
end

#delete(list_name = nil, feature_names) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/rggen/core/builder/feature_registry.rb', line 60

def delete(list_name = nil, feature_names)
  if list_name
    @feature_entries[list_name]&.delete(feature_names)
  else
    Array(feature_names).each(&@feature_entries.method(:delete))
  end
end

#delete_allObject



68
69
70
# File 'lib/rggen/core/builder/feature_registry.rb', line 68

def delete_all
  @feature_entries.clear
end

#enable(list_name = nil, feature_names) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/rggen/core/builder/feature_registry.rb', line 46

def enable(list_name = nil, feature_names)
  if list_name
    (@enabled_features[list_name] ||= []).merge!(Array(feature_names))
  else
    Array(feature_names).each do |name|
      @enabled_features.key?(name) || (@enabled_features[name] = nil)
    end
  end
end

#enable_allObject



56
57
58
# File 'lib/rggen/core/builder/feature_registry.rb', line 56

def enable_all
  @enabled_features.clear
end

#enabled_features(list_name = nil) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/rggen/core/builder/feature_registry.rb', line 80

def enabled_features(list_name = nil)
  if list_name
    enabled_list_features(list_name)
  else
    @enabled_features.empty? && @feature_entries.keys ||
      @enabled_features.keys & @feature_entries.keys
  end
end

#feature?(list_name = nil, feature_name) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
76
77
78
# File 'lib/rggen/core/builder/feature_registry.rb', line 72

def feature?(list_name = nil, feature_name)
  if list_name
    list_feature?(list_name, feature_name)
  else
    @feature_entries.key?(feature_name)
  end
end

#modify_feature(name, &body) ⇒ Object



30
31
32
# File 'lib/rggen/core/builder/feature_registry.rb', line 30

def modify_feature(name, &body)
  modify_entry(:general, name, &body)
end

#modify_list_feature(list_name, &body) ⇒ Object



38
39
40
# File 'lib/rggen/core/builder/feature_registry.rb', line 38

def modify_list_feature(list_name, &body)
  modify_entry(:list, list_name, &body)
end

#modify_list_item_feature(list_name, feature_name, &body) ⇒ Object



42
43
44
# File 'lib/rggen/core/builder/feature_registry.rb', line 42

def modify_list_item_feature(list_name, feature_name, &body)
  list_item_entry(list_name).modify_feature(feature_name, &body)
end

#modify_simple_feature(name, &body) ⇒ Object



34
35
36
# File 'lib/rggen/core/builder/feature_registry.rb', line 34

def modify_simple_feature(name, &body)
  modify_entry(:simple, name, &body)
end