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, **kwargs, &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
16 17 18 19 20 21 22 23 |
# File 'lib/buoys/buoy.rb', line 16 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, **kwargs, &block) ⇒ Object
44 45 46 |
# File 'lib/buoys/buoy.rb', line 44 def method_missing(method, *args, **kwargs, &block) context.send(method, *args, **kwargs, &block) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/buoys/buoy.rb', line 5 def context @context end |
#previous ⇒ Object (readonly)
Returns the value of attribute previous.
5 6 7 |
# File 'lib/buoys/buoy.rb', line 5 def previous @previous end |
Instance Method Details
#link(key, *args) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/buoys/buoy.rb', line 25 def link(key, *args) = args. path = args.shift url = path ? context.url_for(path) : nil text = I18n.t(key, scope: 'buoys.breadcrumbs', default: key) links << Buoys::Link.new(text, url, ) end |
#links ⇒ Object
35 36 37 |
# File 'lib/buoys/buoy.rb', line 35 def links @links ||= [] end |