Class: DatGretel::Link
- Inherits:
-
Object
- Object
- DatGretel::Link
- Defined in:
- lib/dat_gretel/link.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
Returns the value of attribute current.
-
#key ⇒ Object
Returns the value of attribute key.
-
#options ⇒ Object
Returns the value of attribute options.
-
#text ⇒ Object
Returns the value of attribute text.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#current! ⇒ Object
Sets current so
current?
will returntrue
. -
#current? ⇒ Boolean
Returns
true
if this is the last link in the breadcrumb trail. -
#initialize(key, text, url, options = {}) ⇒ Link
constructor
A new instance of Link.
-
#method_missing(method, *args, &block) ⇒ Object
Enables accessors and predicate methods for values in the
options
hash.
Constructor Details
#initialize(key, text, url, options = {}) ⇒ Link
Returns a new instance of Link.
5 6 7 8 9 |
# File 'lib/dat_gretel/link.rb', line 5 def initialize(key, text, url, = {}) # Use accessors so plugins can override their behavior self.key, self.text, self.url, self. = key, text, url, self.current = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Enables accessors and predicate methods for values in the options
hash. This can be used to pass information to links when rendering breadcrumbs manually.
link = Link.new(:my_crumb, "My Crumb", my_path, title: "Test Title", other_value: "Other")
link.title? # => true
link.title # => "Test Title"
link.other_value? # => true
link.other_value # => "Other"
link.some_other? # => false
link.some_other # => nil
32 33 34 35 36 37 38 |
# File 'lib/dat_gretel/link.rb', line 32 def method_missing(method, *args, &block) if method =~ /(.+)\?$/ [$1.to_sym].present? else [method] end end |
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
3 4 5 |
# File 'lib/dat_gretel/link.rb', line 3 def current @current end |
#key ⇒ Object
Returns the value of attribute key.
3 4 5 |
# File 'lib/dat_gretel/link.rb', line 3 def key @key end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/dat_gretel/link.rb', line 3 def @options end |
#text ⇒ Object
Returns the value of attribute text.
3 4 5 |
# File 'lib/dat_gretel/link.rb', line 3 def text @text end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/dat_gretel/link.rb', line 3 def url @url end |
Instance Method Details
#current! ⇒ Object
Sets current so current?
will return true
.
12 13 14 |
# File 'lib/dat_gretel/link.rb', line 12 def current! @current = true end |
#current? ⇒ Boolean
Returns true
if this is the last link in the breadcrumb trail.
17 18 19 |
# File 'lib/dat_gretel/link.rb', line 17 def current? !!@current end |