class Catlass::Converter

Public Instance Methods

convert_attributes(hash) click to toggle source
# File lib/catlass/converter.rb, line 59
def convert_attributes(hash)
  hash.delete('id')
  hash['attributes'].delete('name')
  hash['attributes'].delete('created_at')
  hash['attributes'].delete('updated_at')
  hash['attributes']['rule_value'].delete('next_occurrence')
  if hash['attributes']['rule_value']['weekly_schedule'].is_a?(String)
   hash['attributes']['rule_value']['weekly_schedule'] = eval(hash['attributes']['rule_value']['weekly_schedule'])
  end
  hash
end
dslfile_to_h(dsl_file) click to toggle source
# File lib/catlass/converter.rb, line 50
def dslfile_to_h(dsl_file)
  context = DSLContext.new
  context.eval_dsl(dsl_file)
end
filename(name) click to toggle source
# File lib/catlass/converter.rb, line 55
def filename(name)
  name.gsub!(/\W+/, '_')
end
set_options(options) click to toggle source
# File lib/catlass/converter.rb, line 6
def set_options(options)
  @options = options
end
to_dsl(job) click to toggle source
# File lib/catlass/converter.rb, line 18
    def to_dsl(job)
      exclude_key = proc do |k|
        false
      end

      key_conv = proc do |k|
        k = k.to_s
        if k !~ /\A[_a-z]\w+\Z/i
          "_(#{k.inspect})"
        else
          k
        end

      end

      name = job['attributes']['name']
      hash = convert_attributes(job)

      dsl = Dslh.deval(
        hash,
        exclude_key: exclude_key,
        use_heredoc_for_multi_line: true,
        key_conv: key_conv,
        initial_depth: 1
      )
<<-EOS
Job #{name.inspect} do
#{dsl}
end
EOS
    end
to_dsl_all(docs) click to toggle source
# File lib/catlass/converter.rb, line 10
def to_dsl_all(docs)
  dsls = []
  docs.each do |doc|
    dsls << to_dsl(doc)
  end
  dsls.join("\n")
end