Class: Dragonfly::Configurable::Configurer

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly/configurable.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Configurer

Returns a new instance of Configurer



44
45
46
# File 'lib/dragonfly/configurable.rb', line 44

def initialize(&block)
  (class << self; self; end).class_eval(&block)
end

Instance Method Details

#configure(obj, &block) ⇒ Object



48
49
50
51
52
53
# File 'lib/dragonfly/configurable.rb', line 48

def configure(obj, &block)
  previous_obj = @obj
  @obj = obj
  instance_eval(&block)
  @obj = previous_obj
end

#configure_with_plugin(obj, plugin, *args, &block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/dragonfly/configurable.rb', line 55

def configure_with_plugin(obj, plugin, *args, &block)
  if plugin.is_a?(Symbol)
    symbol = plugin
    raise(UnregisteredPlugin, "plugin #{symbol.inspect} is not registered") unless registered_plugins[symbol]
    plugin = registered_plugins[symbol].call
    obj.plugins[symbol] = plugin if obj.respond_to?(:plugins)
  end
  plugin.call(obj, *args, &block)
  plugin
end

#plugin(plugin, *args, &block) ⇒ Object



70
71
72
# File 'lib/dragonfly/configurable.rb', line 70

def plugin(plugin, *args, &block)
  configure_with_plugin(obj, plugin, *args, &block)
end

#register_plugin(name, &block) ⇒ Object



66
67
68
# File 'lib/dragonfly/configurable.rb', line 66

def register_plugin(name, &block)
  registered_plugins[name] = block
end