module RestUri::Resource
Public Class Methods
resource_id(name, object, parser: DEFAULT_PARSER)
click to toggle source
Take a URI string or URI object and return its ID @example
RestUri::Resource.resource_id('status', https://twitter.com/sferik/status/540897316908331009/') #=> 540897316908331009
@param name [String] Resource
name @param object [Integer, String, URI] An ID, URI, or object. @param @option parser [Integer, String, URI] An ID, URI, or object. @return [Integer, NilClass]
# File lib/rest_uri/resource.rb, line 14 def self.resource_id(name, object, parser: DEFAULT_PARSER) return nil if not name.respond_to? :empty? or name.empty? case object when ::Integer object when ::String resource_id(name, parser.parse(object), parser: parser) when parser resource_id(name, Uri.hashbang_path_or_path(object).split('/')) when Enumerable Uri.find_resource_id(object) {|s| /\A(?:#{name.underscore.singularize}|#{name.underscore.pluralize})\z/ === s } else nil end end
Public Instance Methods
method_missing(name, *args)
click to toggle source
Calls superclass method
# File lib/rest_uri/resource.rb, line 36 def method_missing(name, *args) super unless name.to_s.end_with? @identifier.to_s resource(name[0...-@identifier.to_s.size]) end
resource(name)
click to toggle source
# File lib/rest_uri/resource.rb, line 32 def resource(name) Resource.resource_id(name, @uri, parser: @parser) end