Sha256: 8bbce190c1d38870be2725a0930f4256443d39c4f3c686deb3bbc98a260f74c8

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

require_relative File.join '..', 'type'

# Namespace for the Opushon library.
module Opushon
  module Parameter
    # Abstract class.
    class Base
      def self.load(input_or_output_params)
        if input_or_output_params.nil?
          @input_or_output_params = nil
        else
          @input_or_output_params = {}

          input_or_output_params.each do |key, properties|
            properties_sym = JSON.parse(properties.to_json, symbolize_names: true)
            @input_or_output_params.update key.to_sym => new(properties_sym).to_h
          end
        end

        @input_or_output_params
      end

      def initialize( title:              '',
                      description:        '',
                      nullifiable:        true,
                      type:               'string', **type_properties )

        @title        = title.to_s
        @description  = description.to_s
        @nullifiable  = nullifiable
        @type         = Type.const_get(type.capitalize).new(type_properties)

        freeze
      end

      # Dump attribute's properties to a hash.
      def to_h
        {
          title:        @title,
          description:  @description,
          nullifiable:  @nullifiable,
          type:         @type.to_sym
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
opushon-0.1.1 lib/opushon/parameter/base.rb
opushon-0.1.0 lib/opushon/parameter/base.rb