Sha256: 7639215d647ea40c606c9d39eb4da4a092b07cbb439e4f250e0d666aa3e7216a

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

module Henry

  # Henry Input
  class Input
    attr_reader :params

    # ENV key where the Input will be exported to/imported from.
    EXPORT_KEY = 'HENRY_INPUT'

    # 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[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!
      @params = JSON.parse(ENV[EXPORT_KEY])
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
henry-container-0.0.36 lib/henry/input.rb
henry-container-0.0.35 lib/henry/input.rb