Sha256: 1dacefa4c4c5ece0212ae01494494d47f9cc29e87d9355704a175bee07414b6e

Contents?: true

Size: 1002 Bytes

Versions: 1

Compression:

Stored size: 1002 Bytes

Contents

module Finix
  module HalResource

    attr_accessor :hyperlinks
    attr_accessor :attributes

    def method_missing(method, *args, &block)
      if @attributes.has_key?(method.to_s)
        return @attributes[method.to_s]
      end

      case method.to_s
        when /(.+)=$/
          attr = method.to_s.chop
          @attributes[attr] = args[0]
        else
          if @hyperlinks.has_key? "#{method}"
            value = @hyperlinks["#{method}"]
            result = value.call
            return result
          end
      end
    end

    if RUBY_VERSION < '1.9'
      def respond_to?(method_name, include_private=false)
        does_resource_respond_to?(method_name) || super
      end
    else
      def respond_to_missing?(method_name, include_private=false)
        does_resource_respond_to?(method_name) || super
      end
    end

    def does_resource_respond_to?(method_name)
      @attributes.has_key?(method_name.to_s) or @hyperlinks.has_key?(method_name.to_s)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
finix-0.2 lib/finix/hal_resource.rb