Sha256: cc40227c591546072855091586e0e20cd903912c3f859bf1f508e8d223ae1dd9

Contents?: true

Size: 1.38 KB

Versions: 24

Compression:

Stored size: 1.38 KB

Contents

require 'ceedling/plugin'

class PluginBuilder

  attr_accessor :plugin_objects

  def construct_plugin(plugin_name, object_map_yaml, system_objects)
    # @streaminator.stdout_puts("Constructing plugin #{plugin_name}...", Verbosity::OBNOXIOUS)
    object_map = {}
    @plugin_objects = {}
    @system_objects = system_objects

    if object_map_yaml
      @object_map = YAML.load(object_map_yaml)
      @object_map.each_key do |obj|
        construct_object(obj)
      end
    else
      raise "Invalid object map for plugin #{plugin_name}!"
    end

    return @plugin_objects
  end

  private
  
  def camelize(underscored_name)
    return underscored_name.gsub(/(_|^)([a-z0-9])/) {$2.upcase}
  end

  def construct_object(obj)
    if @plugin_objects[obj].nil?
      if @object_map[obj] && @object_map[obj]['compose']
        @object_map[obj]['compose'].each do |dep|
          construct_object(dep)
        end
      end
      build_object(obj)
    end
  end

  def build_object(new_object)
    if @plugin_objects[new_object.to_sym].nil?
      # @streaminator.stdout_puts("Building plugin object #{new_object}", Verbosity::OBNOXIOUS)
      require new_object
      class_name = camelize(new_object)
      new_instance = eval("#{class_name}.new(@system_objects, class_name.to_s)")
      new_instance.plugin_objects = @plugin_objects
      @plugin_objects[new_object.to_sym] = new_instance
    end
  end

end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ceedling-0.31.1 lib/ceedling/plugin_builder.rb
ceedling-0.31.0 lib/ceedling/plugin_builder.rb
ceedling-0.30.0 lib/ceedling/plugin_builder.rb
ceedling-0.28.3 lib/ceedling/plugin_builder.rb
ceedling-0.28.2 lib/ceedling/plugin_builder.rb
ceedling-0.28.1 lib/ceedling/plugin_builder.rb
ceedling-0.27.0 lib/ceedling/plugin_builder.rb
ceedling-0.25.0 lib/ceedling/plugin_builder.rb
ceedling-0.24.0 lib/ceedling/plugin_builder.rb
ceedling-0.22.0 lib/ceedling/plugin_builder.rb
ceedling-0.21.0 lib/ceedling/plugin_builder.rb
ceedling-0.20.3 lib/ceedling/plugin_builder.rb
ceedling-0.20.2 lib/ceedling/plugin_builder.rb
ceedling-0.19.0 lib/ceedling/plugin_builder.rb
ceedling-0.18.0 lib/ceedling/plugin_builder.rb
ceedling-0.17.0 lib/ceedling/plugin_builder.rb
ceedling-0.16.0 lib/ceedling/plugin_builder.rb
ceedling-0.15.6 lib/ceedling/plugin_builder.rb
ceedling-0.15.5 lib/ceedling/plugin_builder.rb
ceedling-0.15.4 lib/ceedling/plugin_builder.rb