Sha256: 3891f4bcd732eac580bcee50e21678fa8997d1c0ef4f7b9acc5e68a4753fa65d

Contents?: true

Size: 759 Bytes

Versions: 2

Compression:

Stored size: 759 Bytes

Contents

require 'forwardable'

module Typekit
  module Record
    class Base
      extend Forwardable

      attr_reader :attributes
      def_delegator :attributes, :to_json

      def initialize(attributes = {})
        @attributes = Hash[attributes.map { |k, v| [ k.to_sym, v ] }]
      end

      def method_missing(name, *arguments)
        if name.to_s =~ /^(?<name>.*)=$/
          name = Regexp.last_match(:name).to_sym
          return super unless arguments.length == 1
          return super unless @attributes.key?(name)
          @attributes[name] = arguments.first
        else
          return super unless arguments.length.zero?
          return super unless @attributes.key?(name)
          @attributes[name]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
typekit-client-0.0.4 lib/typekit/record/base.rb
typekit-client-0.0.3 lib/typekit/record/base.rb