Sha256: a9b0d1de5419bbfc482de1b0b8460485a2ca8e941ccc87f6a08c3aaac676e6a8

Contents?: true

Size: 559 Bytes

Versions: 20

Compression:

Stored size: 559 Bytes

Contents

require 'delegate'

class ExplicitDelegator < SimpleDelegator
  def self.enforce_definitions(*methods)
    define_method(:enforced_methods) do
      super() | methods
    end
  end

  def initialize(obj)
    super(obj)
    ensure_defined
  end

  def enforced_methods
    []
  end

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
woople-theme-0.6.11 lib/explicit_delegator.rb
woople-theme-0.6.10 lib/explicit_delegator.rb
woople-theme-0.6.9 lib/explicit_delegator.rb
woople-theme-0.6.8 lib/explicit_delegator.rb
woople-theme-0.6.7 lib/explicit_delegator.rb
woople-theme-0.6.6 lib/explicit_delegator.rb
woople-theme-0.6.5 lib/explicit_delegator.rb
woople-theme-0.6.4 lib/explicit_delegator.rb
woople-theme-0.6.3 lib/explicit_delegator.rb
woople-theme-0.6.2 lib/explicit_delegator.rb
woople-theme-0.6.1 lib/explicit_delegator.rb
woople-theme-0.6 lib/explicit_delegator.rb
woople-theme-0.5.17 lib/explicit_delegator.rb
woople-theme-0.5.16 lib/explicit_delegator.rb
woople-theme-0.5.15 lib/explicit_delegator.rb
woople-theme-0.5.14 lib/explicit_delegator.rb
woople-theme-0.5.13 lib/explicit_delegator.rb
woople-theme-0.5.12 lib/explicit_delegator.rb
woople-theme-0.5.11 lib/explicit_delegator.rb
woople-theme-0.5.10 lib/explicit_delegator.rb