Sha256: 8daae1f5090f7d1f3a443c7a00a0c9ea20d70313df74c5bd9a912385cfc25649

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

module Restfulie::Client::HTTP#:nodoc:
  
  # Offers a way to access Atom entries element's in namespaced extensions.
  module AtomElementShortcut
    def method_missing(method_sym,*args)
      return super(method_sym, *args) unless simple_extensions
      
      found = find_extension_entry_for(method_sym)
      return super(method_sym, *args) if found.empty?
      result = found.collect do |pair|
        pair.last.length==1 ? pair.last.first : pair.last
      end
      result.length==1 ? result.first : result
    end
    
    def respond_to?(method_sym)
      return super(method_sym) unless simple_extensions

      found = find_extension_entry_for(method_sym)
      (found.length!=0) || super(method_sym)
    end
    
    private
    def find_extension_entry_for(method_sym)
      start = -(method_sym.to_s.length + 1)
      found = simple_extensions.select do |k, v|
        method_sym.to_s == k[start..-2]
      end
    end
  end
  
  # Offers a way to access Atom entries element's in namespaced extensions.
  module AtomElementShortcut
    def method_missing(method_sym,*args)
      return super(method_sym, *args) unless simple_extensions
      
      start = -(method_sym.to_s.length + 1)
      found = simple_extensions.select do |k, v|
        method_sym.to_s == k[start..-2]
      end
      return super(method_sym, *args) if found.empty?
      result = found.collect do |pair|
        pair.last.length==1 ? pair.last.first : pair.last
      end
      result.length==1 ? result.first : result
    end
  end

  # inject new behavior in rAtom instances to enable easily access to link relationships.
  ::Atom::Feed.instance_eval {
    include Restfulie::Client::LinkShortcut
    include AtomElementShortcut
  }
  ::Atom::Entry.instance_eval {
    include Restfulie::Client::LinkShortcut
    include AtomElementShortcut
  }
  ::Atom::Link.instance_eval {
    include Restfulie::Client::HTTP::LinkRequestBuilder
  }
  
end


class Atom::Link
  def content_type
    type
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
restfulie-0.7.2 lib/restfulie/client/http/atom_ext.rb
restfulie-0.7.1 lib/restfulie/client/http/atom_ext.rb