Class: Buoys::Buoy
- Inherits:
-
Object
- Object
- Buoys::Buoy
- Defined in:
- lib/buoys/buoy.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#previous ⇒ Object
readonly
Returns the value of attribute previous.
Instance Method Summary collapse
-
#initialize(context, key, *args) ⇒ Buoy
constructor
buoy :account do link ‘Account’, account_path end.
- #link(key, *args) ⇒ Object
- #links ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #pre_buoy(key, *args) ⇒ Object (also: #parent)
Constructor Details
#initialize(context, key, *args) ⇒ Buoy
buoy :account do
link 'Account', account_path
end
buoy :account_edit do |account|
link 'Account Show', show_account_path(account)
link 'Account Edit', edit_account_path(account)
pre_buoy :account
end
13 14 15 16 17 18 19 20 |
# File 'lib/buoys/buoy.rb', line 13 def initialize(context, key, *args) block = Buoys::Loader.buoys[key] raise ArgumentError, "Buoys :#{key} is not found" unless block @key = key @context = context instance_exec(*args, &block) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
41 42 43 |
# File 'lib/buoys/buoy.rb', line 41 def method_missing(method, *args, &block) context.send(method, *args, &block) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/buoys/buoy.rb', line 3 def context @context end |
#previous ⇒ Object (readonly)
Returns the value of attribute previous.
3 4 5 |
# File 'lib/buoys/buoy.rb', line 3 def previous @previous end |
Instance Method Details
#link(key, *args) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/buoys/buoy.rb', line 22 def link(key, *args) = args. path = args.shift url = path ? context.url_for(path) : path text = I18n.t(key, scope: 'buoys.breadcrumbs', default: key) links << Buoys::Link.new(text, url, ) end |
#links ⇒ Object
32 33 34 |
# File 'lib/buoys/buoy.rb', line 32 def links @links ||= [] end |