Sha256: e04d4535e1137f73b7cf00e8d10ea4796348d6dc4ed6edd7a73824b0c24a0b85

Contents?: true

Size: 936 Bytes

Versions: 2

Compression:

Stored size: 936 Bytes

Contents

module IronNails

  module View

    class AddSubViewCommand < Command

      # the controller for the subview
      attr_accessor :controller

      # the target that will contain the view for this controller
      attr_accessor :target

      alias_method :nails_base_command_read_options, :read_options

      def read_options(options)
        nails_base_command_read_options options
        raise ArgumentError.new("We need a target to be defined by the :to parameter") if options[:to].nil?
        raise ArgumentError.new("We need a controller instance to be defined in the :controller parameter") if options[:controller].nil? || !options[:controller].respond_to?(:current_view)

        @controller = options[:controller]
        @target = options[:to]
      end

      # executes this command (it calls the action)
      def execute
        view.add_control target, controller.current_view.instance
      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ironnails-0.0.3 lib/ironnails/view/commands/add_sub_view_command.rb
ironnails-0.0.1 lib/ironnails/view/commands/add_sub_view_command.rb