Sha256: 3f4a089a2c9b0f46703e1bb1689cff39227c9332987538f378924f7d459512ed

Contents?: true

Size: 878 Bytes

Versions: 35

Compression:

Stored size: 878 Bytes

Contents

# Allows to check the the view type by using `view.index?` or `view.edit?` etc...
# It also allows to check if the view is a form or a display view by using `view.form?` or `view.display?`
module Avo
  class ViewInquirer < ActiveSupport::StringInquirer
    DISPLAY_VIEWS = %w[index show].freeze unless defined? DISPLAY_VIEWS
    FORM_VIEWS = %w[new edit create update].freeze unless defined? FORM_VIEWS

    def initialize(view)
      super(view.to_s)

      @display = in? DISPLAY_VIEWS
      @form = in? FORM_VIEWS
    end

    def display?
      @display
    end

    def form?
      @form
    end

    # To avoid breaking changes we allow the comparison with symbols
    def ==(other)
      if other.is_a? Symbol
        to_sym == other
      else
        super(other)
      end
    end

    def in?(another_object)
      super(another_object.map(&:to_s))
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
avo-3.14.3 lib/avo/view_inquirer.rb
avo-3.14.2 lib/avo/view_inquirer.rb
avo-3.14.1 lib/avo/view_inquirer.rb
avo-3.14.0 lib/avo/view_inquirer.rb
avo-3.13.7 lib/avo/view_inquirer.rb
avo-3.13.6 lib/avo/view_inquirer.rb
avo-3.13.5 lib/avo/view_inquirer.rb
avo-3.13.4 lib/avo/view_inquirer.rb
avo-3.13.3 lib/avo/view_inquirer.rb
avo-3.13.2 lib/avo/view_inquirer.rb
avo-3.13.1 lib/avo/view_inquirer.rb
avo-3.13.0 lib/avo/view_inquirer.rb
avo-3.12.0 lib/avo/view_inquirer.rb
avo-3.11.10 lib/avo/view_inquirer.rb
avo-3.11.9 lib/avo/view_inquirer.rb
avo-3.11.8 lib/avo/view_inquirer.rb
avo-3.11.7 lib/avo/view_inquirer.rb
avo-3.11.6 lib/avo/view_inquirer.rb
avo-3.11.5 lib/avo/view_inquirer.rb
avo-3.11.4 lib/avo/view_inquirer.rb