Class: CORL::Plugin::Configuration

Inherits:
Object
  • Object
show all
Includes:
Mixin::SubConfig
Defined in:
lib/core/plugin/configuration.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.register_idsObject




10
11
12
# File 'lib/core/plugin/configuration.rb', line 10

def self.register_ids
  [ :name, :directory ]
end

Instance Method Details

#attach(type, name, data, options = {}) ⇒ Object




225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/core/plugin/configuration.rb', line 225

def attach(type, name, data, options = {})
  method_config = Config.ensure(options)
  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




83
84
85
# File 'lib/core/plugin/configuration.rb', line 83

def autoload(default = false)
  _get(:autoload, default)
end

#autoload=(autoload) ⇒ Object



87
88
89
# File 'lib/core/plugin/configuration.rb', line 87

def autoload=autoload
  _set(:autoload, test(autoload))
end

#autosave(default = false) ⇒ Object




93
94
95
# File 'lib/core/plugin/configuration.rb', line 93

def autosave(default = false)
  _get(:autosave, default)
end

#autosave=(autosave) ⇒ Object



97
98
99
# File 'lib/core/plugin/configuration.rb', line 97

def autosave=autosave
  _set(:autosave, test(autosave))
end

#cacheObject




71
72
73
# File 'lib/core/plugin/configuration.rb', line 71

def cache
  project.cache
end

#can_persist?Boolean


Checks

Returns:

  • (Boolean)


52
53
54
# File 'lib/core/plugin/configuration.rb', line 52

def can_persist?
  project.can_persist?
end

#clear(options = {}) ⇒ Object




130
131
132
133
# File 'lib/core/plugin/configuration.rb', line 130

def clear(options = {})
  super
  save(options) if initialized? && autosave
end

#delete(keys, options = {}) ⇒ Object




123
124
125
126
# File 'lib/core/plugin/configuration.rb', line 123

def delete(keys, options = {})
  super(keys)
  save(options) if initialized? && autosave
end

#delete_attachments(type, ids, options = {}) ⇒ Object




243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/core/plugin/configuration.rb', line 243

def delete_attachments(type, ids, options = {})
  method_config = Config.ensure(options)
  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

#directoryObject




65
66
67
# File 'lib/core/plugin/configuration.rb', line 65

def directory
  project.directory  
end

#ignore(files) ⇒ Object




77
78
79
# File 'lib/core/plugin/configuration.rb', line 77

def ignore(files)
  project.ignore(files)
end

#import(properties, options = {}) ⇒ Object


Import / Export



150
151
152
153
# File 'lib/core/plugin/configuration.rb', line 150

def import(properties, options = {})
  super(properties, options)
  save(options) if autosave
end

#load(options = {}) ⇒ Object


Configuration loading / saving



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/core/plugin/configuration.rb', line 158

def load(options = {})
  method_config = Config.ensure(options)
  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({}, {}, true, false)
      success    = yield(method_config, properties) if block_given?
        
      if success && ! properties.export.empty?
        logger.debug("Source configuration parsed properties: #{properties}")
      
        extension(:load_process, { :properties => properties, :config => method_config })               
        config.import(properties, method_config)
      end
    end
  else
    logger.warn("Loading of source configuration failed")
  end
  success
end

#normalize(reload) ⇒ Object


Configuration plugin interface



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/core/plugin/configuration.rb', line 17

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 => _delete(:manage_ignore, true)
  }), _delete(:project_provider, nil)) unless reload
      
  _init(:autoload, true)
  _init(:autosave, false)
  
  yield if block_given?
  
  set_location(@project)
end

#projectObject


Property accessors / modifiers



59
60
61
# File 'lib/core/plugin/configuration.rb', line 59

def project
  @project
end

#remote(name) ⇒ Object




137
138
139
# File 'lib/core/plugin/configuration.rb', line 137

def remote(name)
  project.remote(name)
end

#remove(options = {}) ⇒ Object




205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/core/plugin/configuration.rb', line 205

def remove(options = {})
  method_config = Config.ensure(options)
  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

#remove_pluginObject




45
46
47
# File 'lib/core/plugin/configuration.rb', line 45

def remove_plugin
  CORL.remove_plugin(@project)
end

#save(options = {}) ⇒ Object




186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/core/plugin/configuration.rb', line 186

def save(options = {})
  method_config = Config.ensure(options)
  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




116
117
118
119
# File 'lib/core/plugin/configuration.rb', line 116

def set(keys, value = '', options = {})
  super(keys, value, true)
  save(options) if initialized? && autosave
end

#set_location(directory) ⇒ Object




103
104
105
106
107
108
109
110
111
112
# File 'lib/core/plugin/configuration.rb', line 103

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




143
144
145
# File 'lib/core/plugin/configuration.rb', line 143

def set_remote(name, location)
  project.set_remote(name, location)
end