module Sinatra::EasyBreadcrumbs

Constants

Configuration
EXCLUDED_VARS

Public Instance Methods

easy_breadcrumbs() click to toggle source
# File lib/easy_breadcrumbs.rb, line 11
def easy_breadcrumbs
  breadcrumb = Breadcrumbs.new(config)
  breadcrumb.to_html
end

Private Instance Methods

additional_var?(var) click to toggle source

Ignore pre-existing Sinatra instance variables.

# File lib/easy_breadcrumbs.rb, line 53
def additional_var?(var)
  !EXCLUDED_VARS.include?(var)
end
config() click to toggle source
# File lib/easy_breadcrumbs.rb, line 24
def config
  # The name of the current Sinatra Application
  app = self.class

  # The Rack::Request object
  request_path = request.path

  # All defined GET request routes
  route_matchers = app.routes['GET'].map { |route| route[0] }

  Configuration.new(request_path, route_matchers, view_variables)
end
fetch_ivar_value(var) click to toggle source

Walk through all instance variables and fetch value.

# File lib/easy_breadcrumbs.rb, line 45
def fetch_ivar_value(var)
  name = var.to_s.delete('@').to_sym
  value = instance_eval(var.to_s)

  { name: name, value: value }
end
view_variables() click to toggle source

All user defined instance variables for current request.

# File lib/easy_breadcrumbs.rb, line 38
def view_variables
  instance_variables
    .select { |var| additional_var?(var) }
    .map { |var| fetch_ivar_value(var) }
end