Sha256: 2ec1e7e528831d97760ce3b5461d3b5e8f492c4bda6ca4db9c5f30961ed4bb6c

Contents?: true

Size: 1.2 KB

Versions: 57

Compression:

Stored size: 1.2 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!
      if ENV[EXPORT_KEY]
        @params = JSON.parse(ENV[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

57 entries across 57 versions & 1 rubygems

Version Path
henry-container-0.1.44 lib/henry/input.rb
henry-container-0.1.43 lib/henry/input.rb
henry-container-0.1.42 lib/henry/input.rb
henry-container-0.1.41 lib/henry/input.rb
henry-container-0.1.40 lib/henry/input.rb
henry-container-0.1.39 lib/henry/input.rb
henry-container-0.1.38 lib/henry/input.rb
henry-container-0.1.36 lib/henry/input.rb
henry-container-0.1.34 lib/henry/input.rb
henry-container-0.1.33 lib/henry/input.rb
henry-container-0.1.31 lib/henry/input.rb
henry-container-0.1.30 lib/henry/input.rb
henry-container-0.1.29 lib/henry/input.rb
henry-container-0.1.28 lib/henry/input.rb
henry-container-0.1.27 lib/henry/input.rb
henry-container-0.1.26 lib/henry/input.rb
henry-container-0.1.24 lib/henry/input.rb
henry-container-0.1.23 lib/henry/input.rb
henry-container-0.1.22 lib/henry/input.rb
henry-container-0.1.20 lib/henry/input.rb