module Dionysus::ConfigurationCallbacks::Configuration

Public Instance Methods

after(get_set, key, *args, &block) click to toggle source
# File lib/dionysus/configuration_callbacks.rb, line 40
def after(get_set, key, *args, &block)
  name = _setup_for_callback(get_set, key)
  self.class.set_callback(name, :after, *args, &block)
end
around(get_set, key, *args, &block) click to toggle source
# File lib/dionysus/configuration_callbacks.rb, line 45
def around(get_set, key, *args, &block)
  name = _setup_for_callback(get_set, key)
  self.class.set_callback(name, :around, *args, &block)
end
before(get_set, key, *args, &block) click to toggle source
# File lib/dionysus/configuration_callbacks.rb, line 35
def before(get_set, key, *args, &block)
  name = _setup_for_callback(get_set, key)
  self.class.set_callback(name, :before, *args, &block)
end
forward(get_set, key, to_accessor, to_method) click to toggle source
# File lib/dionysus/configuration_callbacks.rb, line 50
def forward(get_set, key, to_accessor, to_method)
  case get_set.to_sym
  when :get
    self.class.def_delegator(to_accessor, to_method, key)
  when :set
    self.class.def_delegator(to_accessor, to_method, "#{key}=")
  else
    raise ArgumentError, "Invalid get_set parameter %p"%[get_set]
  end
end
respond_to?(name, include_private=false) click to toggle source
# File lib/dionysus/configuration_callbacks.rb, line 27
def respond_to?(name, include_private=false)
  if name.to_s =~ /^_/
    include_private ? method_defined?(name) : public_method_defined?(name)
  else
    true
  end
end

Private Instance Methods

_setup_for_callback(get_set, key) click to toggle source
# File lib/dionysus/configuration_callbacks.rb, line 63
      def _setup_for_callback(get_set, key)
        key = key.to_sym
        name = "#{get_set}_#{key}"

        case get_set.to_sym
        when :get
          if method_defined?(key)
            warn "Cannot setup callbacks for #{self}##{key}.  Method already defined."
          else
            class_eval <<-EOS, __FILE__, __LINE__ + 1
              def #{key}() run_callbacks(#{name.inspect}) { _get(#{key.inspect}) }; end
            EOS
          end
        when :set
          if method_defined?(:"#{key}=")
            warn "Cannot setup callbacks for #{self}##{key}.  Method already defined."
          else
            class_eval <<-EOS, __FILE__, __LINE__ + 1
              def #{key}=(val) run_callbacks(#{name.inspect}) { _set(#{key.inspect}, val) }; end
            EOS
          end
        else
          raise ArgumentError, "Invalid get_set parameter %p"%[get_set]
        end

        self.class.define_callbacks(name)
        return name
      end