Sha256: 4fc4c407bbde9f97b6019163e2cc406b5ae3a8db95141021945b848bb7836225

Contents?: true

Size: 668 Bytes

Versions: 36

Compression:

Stored size: 668 Bytes

Contents

require 'forwardable'

class ExplicitDelegator
  extend Forwardable

  def self.enforce_definitions(*methods)
    define_method(:enforced_methods) do
      super() | methods
    end

    methods.each do |method|
      def_instance_delegator(:@delegate, method)
    end
  end

  def initialize(delegate)
    @delegate = delegate

    ensure_defined
  end

  def enforced_methods
    []
  end

  def ensure_defined
    missing_methods = []
    enforced_methods.each do |method|
      missing_methods << method unless @delegate.methods.include?(method)
    end
    raise "Methods required to use #{self.class}: #{missing_methods}" unless missing_methods.empty?
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
woople-theme-0.8.1 lib/explicit_delegator.rb
woople-theme-0.8.0 lib/explicit_delegator.rb
woople-theme-0.6.27 lib/explicit_delegator.rb
woople-theme-0.6.26 lib/explicit_delegator.rb
woople-theme-0.6.25 lib/explicit_delegator.rb
woople-theme-0.6.24 lib/explicit_delegator.rb
woople-theme-0.6.23 lib/explicit_delegator.rb
woople-theme-0.6.22 lib/explicit_delegator.rb
woople-theme-0.6.21 lib/explicit_delegator.rb
woople-theme-0.6.20 lib/explicit_delegator.rb
woople-theme-0.6.19 lib/explicit_delegator.rb
woople-theme-0.6.18 lib/explicit_delegator.rb
woople-theme-0.6.17 lib/explicit_delegator.rb
woople-theme-0.6.14 lib/explicit_delegator.rb
woople-theme-0.6.13 lib/explicit_delegator.rb
woople-theme-0.6.12 lib/explicit_delegator.rb