Sha256: 23c3b6aa782c2de8600d4d20da0bf8b7e88c559649c63552cd0652e05e2d8a51

Contents?: true

Size: 877 Bytes

Versions: 24

Compression:

Stored size: 877 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

24 entries across 24 versions & 1 rubygems

Version Path
avo-3.9.2 lib/avo/view_inquirer.rb
avo-3.9.1 lib/avo/view_inquirer.rb
avo-3.8.2 lib/avo/view_inquirer.rb
avo-3.9.0 lib/avo/view_inquirer.rb
avo-3.8.1 lib/avo/view_inquirer.rb
avo-3.8.0 lib/avo/view_inquirer.rb
avo-3.6.4 lib/avo/view_inquirer.rb
avo-3.6.3 lib/avo/view_inquirer.rb
avo-3.6.2 lib/avo/view_inquirer.rb
avo-3.6.1 lib/avo/view_inquirer.rb
avo-3.6.0 lib/avo/view_inquirer.rb
avo-3.5.8 lib/avo/view_inquirer.rb
avo-3.5.7 lib/avo/view_inquirer.rb
avo-3.5.6 lib/avo/view_inquirer.rb
avo-3.5.6.beta1 lib/avo/view_inquirer.rb
avo-3.5.5 lib/avo/view_inquirer.rb
avo-3.5.4 lib/avo/view_inquirer.rb
avo-3.5.3 lib/avo/view_inquirer.rb
avo-3.5.2 lib/avo/view_inquirer.rb
avo-3.5.1 lib/avo/view_inquirer.rb