Class: Nucleon::Plugin::Configuration
- Inherits:
-
Object
- Object
- Nucleon::Plugin::Configuration
- Includes:
- Mixin::SubConfig
- Defined in:
- lib/core/plugin/configuration.rb
Instance Method Summary collapse
-
#attach(type, name, data, options = {}) ⇒ Object
—.
-
#autoload(default = false) ⇒ Object
—.
- #autoload=(autoload) ⇒ Object
-
#autosave(default = false) ⇒ Object
—.
- #autosave=(autosave) ⇒ Object
-
#cache ⇒ Object
—.
-
#can_persist? ⇒ Boolean
—————————————————————————– Checks.
-
#clear(options = {}) ⇒ Object
—.
-
#delete(keys, options = {}) ⇒ Object
—.
-
#delete_attachments(type, ids, options = {}) ⇒ Object
—.
-
#directory ⇒ Object
—.
-
#ignore(files) ⇒ Object
—.
-
#import(properties, options = {}) ⇒ Object
—————————————————————————– Import / Export.
-
#load(options = {}) ⇒ Object
—————————————————————————– Configuration loading / saving.
-
#normalize(reload) ⇒ Object
—————————————————————————– Configuration plugin interface.
-
#project ⇒ Object
—————————————————————————– Property accessors / modifiers.
-
#remote(name) ⇒ Object
—————————————————————————–.
-
#remove(options = {}) ⇒ Object
—.
-
#save(options = {}) ⇒ Object
—.
-
#set(keys, value = '', options = {}) ⇒ Object
—————————————————————————–.
-
#set_location(directory) ⇒ Object
—————————————————————————–.
-
#set_remote(name, location) ⇒ Object
—.
Instance Method Details
#attach(type, name, data, options = {}) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/core/plugin/configuration.rb', line 213 def attach(type, name, data, = {}) method_config = Config.ensure() new_location = nil if can_persist? if extension_check(:attach, { :config => method_config }) logger.info("Attaching data to source configuration") new_location = yield(method_config) if block_given? end else logger.warn("Can not attach data to source configuration") end new_location end |
#autoload(default = false) ⇒ Object
70 71 72 |
# File 'lib/core/plugin/configuration.rb', line 70 def autoload(default = false) _get(:autoload, default) end |
#autoload=(autoload) ⇒ Object
74 75 76 |
# File 'lib/core/plugin/configuration.rb', line 74 def autoload=autoload _set(:autoload, test(autoload)) end |
#autosave(default = false) ⇒ Object
80 81 82 |
# File 'lib/core/plugin/configuration.rb', line 80 def autosave(default = false) _get(:autosave, default) end |
#autosave=(autosave) ⇒ Object
84 85 86 |
# File 'lib/core/plugin/configuration.rb', line 84 def autosave=autosave _set(:autosave, test(autosave)) end |
#cache ⇒ Object
58 59 60 |
# File 'lib/core/plugin/configuration.rb', line 58 def cache project.cache end |
#can_persist? ⇒ Boolean
Checks
39 40 41 |
# File 'lib/core/plugin/configuration.rb', line 39 def can_persist? project.can_persist? end |
#clear(options = {}) ⇒ Object
117 118 119 120 |
# File 'lib/core/plugin/configuration.rb', line 117 def clear( = {}) super save() if autosave end |
#delete(keys, options = {}) ⇒ Object
110 111 112 113 |
# File 'lib/core/plugin/configuration.rb', line 110 def delete(keys, = {}) super(keys) save() if autosave end |
#delete_attachments(type, ids, options = {}) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/core/plugin/configuration.rb', line 231 def (type, ids, = {}) method_config = Config.ensure() locations = [] if can_persist? if extension_check(:remove_attachments, { :config => method_config }) logger.info("Removing attached data from source configuration") locations = yield(method_config) if block_given? end else logger.warn("Can not remove attached data from source configuration") end locations end |
#directory ⇒ Object
52 53 54 |
# File 'lib/core/plugin/configuration.rb', line 52 def directory project.directory end |
#ignore(files) ⇒ Object
64 65 66 |
# File 'lib/core/plugin/configuration.rb', line 64 def ignore(files) project.ignore(files) end |
#import(properties, options = {}) ⇒ Object
Import / Export
137 138 139 140 |
# File 'lib/core/plugin/configuration.rb', line 137 def import(properties, = {}) super(properties, ) save() if autosave end |
#load(options = {}) ⇒ Object
Configuration loading / saving
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/core/plugin/configuration.rb', line 145 def load( = {}) method_config = Config.ensure() success = false if can_persist? if extension_check(:load, { :config => method_config }) logger.info("Loading source configuration") config.clear if method_config.get(:override, false) properties = Config.new yield(method_config, properties) if block_given? unless properties.export.empty? logger.debug("Source configuration parsed properties: #{properties}") extension(:load_process, { :properties => properties, :config => method_config }) config.import(properties, method_config) end success = true end else logger.warn("Loading of source configuration failed") end success end |
#normalize(reload) ⇒ Object
Configuration plugin interface
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/core/plugin/configuration.rb', line 11 def normalize(reload) super logger.debug("Initializing source sub configuration") init_subconfig(true) unless reload logger.info("Setting source configuration project") @project = CORL.project(extended_config(:project, { :directory => _delete(:directory, Dir.pwd), :url => _delete(:url), :revision => _delete(:revision), :create => _delete(:create, false), :pull => true, :internal_ip => CORL.public_ip, # Needed for seeding Vagrant VMs :manage_ignore => true }), _delete(:project_provider)) _init(:autoload, true) _init(:autosave, false) yield if block_given? set_location(@project) end |
#project ⇒ Object
Property accessors / modifiers
46 47 48 |
# File 'lib/core/plugin/configuration.rb', line 46 def project @project end |
#remote(name) ⇒ Object
124 125 126 |
# File 'lib/core/plugin/configuration.rb', line 124 def remote(name) project.remote(name) end |
#remove(options = {}) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/core/plugin/configuration.rb', line 193 def remove( = {}) method_config = Config.ensure() success = false if can_persist? if extension_check(:delete, { :config => method_config }) logger.info("Removing source configuration") config.clear success = yield(method_config) if block_given? end else logger.warn("Can not remove source configuration") end success end |
#save(options = {}) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/core/plugin/configuration.rb', line 174 def save( = {}) method_config = Config.ensure() success = false if can_persist? if extension_check(:save, { :config => method_config }) logger.info("Saving source configuration") logger.debug("Source configuration properties: #{config.export}") success = yield(method_config) if block_given? end else logger.warn("Can not save source configuration") end success end |
#set(keys, value = '', options = {}) ⇒ Object
103 104 105 106 |
# File 'lib/core/plugin/configuration.rb', line 103 def set(keys, value = '', = {}) super(keys, value) save() if autosave end |
#set_location(directory) ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/core/plugin/configuration.rb', line 90 def set_location(directory) if directory && directory.is_a?(CORL::Plugin::Project) logger.debug("Setting source project directory from other project at #{directory.directory}") project.set_location(directory.directory) elsif directory && directory.is_a?(String) || directory.is_a?(Symbol) logger.debug("Setting source project directory to #{directory}") project.set_location(directory.to_s) end end |
#set_remote(name, location) ⇒ Object
130 131 132 |
# File 'lib/core/plugin/configuration.rb', line 130 def set_remote(name, location) project.set_remote(name, location) end |