waiter 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmQ1YzdlZmU3MDM4ZDgwOWQ0ZmNhMjI5MDcwNGYxZTUwMTE5YzI1MQ==
4
+ YjE2YjI1MjFlNjUzZTZiZWZhMTVlZDc0YjZjODg0Y2Y4YWExNjliMg==
5
5
  data.tar.gz: !binary |-
6
- ZTg1ZmIzMDc1MmQ4MDQ0MDk1ZDRmZjIwNzViMDVmYmFlYzBjYzhiNQ==
6
+ ZmQzYTJmOWIwYjJlMTQxYjIxZmVkMWZkOWVmZGU0ZDMwMmEzNzFhYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTBhMTMxOWQ4ZmNiZWEwZmNkMDkwMDBiZDA3YjIyODNhYTM1M2ZhNDgwYjY2
10
- OThhODZmYmQ3MDVhMWQzYTY4YWM4NWMwNGFiNzg5MTk4NWM1OTlkODIxMDM3
11
- ZTAwYjFhMTE1YWU3ZDhjYzE5ZDkyODI1ZjllNjdmMDEyZTY2ZGQ=
9
+ ZGY5ZTllYmVkMDJjYTQ5OGYwN2ZhYTcyNmY2MDBmZjgxMzAzM2U4ZjZiNjMz
10
+ ODQzMDAyN2JmNjhiNWY4NDRjNjY4N2NmOTg3YmJhMDYwZWYxN2NmMTYwMjlm
11
+ MDM2ZDJjZmQxNDY0NTUxZTc3YjMxOTE4ZjZlY2I3MjFlNGRhOTA=
12
12
  data.tar.gz: !binary |-
13
- MGVjZTZmMWY4NmY3MTM4NDI0NGQyNjBkMTc1MTFkZGM4OWFkYjU1YTc2MmIz
14
- MWNkNWYwNjhiMWY5YTRhNGQ2NWNkMzdjMDQzZDA3YzBkN2FlNzEwMzc4OTIz
15
- NzU4YmZjZTA2YjFhNDVmNWEwMTM2NTJhMzk1ZGIyOTZkMzVjNGY=
13
+ YjFhNjkzYzQwYTQ1OTRmNmY1M2I1ZmJmMDdlYmZhMjI0MWZjMDlkYjdkM2E4
14
+ MmUzNGVkNDIwZmM5NTA0ZWMxYTdmYzZjOTA0OGM1MDZkOWNhNGFjNjc2Nzky
15
+ YTIyOTU3NmIwY2FhZjkzZDc4NjU1YTRiNGViYWU3NWE1OTljYzY=
@@ -1,4 +1,4 @@
1
- - section.items.each do |subitem|
1
+ - section.items(true).each do |subitem|
2
2
  = render 'waiter/sub_item', item: item, subitem: subitem
3
3
 
4
4
  - unless last
data/lib/waiter/menu.rb CHANGED
@@ -3,6 +3,7 @@ require 'waiter/menu/item_list'
3
3
  require 'waiter/menu/item'
4
4
  require 'waiter/menu/section'
5
5
  require 'waiter/menu/drawer'
6
+ require 'active_support/core_ext/hash/slice'
6
7
 
7
8
  module Waiter
8
9
  class Menu
@@ -50,11 +51,7 @@ module Waiter
50
51
 
51
52
  def items(sorted = false)
52
53
  return @items unless sorted
53
-
54
- items = @items.dup
55
- items.sort_by!(&options[:sort].to_sym) if options.fetch(:sort, false)
56
- items.reverse! if options.fetch(:reverse, false)
57
- ItemList.new(items)
54
+ ItemList.new(@items, options.slice(:sort, :reverse))
58
55
  end
59
56
 
60
57
  def top?
@@ -1,6 +1,11 @@
1
1
  module Waiter
2
2
  class Menu
3
3
  class ItemList < Array
4
+ def initialize(ary = [], sort_options = {})
5
+ super(ary)
6
+ sort(sort_options)
7
+ end
8
+
4
9
  def include?(other)
5
10
  return map(&:name).include?(other) if other.is_a? Symbol
6
11
  super
@@ -14,6 +19,11 @@ module Waiter
14
19
  def names
15
20
  map(&:name)
16
21
  end
22
+
23
+ def sort(options = {})
24
+ sort_by!(&options[:sort].to_sym) if options.fetch(:sort, false)
25
+ reverse! if options.fetch(:reverse, false)
26
+ end
17
27
  end
18
28
  end
19
29
  end
@@ -11,6 +11,11 @@ module Waiter
11
11
  true
12
12
  end
13
13
 
14
+ def items(sorted = false)
15
+ return super() unless sorted
16
+ ItemList.new(super(), options.slice(:sort, :reverse))
17
+ end
18
+
14
19
  private
15
20
 
16
21
  def complete_path_for(*)
@@ -1,3 +1,3 @@
1
1
  module Waiter
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
@@ -3,7 +3,7 @@ require 'waiter/menu/section'
3
3
  require 'waiter/menu'
4
4
 
5
5
  RSpec.describe Waiter::Menu::Section do
6
- let(:parent) { double(Waiter::Menu, name: :parent, options: {}) }
6
+ let(:parent) { double(Waiter::Menu, name: :parent, context: nil, options: {}) }
7
7
  subject { described_class.new(parent) }
8
8
 
9
9
  before do
@@ -18,4 +18,32 @@ RSpec.describe Waiter::Menu::Section do
18
18
  its(:submenu) { is_expected.to be_nil }
19
19
 
20
20
  it_behaves_like 'a menu item', []
21
+
22
+ describe '#items' do
23
+ subject do
24
+ described_class.new(parent, @options) do
25
+ foo
26
+ bar
27
+ baz
28
+ quux
29
+ end
30
+ end
31
+
32
+ before { allow_any_instance_of(Waiter::Menu::Item).to receive(:translate) { |_, key| key.to_sym } }
33
+
34
+ it 'should sort by item title' do
35
+ @options = { sort: :item_title }
36
+ expect(subject.items(true).names).to match [:bar, :baz, :foo, :quux]
37
+ end
38
+
39
+ it 'should reverse' do
40
+ @options = { reverse: true }
41
+ expect(subject.items(true).names).to match [:quux, :baz, :bar, :foo]
42
+ end
43
+
44
+ it 'should sort and reverse at the same time' do
45
+ @options = { sort: :item_title, reverse: true }
46
+ expect(subject.items(true).names).to match [:quux, :foo, :baz, :bar]
47
+ end
48
+ end
21
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waiter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Vandersluis