Sha256: f0098f3398dff6e704423296f18e22d12f490a171801bd1be71756239dd3708b

Contents?: true

Size: 1 KB

Versions: 28

Compression:

Stored size: 1 KB

Contents

module Betterdocs
  class ControllerCollector
    def initialize
      @actions    = {}
      @element    = nil
      @controller = nil
    end

    attr_accessor :controller

    attr_writer :element

    def actions
      @actions.values.reject(&:private)
    end

    def action(action_name)
      action_name = action_name.to_sym
      @actions[action_name]
    end

    def section
      @controller.ask_and_send(:section)
    end

    def add_element(klass, type, &block)
      element = build_element(klass, type, &block)
      element.add_to_collector(self)
    end

    def configure_current_element(action_name)
      if @element
        @element.configure_for_action(action_name)
        @actions[action_name] = @element
      end
      @element = nil
      self
    end

    def to_s
      ([ @controller, '=' * 79, actions * ("-" * 79 + "\n"), '' ]) * "\n"
    end

    private

    def build_element(klass, type, &block)
      Dsl::Controller.const_get(type.to_s.camelcase).new(klass, &block)
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
betterdocs-0.12.5 lib/betterdocs/controller_collector.rb
betterdocs-0.12.4 lib/betterdocs/controller_collector.rb
betterdocs-0.12.3 lib/betterdocs/controller_collector.rb
betterdocs-0.12.2 lib/betterdocs/controller_collector.rb
betterdocs-0.12.1 lib/betterdocs/controller_collector.rb
betterdocs-0.12.0 lib/betterdocs/controller_collector.rb
betterdocs-0.11.0 lib/betterdocs/controller_collector.rb
betterdocs-0.10.0 lib/betterdocs/controller_collector.rb
betterdocs-0.9.2 lib/betterdocs/controller_collector.rb
betterdocs-0.9.1 lib/betterdocs/controller_collector.rb
betterdocs-0.9.0 lib/betterdocs/controller_collector.rb
betterdocs-0.8.1 lib/betterdocs/controller_collector.rb
betterdocs-0.8.0 lib/betterdocs/controller_collector.rb
betterdocs-0.7.1 lib/betterdocs/controller_collector.rb
betterdocs-0.7.0 lib/betterdocs/controller_collector.rb
betterdocs-0.6.8 lib/betterdocs/controller_collector.rb
betterdocs-0.6.7 lib/betterdocs/controller_collector.rb
betterdocs-0.6.6 lib/betterdocs/controller_collector.rb
betterdocs-0.6.5 lib/betterdocs/controller_collector.rb
betterdocs-0.6.4 lib/betterdocs/controller_collector.rb