Sha256: 62542227e10bb6c46b0dd83ea9c007e945b941b9e5b833a1388d22866f8e5c30

Contents?: true

Size: 769 Bytes

Versions: 3

Compression:

Stored size: 769 Bytes

Contents

require 'forwardable'

module Mumble
  class Model
    extend ::Forwardable

    class << self
      def attribute(name, &block)
        attributes << name
        define_method(name) do
          if block_given?
            self.instance_eval(&block)
          else
            @data[name.to_s]
          end
        end
      end

      def attributes
        @attributes ||= []
      end
    end

    def initialize(client, data)
      @client = client
      @data   = data
    end

    def update(data)
      @data.merge!(data)
    end

    def inspect
      attrs = self.class.attributes.map do |attr|
        [attr, send(attr)].join("=")
      end.join(" ")
      %Q{#<#{self.class.name} #{attrs}>}
    end

    protected
    attr_reader :data, :client
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
mumble-ruby2-1.1.4 lib/mumble-ruby2/model.rb
mumble-ruby-1.1.3 lib/mumble-ruby/model.rb
mumble-ruby-1.1.2 lib/mumble-ruby/model.rb