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.
7 8 9 10 11 12 13 |
# File 'lib/modulesync/settings.rb', line 7 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.
5 6 7 |
# File 'lib/modulesync/settings.rb', line 5 def additional_settings @additional_settings end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
5 6 7 |
# File 'lib/modulesync/settings.rb', line 5 def defaults @defaults end |
#global_defaults ⇒ Object (readonly)
Returns the value of attribute global_defaults.
5 6 7 |
# File 'lib/modulesync/settings.rb', line 5 def global_defaults @global_defaults end |
#module_configs ⇒ Object (readonly)
Returns the value of attribute module_configs.
5 6 7 |
# File 'lib/modulesync/settings.rb', line 5 def module_configs @module_configs end |
#module_defaults ⇒ Object (readonly)
Returns the value of attribute module_defaults.
5 6 7 |
# File 'lib/modulesync/settings.rb', line 5 def module_defaults @module_defaults end |
Instance Method Details
#build_file_configs(target_name) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/modulesync/settings.rb', line 19 def build_file_configs(target_name) file_def = lookup_config(defaults, target_name) file_mc = lookup_config(module_configs, target_name) global_defaults.merge(file_def).merge(module_defaults).merge(file_mc).merge(additional_settings) end |
#lookup_config(hash, target_name) ⇒ Object
15 16 17 |
# File 'lib/modulesync/settings.rb', line 15 def lookup_config(hash, target_name) hash[target_name] || {} end |
#managed?(target_name) ⇒ Boolean
26 27 28 29 30 31 32 |
# File 'lib/modulesync/settings.rb', line 26 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
35 36 37 38 39 |
# File 'lib/modulesync/settings.rb', line 35 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
42 43 44 45 46 |
# File 'lib/modulesync/settings.rb', line 42 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 |