Sha256: a2f55246b2063ca9d3a225ff0839380e6901503d36cda249cc4ec4161ba11474

Contents?: true

Size: 792 Bytes

Versions: 13

Compression:

Stored size: 792 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]
    FORM_VIEWS = %w[new edit]

    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

13 entries across 13 versions & 1 rubygems

Version Path
avo-3.0.1.beta17 lib/avo/view_inquirer.rb
avo-3.0.1.beta18 lib/avo/view_inquirer.rb
avo-3.0.1.beta19 lib/avo/view_inquirer.rb
avo-3.0.1.beta15 lib/avo/view_inquirer.rb
avo-3.0.1.beta16 lib/avo/view_inquirer.rb
avo-3.0.1.beta14 lib/avo/view_inquirer.rb
avo-3.0.1.beta12 lib/avo/view_inquirer.rb
avo-3.0.1.beta13 lib/avo/view_inquirer.rb
avo-3.0.1.beta10 lib/avo/view_inquirer.rb
avo-3.0.1.beta11 lib/avo/view_inquirer.rb
avo-3.0.0.pre19 lib/avo/view_inquirer.rb
avo-3.0.1.beta8 lib/avo/view_inquirer.rb
avo-3.0.1.beta9 lib/avo/view_inquirer.rb