Class: RailsOmnibar::Item::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_omnibar/item/base.rb

Direct Known Subclasses

Help

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, url: nil, modal_html: nil, type: :default) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
12
13
14
# File 'lib/rails_omnibar/item/base.rb', line 6

def initialize(title:, url: nil, modal_html: nil, type: :default)
  title.class.in?([String, Symbol]) && title.present? || raise(ArgumentError, 'title: must be a String')
  url.present? && modal_html.present? && raise(ArgumentError, 'use EITHER url: OR modal_html:')

  @title      = title
  @url        = url
  @modal_html = modal_html
  @type       = type
end

Instance Attribute Details

Returns the value of attribute modal_html.



4
5
6
# File 'lib/rails_omnibar/item/base.rb', line 4

def modal_html
  @modal_html
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/rails_omnibar/item/base.rb', line 4

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/rails_omnibar/item/base.rb', line 4

def type
  @type
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/rails_omnibar/item/base.rb', line 4

def url
  @url
end

Instance Method Details

#as_jsonObject



16
17
18
# File 'lib/rails_omnibar/item/base.rb', line 16

def as_json(*)
  { title: title, url: url, modalHTML: modal_html, type: type }
end