Sha256: 4aa0b9b714ed35be321ff48a273a9a067370d6507527faa30060392bb5f2fe0d

Contents?: true

Size: 866 Bytes

Versions: 3

Compression:

Stored size: 866 Bytes

Contents

require "map"
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

3 entries across 3 versions & 1 rubygems

Version Path
mvcli-0.0.6 lib/mvcli/actions.rb
mvcli-0.0.5 lib/mvcli/actions.rb
mvcli-0.0.4 lib/mvcli/actions.rb