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




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

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




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

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

#autoload=(autoload) ⇒ Object



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

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

#autosave(default = false) ⇒ Object




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

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

#autosave=(autosave) ⇒ Object



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

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

#cacheObject




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

def cache
  project.cache
end

#can_persist?Boolean


Checks

Returns:

  • (Boolean)


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

def can_persist?
  project.can_persist?
end

#clear(options = {}) ⇒ Object




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

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

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




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

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

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




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

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




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

def directory
  project.directory  
end

#ignore(files) ⇒ Object




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

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

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


Import / Export



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

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

#load(options = {}) ⇒ Object


Configuration loading / saving



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

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
      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
# 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))
      
  _init(:autoload, true)
  _init(:autosave, false)
  
  yield if block_given?
  
  set_location(@project)
end

#projectObject


Property accessors / modifiers



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

def project
  @project
end

#remote(name) ⇒ Object




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

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

#remove(options = {}) ⇒ Object




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

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




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

def remove_plugin
  CORL.remove_plugin(@project)
end

#save(options = {}) ⇒ Object




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

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




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

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

#set_location(directory) ⇒ Object




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

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




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

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