Sha256: 63259adaa20e71edbca478a6ec63e61ef2750bd0fceec9701da030f6e38eecd5

Contents?: true

Size: 2 KB

Versions: 2

Compression:

Stored size: 2 KB

Contents

module Vedeu

  module Buffers

    # Refreshes the given named interface.
    #
    class Refresh

      include Vedeu::Common

      # @example
      #   Vedeu.trigger(:_refresh_view_, name)
      #
      # @param (see #initialize)
      # @return (see #by_name)
      def self.by_name(name)
        new(name).by_name
      end

      # @example
      #   Vedeu.trigger(:_refresh_view_content_, name)
      #
      # @param (see #initialize)
      # @return (see #by_name)
      def self.refresh_content_by_name(name)
        new(name, content_only: true).by_name
      end

      # Return a new instance of Vedeu::Buffers::Refresh.
      #
      # @param name [String|Symbol] The name of the interface to be refreshed
      #   using the named buffer.
      # @param options [Hash]
      # @option options content_only [Boolean]
      # @return [Vedeu::Buffers::Refresh]
      def initialize(name, options = {})
        @name    = name
        @options = options
      end

      # @return [Array|Vedeu::Error::ModelNotFound]
      def by_name
        Vedeu.trigger(:_clear_view_content_, name)

        Vedeu.buffers.by_name(name).render

        Vedeu.trigger(:_refresh_border_, name) unless content_only?
      end

      protected

      # @!attribute [r] name
      # @return [String|Symbol]
      attr_reader :name

      # @return [Boolean]
      def content_only?
        options[:content_only] == true
      end

      # @return [Hash<Symbol => Boolean>]
      def options
        defaults.merge!(@options)
      end

      # @return [Hash<Symbol => Boolean>]
      def defaults
        {
          content_only: false,
        }
      end

    end # Refresh

  end # Buffers

  # :nocov:

  # See {file:docs/events/refresh.md#\_refresh_view_}
  Vedeu.bind(:_refresh_view_) do |name|
    Vedeu::Buffers::Refresh.by_name(name)
  end

  # See {file:docs/events/refresh.md#\_refresh_view_content_}
  Vedeu.bind(:_refresh_view_content_) do |name|
    Vedeu::Buffers::Refresh.refresh_content_by_name(name)
  end

  # :nocov:

end # Vedeu

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.6.32 lib/vedeu/buffers/refresh.rb
vedeu-0.6.31 lib/vedeu/buffers/refresh.rb