Class: Uchi::View
- Inherits:
-
Object
- Object
- Uchi::View
- Defined in:
- lib/uchi/view.rb,
lib/uchi/view/constants.rb
Overview
Represents a view/action a field or resource can appear on, e.g. :index, :show, :new, :edit.
Uchi::View behaves like the underlying Symbol for equality, hashing and array membership.
Constant Summary collapse
- NAMES =
[:edit, :index, :new, :show].freeze
- EDIT =
Define some commonly used views as constants for convenience.
new(:edit).freeze
- INDEX =
new(:index).freeze
- NEW =
new(:new).freeze
- SHOW =
new(:show).freeze
- ALL =
Shorthand for all views.
[EDIT, INDEX, NEW, SHOW].freeze
- FORM =
Shorthand for views with a form
[EDIT, NEW].freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #edit? ⇒ Boolean
- #hash ⇒ Object
- #index? ⇒ Boolean
-
#initialize(name) ⇒ View
constructor
A new instance of View.
- #inspect ⇒ Object
- #new? ⇒ Boolean
- #show? ⇒ Boolean
- #to_s ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(name) ⇒ View
Returns a new instance of View.
17 18 19 20 21 22 |
# File 'lib/uchi/view.rb', line 17 def initialize(name) raise ArgumentError, "Unsupported view: #{name.inspect}" unless name.respond_to?(:to_sym) @name = name.is_a?(View) ? name.name : name.to_sym raise ArgumentError, "unknown view: #{@name.inspect}" unless NAMES.include?(@name) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/uchi/view.rb', line 15 def name @name end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
24 25 26 27 28 29 |
# File 'lib/uchi/view.rb', line 24 def ==(other) return name == other if other.is_a?(Symbol) return name == other.name if other.is_a?(self.class) false end |
#edit? ⇒ Boolean
48 49 50 |
# File 'lib/uchi/view.rb', line 48 def edit? name == :edit end |
#hash ⇒ Object
32 33 34 |
# File 'lib/uchi/view.rb', line 32 def hash name.hash end |
#index? ⇒ Boolean
52 53 54 |
# File 'lib/uchi/view.rb', line 52 def index? name == :index end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/uchi/view.rb', line 36 def inspect "#<Uchi::View #{name.inspect}>" end |
#new? ⇒ Boolean
56 57 58 |
# File 'lib/uchi/view.rb', line 56 def new? name == :new end |
#show? ⇒ Boolean
60 61 62 |
# File 'lib/uchi/view.rb', line 60 def show? name == :show end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/uchi/view.rb', line 40 def to_s name.to_s end |
#to_sym ⇒ Object
44 45 46 |
# File 'lib/uchi/view.rb', line 44 def to_sym name end |