Sha256: 58201126a3f72b6d843344b4e747049c2fb7b9cf77d9212b87f54fab7f08bf51

Contents?: true

Size: 1.68 KB

Versions: 16

Compression:

Stored size: 1.68 KB

Contents

require 'contracts'
require 'java-properties'

require_relative '../config'
require_relative '../seed_properties'

module Cloudstrap
  module HDP
    class BootstrapProperties
      include ::Contracts::Core
      include ::Contracts::Builtin

      Contract None => Hash
      def properties
        @properties ||= load!
      end

      Contract RespondTo[:to_sym], String => BootstrapProperties
      def update!(property, value)
        update(property, value).tap do
          save!
        end
      end

      Contract RespondTo[:to_sym], String => BootstrapProperties
      def update(property, value)
        raise KeyError unless properties.has_key? property.to_sym

        properties.store property.to_sym, value

        self
      end

      Contract RespondTo[:to_sym], String => BootstrapProperties
      def define(property, value)
        properties.store property.to_sym, value
        self
      end

      Contract None => Bool
      def save!
        JavaProperties.write(properties, file) ? true : false
      end

      Contract None => String
      def file
        @file ||= [config.hdp_dir, 'bootstrap.properties'].join('/')
      end

      private

      Contract None => SeedProperties
      def seed
        @seed ||= SeedProperties.new
      end

      Contract None => Bool
      def exist?
        File.exist?(file)
      end

      Contract None => Hash
      def load
        if exist?
          JavaProperties.load file
        else
          JavaProperties.parse ''
        end
      end

      Contract None => Hash
      def load!
        @properties = load
      end

      Contract None => Config
      def config
        @config ||= Config.new
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
cloudstrap-0.41.4.pre lib/cloudstrap/hdp/bootstrap_properties.rb
cloudstrap-0.41.0.pre lib/cloudstrap/hdp/bootstrap_properties.rb
cloudstrap-0.40.6.pre lib/cloudstrap/hdp/bootstrap_properties.rb
cloudstrap-0.40.5.pre lib/cloudstrap/hdp/bootstrap_properties.rb
cloudstrap-0.40.4.pre lib/cloudstrap/hdp/bootstrap_properties.rb
cloudstrap-0.40.3.pre lib/cloudstrap/hdp/bootstrap_properties.rb
cloudstrap-0.40.1.pre lib/cloudstrap/hdp/bootstrap_properties.rb
cloudstrap-0.40.0.pre lib/cloudstrap/hdp/bootstrap_properties.rb
cloudstrap-0.39.0.pre lib/cloudstrap/hdp/bootstrap_properties.rb
cloudstrap-0.38.18.pre lib/cloudstrap/hdp/bootstrap_properties.rb
cloudstrap-0.38.17.pre lib/cloudstrap/hdp/bootstrap_properties.rb
cloudstrap-0.38.5.pre lib/cloudstrap/hdp/bootstrap_properties.rb
cloudstrap-0.38.3.pre lib/cloudstrap/hdp/bootstrap_properties.rb
cloudstrap-0.38.2.pre lib/cloudstrap/hdp/bootstrap_properties.rb
cloudstrap-0.38.1.pre lib/cloudstrap/hdp/bootstrap_properties.rb
cloudstrap-0.38.0.pre lib/cloudstrap/hdp/bootstrap_properties.rb