Module: Liquor::External

Included in:
Builtins::ForLoop, Drop, Drop::Scope, Pagination::PageExternal, Rails::Request
Defined in:
lib/liquor/external.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/liquor/external.rb', line 38

def self.included(klass)
  klass.instance_exec do
    class << self
      attr_reader :liquor_exports
      attr_reader :liquor_deprecations
    end

    @liquor_exports      = Set[]
    @liquor_deprecations = {}

    extend ClassMethods
  end
end

Instance Method Details

#liquor_send(method, args, loc = nil) ⇒ Object


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/liquor/external.rb', line 52

def liquor_send(method, args, loc=nil)
  method = method.to_sym

  if self.class.liquor_exports.include?(method)
    if (deprecation = self.class.liquor_deprecations[method])
      Liquor::Runtime.deprecation(
          "`#{method}' is deprecated and will be removed after " <<
          "#{deprecation[:date]}: #{deprecation[:message]}", loc)
    end

    begin
      send method, *args
    rescue ::Liquor::Diagnostic => e
      raise e
    rescue ::Exception => e
      # First, remove the caller backtrace at the following line.
      # This will not include the line in liquor_send which will
      # be in the host exception backtrace. Second, remove that one.
      host_backtrace = (e.backtrace - caller)[0..-2]

      raise HostError.new(nil, e, host_backtrace, loc)
    end
  else
    raise ArgumentError.new("undefined external method #{method} for #{self.class}", loc)
  end
end