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.10.0 lib/explicit_delegator.rb
woople-theme-0.9.0 lib/explicit_delegator.rb
woople-theme-0.8.19 lib/explicit_delegator.rb
woople-theme-0.8.18 lib/explicit_delegator.rb
woople-theme-0.8.17 lib/explicit_delegator.rb
woople-theme-0.8.16 lib/explicit_delegator.rb
woople-theme-0.8.15 lib/explicit_delegator.rb
woople-theme-0.8.14 lib/explicit_delegator.rb
woople-theme-0.8.13 lib/explicit_delegator.rb
woople-theme-0.8.12 lib/explicit_delegator.rb
woople-theme-0.8.11 lib/explicit_delegator.rb
woople-theme-0.8.10 lib/explicit_delegator.rb
woople-theme-0.8.9 lib/explicit_delegator.rb
woople-theme-0.8.8 lib/explicit_delegator.rb
woople-theme-0.8.7 lib/explicit_delegator.rb
woople-theme-0.8.6 lib/explicit_delegator.rb
woople-theme-0.8.5 lib/explicit_delegator.rb
woople-theme-0.8.4 lib/explicit_delegator.rb
woople-theme-0.8.3 lib/explicit_delegator.rb
woople-theme-0.8.2 lib/explicit_delegator.rb