Sha256: 35821034bb2b7eca6f01def8c9d300236c6101e88d532b02c77924526fc1be6c

Contents?: true

Size: 856 Bytes

Versions: 1

Compression:

Stored size: 856 Bytes

Contents

require 'pinnacle/error'
require 'pinnacle/version'

module Pinnacle
  module_function

  class DatumModel
    attr_accessor :attrs
    alias :to_hash :attrs

    # Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
    #
    # @overload self.lazy_attr_reader(attr)
    #   @param attr [Symbol]
    # @overload self.lazy_attr_reader(attrs)
    #   @param attrs [Array<Symbol>]
    def self.lazy_attr_reader(*attrs)
      attrs.each do |attribute|
        class_eval do
          define_method attribute do
            @attrs[attribute.to_s] || @attrs[attribute.to_sym]
          end
        end
      end
    end

    # Initializes a new Base object
    #
    # @param attrs [Hash]
    # @return [DatumModel]
    def initialize(attrs={})
      @attrs = attrs.dup
    end
  end
end

require 'api'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pinnacle-0.0.1 lib/pinnacle.rb