Sha256: 041abd4340d1e33846a7f8901c5d4289eaca9f831ebc38202c707d209335d3fe

Contents?: true

Size: 914 Bytes

Versions: 5

Compression:

Stored size: 914 Bytes

Contents

require "map"
require "mvcli/controller"
require "mvcli/form"
require_relative "loader"
require_relative "renderer"

module MVCLI
  class Actions
    def initialize(root, loader = Loader.new, renderer = nil)
      @loader = loader
      @renderer = renderer || Renderer.new(root)
    end

    def [](key)
      controller, method = key.split('#')
      Action.new @loader, @renderer, controller, method
    end

    class Action
      def initialize(loader, renderer, controller, method)
        @loader = loader
        @renderer = renderer
        @controller = controller
        @method = method
      end

      def call(command, bindings = Map.new)
        controller = @loader.load :controller, @controller, bindings
        context = controller.send @method
        path = [@controller, @method].join('/')
        @renderer.render command.output, path, context
        return 0
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mvcli-0.0.11 lib/mvcli/actions.rb
mvcli-0.0.10 lib/mvcli/actions.rb
mvcli-0.0.9 lib/mvcli/actions.rb
mvcli-0.0.8 lib/mvcli/actions.rb
mvcli-0.0.7 lib/mvcli/actions.rb