Sha256: d329c311b6f19304a218534359f7791044eede3a3959ca5c72f0e63e2808415c

Contents?: true

Size: 785 Bytes

Versions: 11

Compression:

Stored size: 785 Bytes

Contents

class Lbrt::Service::DSL::Converter
  def self.convert(exported, options = {})
    self.new(exported, options).convert
  end

  def initialize(exported, options = {})
    @exported = exported
    @options = options
  end

  def convert
    output_services(@exported)
  end

  private

  def output_services(service_by_key)
    services = []

    service_by_key.sort_by(&:first).map do |key, attrs|
      next unless key.any? {|i| Lbrt::Utils.matched?(i, @options[:target]) }
      services << output_service(key, attrs)
    end

    services.join("\n")
  end

  def output_service(key, attrs)
    type, title = key
    settings = attrs.fetch('settings')

    <<-EOS
service #{type.inspect}, #{title.inspect} do
  settings #{Lbrt::Utils.unbrace(settings.inspect)}
end
    EOS
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
lbrt-0.2.1 lib/lbrt/service/dsl/converter.rb
lbrt-0.2.0 lib/lbrt/service/dsl/converter.rb
lbrt-0.1.9 lib/lbrt/service/dsl/converter.rb
lbrt-0.1.8 lib/lbrt/service/dsl/converter.rb
lbrt-0.1.7 lib/lbrt/service/dsl/converter.rb
lbrt-0.1.6 lib/lbrt/service/dsl/converter.rb
lbrt-0.1.5 lib/lbrt/service/dsl/converter.rb
lbrt-0.1.4 lib/lbrt/service/dsl/converter.rb
lbrt-0.1.3 lib/lbrt/service/dsl/converter.rb
lbrt-0.1.1 lib/lbrt/service/dsl/converter.rb
lbrt-0.1.0 lib/lbrt/service/dsl/converter.rb