Switch from ActiveSupports delegate method to Ruby 1.9+ def_delegator
This commit is contained in:
parent
3a19cc668d
commit
336b80cbbd
|
@ -33,6 +33,8 @@ require 'middleman-core/core_extensions/extensions'
|
|||
# Core Middleman Class
|
||||
module Middleman
|
||||
class Application
|
||||
extend Forwardable
|
||||
|
||||
# Global configuration
|
||||
include Configuration::Global
|
||||
|
||||
|
@ -57,13 +59,13 @@ module Middleman
|
|||
def self.root
|
||||
ENV['MM_ROOT'] || Dir.pwd
|
||||
end
|
||||
delegate :root, to: :"self.class"
|
||||
def_delegator :"self.class", :root
|
||||
|
||||
# Pathname-addressed root
|
||||
def self.root_path
|
||||
Pathname(root)
|
||||
end
|
||||
delegate :root_path, to: :"self.class"
|
||||
def_delegator :"self.class", :root_path
|
||||
|
||||
# Name of the source directory
|
||||
# @return [String]
|
||||
|
@ -180,7 +182,7 @@ module Middleman
|
|||
attr_reader :template_context_class
|
||||
|
||||
attr_reader :generic_template_context
|
||||
delegate :link_to, :image_tag, :asset_path, to: :generic_template_context
|
||||
def_delegators :@generic_template_context, :link_to, :image_tag, :asset_path
|
||||
|
||||
# Initialize the Middleman project
|
||||
def initialize
|
||||
|
@ -242,7 +244,7 @@ module Middleman
|
|||
File.join(root, config[:source])
|
||||
end
|
||||
|
||||
delegate :instrument, to: ::Middleman::Util
|
||||
def_delegator ::Middleman::Util, :instrument
|
||||
|
||||
# Work around this bug: http://bugs.ruby-lang.org/issues/4521
|
||||
# where Ruby will call to_s/inspect while printing exception
|
||||
|
@ -256,8 +258,6 @@ module Middleman
|
|||
# Hooks clones _hooks from the class to the instance.
|
||||
# https://github.com/apotonick/hooks/blob/master/lib/hooks/instance_hooks.rb#L10
|
||||
# Middleman expects the same list of hooks for class and instance hooks:
|
||||
def _hooks
|
||||
self.class._hooks
|
||||
end
|
||||
def_delegator :"self.class", :_hooks
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
module Middleman
|
||||
class ConfigContext
|
||||
extend Forwardable
|
||||
|
||||
attr_reader :app
|
||||
|
||||
# Whitelist methods that can reach out.
|
||||
delegate :config, :logger, :activate, :use, :map, :mime_type, :data, :files, :root, to: :app
|
||||
def_delegators :@app, :config, :logger, :activate, :use, :map, :mime_type, :data, :files, :root
|
||||
|
||||
def initialize(app, template_context_class)
|
||||
@app = app
|
||||
|
|
|
@ -5,7 +5,7 @@ module Middleman
|
|||
module Global
|
||||
def self.included(app)
|
||||
app.send :extend, ClassMethods
|
||||
app.send :delegate, :config, to: :"self.class"
|
||||
app.send :def_delegator, :"self.class", :config
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
|
|
@ -16,7 +16,7 @@ module Middleman
|
|||
app.config[:autoload_sprockets] = (ENV['AUTOLOAD_SPROCKETS'] == 'true') if ENV['AUTOLOAD_SPROCKETS']
|
||||
|
||||
app.extend ClassMethods
|
||||
app.delegate :configure, to: :"self.class"
|
||||
app.def_delegator :"self.class", :configure
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
|
|
@ -53,9 +53,12 @@ module Middleman
|
|||
|
||||
# Core File Change API class
|
||||
class API
|
||||
extend Forwardable
|
||||
|
||||
attr_reader :app
|
||||
attr_reader :known_paths
|
||||
delegate :logger, to: :app
|
||||
|
||||
def_delegator :@app, :logger
|
||||
|
||||
# Initialize api and internal path cache
|
||||
def initialize(app)
|
||||
|
|
|
@ -52,7 +52,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
end
|
||||
end
|
||||
|
||||
delegate :logger, to: :app
|
||||
def_delegator :@app, :logger
|
||||
|
||||
def langs
|
||||
@langs ||= known_languages
|
||||
|
|
|
@ -146,8 +146,9 @@ module Middleman
|
|||
|
||||
# Methods to be mixed-in to Middleman::Application
|
||||
module InstanceMethods
|
||||
delegate :use, to: :"self.class"
|
||||
delegate :map, to: :"self.class"
|
||||
def self.included(app)
|
||||
app.send :def_delegators, :"self.class", :use, :map
|
||||
end
|
||||
|
||||
def call(env)
|
||||
dup.call!(env)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
require 'active_support/core_ext/module/delegation'
|
||||
require 'active_support/core_ext/class/attribute'
|
||||
require 'middleman-core/configuration'
|
||||
|
||||
|
@ -65,6 +64,8 @@ module Middleman
|
|||
#
|
||||
# @see http://middlemanapp.com/advanced/custom/ Middleman Custom Extensions Documentation
|
||||
class Extension
|
||||
extend Forwardable
|
||||
|
||||
# @!attribute supports_multiple_instances
|
||||
# @!scope class
|
||||
# @return [Boolean] whether or not an extension can be activated multiple times, generating multiple instances of the extension.
|
||||
|
@ -175,7 +176,7 @@ module Middleman
|
|||
# @param [Symbol] name The name the extension was registered under
|
||||
# @param [Proc] block A callback to run when the named extension is activated
|
||||
# @return [void]
|
||||
delegate :after_extension_activated, to: :"::Middleman::Extension"
|
||||
def_delegator :"::Middleman::Extension", :after_extension_activated
|
||||
|
||||
# Extensions are instantiated when they are activated.
|
||||
# @param [Class] klass The Middleman::Application class
|
||||
|
|
|
@ -3,11 +3,13 @@ require 'active_support/core_ext/string/output_safety'
|
|||
|
||||
module Middleman
|
||||
class FileRenderer
|
||||
extend Forwardable
|
||||
|
||||
def self.cache
|
||||
@_cache ||= ::Tilt::Cache.new
|
||||
end
|
||||
|
||||
delegate :cache, to: :"self.class"
|
||||
def_delegator :"self.class", :cache
|
||||
|
||||
def initialize(app, path)
|
||||
@app = app
|
||||
|
|
|
@ -8,8 +8,10 @@ module Middleman
|
|||
DEFAULT_PORT = 4567
|
||||
|
||||
class << self
|
||||
extend Forwardable
|
||||
|
||||
attr_reader :app, :host, :port
|
||||
delegate :logger, to: :app
|
||||
def_delegator :app, :logger
|
||||
|
||||
# Start an instance of Middleman::Application
|
||||
# @return [void]
|
||||
|
|
|
@ -54,7 +54,7 @@ module Middleman
|
|||
register_resource_list_manipulator(k, m)
|
||||
end
|
||||
|
||||
@app.config_context.class.send :delegate, :sitemap, to: :app
|
||||
@app.config_context.class.send :def_delegator, :app, :sitemap
|
||||
end
|
||||
|
||||
# Register an object which can transform the sitemap resource list. Best to register
|
||||
|
|
|
@ -11,6 +11,8 @@ module Middleman
|
|||
# A new context is created for each render of a path, but that context is shared through
|
||||
# the request, passed from template, to layouts and partials.
|
||||
class TemplateContext
|
||||
extend Forwardable
|
||||
|
||||
# Allow templates to directly access the current app instance.
|
||||
# @return [Middleman::Application]
|
||||
attr_reader :app
|
||||
|
@ -19,7 +21,7 @@ module Middleman
|
|||
attr_accessor :current_engine
|
||||
|
||||
# Shorthand references to global values on the app instance.
|
||||
delegate :config, :logger, :sitemap, :server?, :build?, :environment?, :data, :extensions, :source_dir, :root, to: :app
|
||||
def_delegators :@app, :config, :logger, :sitemap, :server?, :build?, :environment?, :data, :extensions, :source_dir, :root
|
||||
|
||||
# Initialize a context with the current app and predefined locals and options hashes.
|
||||
#
|
||||
|
@ -154,7 +156,7 @@ module Middleman
|
|||
file_renderer = ::Middleman::FileRenderer.new(@app, path)
|
||||
file_renderer.render(locs, opts, self, &block)
|
||||
end
|
||||
|
||||
|
||||
def current_path
|
||||
@locs[:current_path]
|
||||
end
|
||||
|
|
|
@ -5,11 +5,13 @@ require 'middleman-core/file_renderer'
|
|||
|
||||
module Middleman
|
||||
class TemplateRenderer
|
||||
extend Forwardable
|
||||
|
||||
def self.cache
|
||||
@_cache ||= ::Tilt::Cache.new
|
||||
end
|
||||
|
||||
delegate :cache, to: :"self.class"
|
||||
def_delegator :"self.class", :cache
|
||||
|
||||
# Custom error class for handling
|
||||
class TemplateNotFound < RuntimeError; end
|
||||
|
|
Loading…
Reference in a new issue