Module: Musashi::Resource::JSON

Includes:
Format
Defined in:
lib/musashi/resource.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Format

formats, #retrieve

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/musashi/resource.rb', line 39

def method_missing(sym,*args,&block)
  super 
rescue NoMethodError => error
  raise error unless retrieved?
  raise NoMethodError.new(sym) unless respond_to?(:link)
  selected = self.link.select{|l| l.rel == sym.to_s}
  raise NoMethodError.new(sym) if selected.nil? or selected.empty?
  raise "More than one result for #{sym} #{selected.join(',')}" if selected.size > 1
  selected.first.href
end

Class Method Details

.included(clazz) ⇒ Object



22
23
24
25
26
# File 'lib/musashi/resource.rb', line 22

def self.included(clazz)
  super
  clazz.extend ClassMethods
  clazz.send :include, InstanceMethods
end