Sha256: 23890d501cb80c016166c74032ec159d5588027d39dd38817bd7b605e02f6ae2

Contents?: true

Size: 797 Bytes

Versions: 1

Compression:

Stored size: 797 Bytes

Contents

module Concerns
  module Storable
    class Config
      attr_reader :fields

      KLASSES = {
        array: [Array],
        boolean: [TrueClass, FalseClass],
        date: [Date],
        date_time: [DateTime],
        float: [Float],
        integer: [Fixnum],
        string: [String]
      }

      def initialize
        @fields = {}
      end

      def add(field, klass, default = nil)
        raise "#{klass} is not a valid storable config klass" unless valid_klass?(klass)

        @fields[field.to_sym] = {
          klass: klass.to_sym,
          default: default
        }
      end

      def allowed?(field)
        @fields.keys.include?(field.to_sym)
      end

      private

      def valid_klass?(value)
        KLASSES.keys.include?(value.to_sym)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
udongo-0.1.0 app/models/concerns/storable/config.rb