Sha256: 7950ce3a54a779299c4b43c5d72296c8db1ca64fd4c2a1a8cc61161967ef1beb

Contents?: true

Size: 671 Bytes

Versions: 43

Compression:

Stored size: 671 Bytes

Contents

require "json"
require "erb"
require "fileutils"

class ChefDnaParser

  class << self
    attr_accessor :dna, :parsed, :file_path, :test_dna
    
    def test_dna=(json)
      @test_dna = json
    end
    
    def load_dna
      @parsed ||= {}
      @dna ||= ""
      if @test_dna
        @dna = ERB.new(@test_dna).result(binding)
      else
        @file_path = ENV["DNA"] || ENV["dna"] || default_dna_path
        
        @dna = ERB.new(File.read(file_path)).result(binding)
      end
      @parsed = JSON.parse(@dna)
    end

    def default_dna_path
      File.join(rails_root, "chef", "node.json")
    end

    def rails_root
      FileUtils.pwd
    end
  end

end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
chef_cap-0.3.23 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.22 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.21 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.20 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.19 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.18 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.17 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.16 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.15 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.14 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.13 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.12 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.11 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.10 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.9 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.8 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.7 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.6 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.5 recipes/lib/chef_dna_parser.rb
chef_cap-0.3.4 recipes/lib/chef_dna_parser.rb