module Fragments

Top level module for the Fragments library

This module should be considered as a Facade, so some internal functionality should not be used from the outside. So, use an API, which is provided by this module instead!

Constants

VERSION

Public Class Methods

config() { |config| ... } click to toggle source

Get or set a configuration for the library

# File lib/fragments.rb, line 13
def self.config(&block)
  @config ||= ::Fragments::Config.new
  block_given? ? yield(@config) : @config
end
enabled?() click to toggle source

Specifies either should fragments be used or not

@return [Boolean] - a value which specifies enableness

# File lib/fragments.rb, line 21
def self.enabled?
  config.is_enabled
end
get_html(code, request) click to toggle source

Provides a html structure for a fragment with a specified code

@param code [String] - a code of a fragment which you want to request @param request [Request] - a reference to an object which represents an income HTTP request @return [String] a html structure of a needed fragment

# File lib/fragments.rb, line 30
def self.get_html(code, request)
  ::Fragments::Requester.call(
    fragment_code: code,
    current_host: ::Fragments.config.host,
    cookies: request.headers["HTTP_COOKIE"],
    current_url: request.original_url
  )
rescue Exception => e
  ""
end