Class: Buoys::Buoy

Inherits:
Object
  • Object
show all
Defined in:
lib/buoys/buoy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, key, *args) ⇒ Buoy

buoy :account do

link 'Account', 

end

buoy :account_edit do |account|

link 'Account Show', ()
link 'Account Edit', ()
pre_buoy :account

end

Raises:

  • (ArgumentError)


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

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/buoys/buoy.rb', line 3

def context
  @context
end

#previousObject (readonly)

Returns the value of attribute previous.



3
4
5
# File 'lib/buoys/buoy.rb', line 3

def previous
  @previous
end

Instance Method Details



22
23
24
25
26
27
28
29
30
# File 'lib/buoys/buoy.rb', line 22

def link(key, *args)
  options = args.extract_options!
  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, options)
end


32
33
34
# File 'lib/buoys/buoy.rb', line 32

def links
  @links ||= []
end

#pre_buoy(key, *args) ⇒ Object Also known as: parent



36
37
38
# File 'lib/buoys/buoy.rb', line 36

def pre_buoy(key, *args)
  @previous = Buoys::Buoy.new(context, key, *args)
end