Class: Coral::Plugin::Base

Inherits:
Core show all
Defined in:
lib/coral_core/plugin_base.rb

Direct Known Subclasses

Command, Machine, Network, Node

Instance Attribute Summary

Attributes inherited from Core

#ui

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core

#inspect, logger, #logger, logger=, ui

Methods inherited from Config

#[], #[]=, array, #array, #clear, #defaults, #delete, ensure, #export, filter, #filter, #get, #get_array, #get_hash, #hash, hash, #import, #init, init, init_flat, #set, string, #string, #string_map, string_map, symbol, #symbol, #symbol_map, symbol_map, test, #test

Methods included from Mixin::ConfigOptions

#clear_options, #contexts, #get_options, #set_options

Methods included from Mixin::ConfigCollection

#all_properties, #clear_properties, #delete_property, #get_property, #save_properties, #set_property

Methods included from Mixin::Lookup

#hiera, #hiera_config, #lookup, #lookup_array, #lookup_hash

Methods included from Mixin::ConfigOps

#parse

Constructor Details

#initialize(type, provider, options) ⇒ Base

All Plugin classes should directly or indirectly extend Base



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/coral_core/plugin_base.rb', line 7

def initialize(type, provider, options)
  config = Config.ensure(options)
  name   = Util::Data.ensure_value(config.delete(:name), provider)
  
  set_meta(config.delete(:meta, Config.new))
  
  super(config)
  
  self.name = name
  
  normalize
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object




28
29
30
# File 'lib/coral_core/plugin_base.rb', line 28

def method_missing(method, *args, &block)  
  return nil  
end

Class Method Details

.build_info(type, data) ⇒ Object


Utilities



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/coral_core/plugin_base.rb', line 108

def self.build_info(type, data)  
  plugins = []
  
  if data.is_a?(Hash)
    data = [ data ]
  end
  
  if data.is_a?(Array)
    data.each do |info|
      unless Util::Data.empty?(info)
        info = translate(info)
        
        if Util::Data.empty?(info[:provider])
          info[:provider] = Plugin.type_default(type)
        end
        
        plugins << info
      end
    end
  end
  return plugins
end

.ensure_plugin_collectionObject




139
140
141
142
143
144
# File 'lib/coral_core/plugin_base.rb', line 139

def self.ensure_plugin_collection
  include Mixin::Settings
  include Mixin::SubConfig
  
  extend Mixin::Macro::PluginInterface
end

.translate(data) ⇒ Object




133
134
135
# File 'lib/coral_core/plugin_base.rb', line 133

def self.translate(data)
  return ( data.is_a?(Hash) ? symbol_map(data) : {} )
end

Instance Method Details

#initialized?(options = {}) ⇒ Boolean


Returns:

  • (Boolean)


22
23
24
# File 'lib/coral_core/plugin_base.rb', line 22

def initialized?(options = {})
  return true  
end

#metaObject




47
48
49
# File 'lib/coral_core/plugin_base.rb', line 47

def meta
  return @meta
end

#nameObject


Property accessor / modifiers



35
36
37
# File 'lib/coral_core/plugin_base.rb', line 35

def name
  return get(:name)
end

#name=(name) ⇒ Object




41
42
43
# File 'lib/coral_core/plugin_base.rb', line 41

def name=name
  set(:name, string(name))
end

#normalizeObject


Plugin operations



102
103
# File 'lib/coral_core/plugin_base.rb', line 102

def normalize
end

#plugin_directoryObject




71
72
73
# File 'lib/coral_core/plugin_base.rb', line 71

def plugin_directory
  return meta.get(:directory)
end

#plugin_fileObject




77
78
79
# File 'lib/coral_core/plugin_base.rb', line 77

def plugin_file
  return meta.get(:file)
end

#plugin_instance_nameObject




83
84
85
# File 'lib/coral_core/plugin_base.rb', line 83

def plugin_instance_name
  return meta.get(:instance_name)
end

#plugin_parentObject




95
96
97
# File 'lib/coral_core/plugin_base.rb', line 95

def plugin_parent
  return meta.get(:parent)
end

#plugin_parent=(parent) ⇒ Object




89
90
91
# File 'lib/coral_core/plugin_base.rb', line 89

def plugin_parent=parent
  meta.set(:parent, parent) if parent.is_a?(Coral::Plugin::Base)
end

#plugin_providerObject




65
66
67
# File 'lib/coral_core/plugin_base.rb', line 65

def plugin_provider
  return meta.get(:provider)
end

#plugin_typeObject




59
60
61
# File 'lib/coral_core/plugin_base.rb', line 59

def plugin_type
  return meta.get(:type)
end

#set_meta(meta) ⇒ Object




53
54
55
# File 'lib/coral_core/plugin_base.rb', line 53

def set_meta(meta)
  @meta = Config.ensure(meta)
end