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




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

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




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

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

#autoload=(autoload) ⇒ Object



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

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

#autosave(default = false) ⇒ Object




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

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

#autosave=(autosave) ⇒ Object



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

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

#cacheObject




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

def cache
  project.cache
end

#can_persist?Boolean


Checks

Returns:

  • (Boolean)


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

def can_persist?
  project.can_persist?
end

#clear(options = {}) ⇒ Object




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

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

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




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

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

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




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

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




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

def directory
  project.directory
end

#ignore(files) ⇒ Object




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

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

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


Import / Export



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

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

#load(options = {}) ⇒ Object


Configuration loading / saving



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
185
# File 'lib/core/plugin/configuration.rb', line 160

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
43
# 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,
    :external_ip   => _delete(:external_ip, nil),
    :internal_ip   => _delete(: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



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

def project
  @project
end

#remote(name) ⇒ Object




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

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

#remove(options = {}) ⇒ Object




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

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




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

def remove_plugin
  CORL.remove_plugin(@project)
end

#save(options = {}) ⇒ Object




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

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




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

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

#set_location(directory) ⇒ Object




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

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




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

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