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




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

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




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

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

#autoload=(autoload) ⇒ Object



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

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

#autosave(default = false) ⇒ Object




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

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

#autosave=(autosave) ⇒ Object



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

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

#cacheObject




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

def cache
  project.cache
end

#can_persist?Boolean


Checks

Returns:

  • (Boolean)


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

def can_persist?
  project.can_persist?
end

#clear(options = {}) ⇒ Object




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

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

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




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

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

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




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

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




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

def directory
  project.directory
end

#ignore(files) ⇒ Object




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

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

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


Import / Export



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

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

#load(options = {}) ⇒ Object


Configuration loading / saving



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

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
    success = cache.load if success
  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
42
# 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),
    :new           => 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



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

def project
  @project
end

#remote(name) ⇒ Object




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

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

#remove(options = {}) ⇒ Object




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

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




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

def remove_plugin
  CORL.remove_plugin(@project)
end

#save(options = {}) ⇒ Object




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

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
    success = cache.save if success
  else
    logger.warn("Can not save source configuration")
  end
  success
end

#set(keys, value = '', options = {}) ⇒ Object




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

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

#set_location(directory) ⇒ Object




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

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




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

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