Class: Cartoonist::Admin::Tab

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

Constant Summary collapse

@@all =
{}
@@cached_order =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, options) ⇒ Tab

Returns a new instance of Tab.



18
19
20
21
22
# File 'lib/cartoonist.rb', line 18

def initialize(key, options)
  @key = key
  @url = options[:url]
  @order = options[:order]
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



13
14
15
# File 'lib/cartoonist.rb', line 13

def key
  @key
end

#orderObject (readonly)

Returns the value of attribute order.



13
14
15
# File 'lib/cartoonist.rb', line 13

def order
  @order
end

#urlObject (readonly)

Returns the value of attribute url.



13
14
15
# File 'lib/cartoonist.rb', line 13

def url
  @url
end

Class Method Details

.[](key) ⇒ Object



29
30
31
# File 'lib/cartoonist.rb', line 29

def [](key)
  @@all[key].url
end

.add(key, options) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cartoonist.rb', line 33

def add(key, options)
  @@all[key] = Cartoonist::Admin::Tab.new key, options
  @@cached_order = @@all.values.sort do |a, b|
    if a.order && b.order
      a.order <=> b.order
    elsif a.order && !b.order
      -1
    elsif b.order && !a.order
      1
    else
      a.key <=> b.key
    end
  end.map &:key
end

.allObject



25
26
27
# File 'lib/cartoonist.rb', line 25

def all
  @@cached_order
end