Sha256: affb89856a22c61a05db7e82f57b2c8fd932bdb32bbbe208b18ba53f70e77b68

Contents?: true

Size: 589 Bytes

Versions: 3

Compression:

Stored size: 589 Bytes

Contents

require "espago/api_connection"

module Espago
  class Router
    attr_accessor :path,  :method
    NoPathError = Class.new(StandardError)

    def initialize(path, method)
      @path, @method = path, method
    end

    def route
      raise NoPathError unless path_exists?
      get_route
    end

    def path_exists?
      get_route
      true
    rescue
      false
    end

    private
    def get_route
      Espago::ApiConnection.const_get get_class_name
    end

    def get_class_name
      method.to_s.capitalize + path.to_s.split("_").map(&:capitalize).join
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
espago-0.0.9 lib/espago/router.rb
espago-0.0.7 lib/espago/router.rb
espago-0.0.6 lib/espago/router.rb