Sha256: 1dd1d1dd3dfaed7e91453b084dde774499317e78995841b49df7fb8f4e8a3c35

Contents?: true

Size: 1.46 KB

Versions: 36

Compression:

Stored size: 1.46 KB

Contents

module Henry

  # Henry Input
  class Input
    attr_reader :params

    # ENV key where the Config will be exported to/imported from.
    #
    # @return [String] the env config key.
    EXPORT_KEY = 'HENRY_INPUT'
    
    # ENV key where the Config will be exported to/imported from.
    #
    # @return [String] the env config key.
    def self.export_key
      Henry::Input::EXPORT_KEY 
    end

    # Initialize the Input with the given params  or empty.
    #
    # @param params [Hash] the Input params.
    def initialize(params={})
      @params = params
    end
   
    # Initialize and export the Input to the target ENV namespace.
    #
    # @param params [Hash] the Input params to be exported.
    # @return [Input]
    def self.export!(params)
      self.new(params).export!
    end

    # Exports the Input to the target ENV namespace.
    #
    # @return [Input]
    def export!
      ENV[self.class.export_key] = JSON.dump(@params)
      self
    end

    # Initialize and import the Input from the target ENV namespece.
    #
    # @return [Input]
    def self.import!
      self.new.import!
    end
  
    # Imports the Input from the target ENV  namespace.
    #
    # @return [Input]
    def import!
      if ENV[self.class.export_key]
        @params = JSON.parse(ENV[self.class.export_key])
      else
        warn("Could not load the execution params.\nAre you running this Task via the henry-ruby-container? You should!".red)
      end

      self
    end

  end

end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
henry-container-0.1.82 lib/henry/input.rb
henry-container-0.1.81 lib/henry/input.rb
henry-container-0.1.80 lib/henry/input.rb
henry-container-0.1.79 lib/henry/input.rb
henry-container-0.1.78 lib/henry/input.rb
henry-container-0.1.77 lib/henry/input.rb
henry-container-0.1.76 lib/henry/input.rb
henry-container-0.1.75 lib/henry/input.rb
henry-container-0.1.74 lib/henry/input.rb
henry-container-0.1.73 lib/henry/input.rb
henry-container-0.1.72 lib/henry/input.rb
henry-container-0.1.71 lib/henry/input.rb
henry-container-0.1.70 lib/henry/input.rb
henry-container-0.1.69 lib/henry/input.rb
henry-container-0.1.68 lib/henry/input.rb
henry-container-0.1.67 lib/henry/input.rb
henry-container-0.1.66 lib/henry/input.rb
henry-container-0.1.65 lib/henry/input.rb
henry-container-0.1.64 lib/henry/input.rb
henry-container-0.1.63 lib/henry/input.rb