Class: ModuleSync::Settings
- Inherits:
-
Object
- Object
- ModuleSync::Settings
- Defined in:
- lib/modulesync/settings.rb
Overview
Encapsulate a configs for a module, providing easy access to its parts All configs MUST be keyed by the relative target filename
Instance Attribute Summary collapse
-
#additional_settings ⇒ Object
readonly
Returns the value of attribute additional_settings.
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#global_defaults ⇒ Object
readonly
Returns the value of attribute global_defaults.
-
#module_configs ⇒ Object
readonly
Returns the value of attribute module_configs.
-
#module_defaults ⇒ Object
readonly
Returns the value of attribute module_defaults.
Instance Method Summary collapse
- #build_file_configs(target_name) ⇒ Object
-
#initialize(global_defaults, defaults, module_defaults, module_configs, additional_settings) ⇒ Settings
constructor
A new instance of Settings.
- #lookup_config(hash, target_name) ⇒ Object
- #managed?(target_name) ⇒ Boolean
-
#managed_files(target_name_list) ⇒ Object
given a list of templates in the repo, return everything that we might want to act on.
-
#unmanaged_files(target_name_list) ⇒ Object
returns a list of templates that should not be touched.
Constructor Details
#initialize(global_defaults, defaults, module_defaults, module_configs, additional_settings) ⇒ Settings
Returns a new instance of Settings.
8 9 10 11 12 13 14 |
# File 'lib/modulesync/settings.rb', line 8 def initialize(global_defaults, defaults, module_defaults, module_configs, additional_settings) @global_defaults = global_defaults @defaults = defaults @module_defaults = module_defaults @module_configs = module_configs @additional_settings = additional_settings end |
Instance Attribute Details
#additional_settings ⇒ Object (readonly)
Returns the value of attribute additional_settings.
6 7 8 |
# File 'lib/modulesync/settings.rb', line 6 def additional_settings @additional_settings end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
6 7 8 |
# File 'lib/modulesync/settings.rb', line 6 def defaults @defaults end |
#global_defaults ⇒ Object (readonly)
Returns the value of attribute global_defaults.
6 7 8 |
# File 'lib/modulesync/settings.rb', line 6 def global_defaults @global_defaults end |
#module_configs ⇒ Object (readonly)
Returns the value of attribute module_configs.
6 7 8 |
# File 'lib/modulesync/settings.rb', line 6 def module_configs @module_configs end |
#module_defaults ⇒ Object (readonly)
Returns the value of attribute module_defaults.
6 7 8 |
# File 'lib/modulesync/settings.rb', line 6 def module_defaults @module_defaults end |
Instance Method Details
#build_file_configs(target_name) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/modulesync/settings.rb', line 20 def build_file_configs(target_name) file_def = lookup_config(defaults, target_name) file_md = lookup_config(module_defaults, target_name) file_mc = lookup_config(module_configs, target_name) global_defaults.merge(file_def).merge(file_md).merge(file_mc).merge(additional_settings) end |
#lookup_config(hash, target_name) ⇒ Object
16 17 18 |
# File 'lib/modulesync/settings.rb', line 16 def lookup_config(hash, target_name) hash[target_name] || {} end |
#managed?(target_name) ⇒ Boolean
28 29 30 31 32 33 34 |
# File 'lib/modulesync/settings.rb', line 28 def managed?(target_name) Pathname.new(target_name).ascend do |v| configs = build_file_configs(v.to_s) return false if configs['unmanaged'] end true end |
#managed_files(target_name_list) ⇒ Object
given a list of templates in the repo, return everything that we might want to act on
37 38 39 40 41 |
# File 'lib/modulesync/settings.rb', line 37 def managed_files(target_name_list) (target_name_list | defaults.keys | module_configs.keys).select do |f| (f != ModuleSync::GLOBAL_DEFAULTS_KEY) && managed?(f) end end |
#unmanaged_files(target_name_list) ⇒ Object
returns a list of templates that should not be touched
44 45 46 47 48 |
# File 'lib/modulesync/settings.rb', line 44 def unmanaged_files(target_name_list) (target_name_list | defaults.keys | module_configs.keys).select do |f| (f != ModuleSync::GLOBAL_DEFAULTS_KEY) && !managed?(f) end end |