active_enum 1.0.0.rc3 → 1.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d2ff570eda0a94b326f65a6a97b5b6bb68cd3f953fba95cdc14e34e184f8afc
4
- data.tar.gz: fb5e45a1e55ee514408b1e1a71c0559b52bacb74f2d632dea63680a495bcf523
3
+ metadata.gz: 86faf9c711cf0ac0e6cce2450bee21b48d979c7e3feff9db3fde5d89628e2ee3
4
+ data.tar.gz: 49a52e216f81e72be6ac0ad601281efa6f171d599a7d91d974a2745e3d6ddfd4
5
5
  SHA512:
6
- metadata.gz: dae56bad88d50dbef7355c37243b5c76dea0cd4a741ee6389f94824453f3e5d05bae64966102a304ce643fc675f3a37584637ac4e6bf9d0219d96911e0effbd2
7
- data.tar.gz: 6aec92d08a5afad8eb137cd319346d41784ec19648a8c261408dc2896fcb853a4e8ba345bd50d98b67ddf5e49d82747c3fdd32035a9011184a1c7783a1f69b63
6
+ metadata.gz: 817cd0815232eddfad91e4aa95e2e09a9aa13ed04265e0427644255722f257a4da323e9179cbb37a601ccb4f59190c5ac1358cc242db290c0820377947ac83dd
7
+ data.tar.gz: 42eede1664ec537ba56c5d657baefe168e588955d1b29e7e8c2e346977a2d2ef3f9f02413ee0efdf783639a657a9d677eec619b46c799f82668ee46a3ff5ea09
@@ -16,6 +16,10 @@ module ActiveEnum
16
16
 
17
17
  module ClassMethods
18
18
 
19
+ def values
20
+ enum_values.map { |v| [ v.id, v.send(active_enum_options[:name_column]) ] }
21
+ end
22
+
19
23
  def ids
20
24
  enum_values.map { |v| v.id }
21
25
  end
@@ -34,9 +34,11 @@ module ActiveEnum
34
34
  @order = order
35
35
  end
36
36
 
37
- def all
37
+ # Array of arrays of stored values defined id, name, meta values hash
38
+ def values
38
39
  store.values
39
40
  end
41
+ alias_method :all, :values
40
42
 
41
43
  def each(&block)
42
44
  all.each(&block)
@@ -1,3 +1,3 @@
1
1
  module ActiveEnum
2
- VERSION = '1.0.0.rc3'
2
+ VERSION = '1.0.0.rc4'
3
3
  end
@@ -45,6 +45,12 @@ describe ActiveEnum::ActsAsEnum do
45
45
  end
46
46
  end
47
47
 
48
+ context '#values' do
49
+ it "should return array of arrays containing id and name column values" do
50
+ expect(Person.values).to eq([[1, 'Dave'], [2, 'John']])
51
+ end
52
+ end
53
+
48
54
  context '#to_select' do
49
55
  it "should return array for select helpers" do
50
56
  expect(Person.to_select).to eq([['Dave', 1], ['John', 2]])
@@ -24,9 +24,9 @@ describe ActiveEnum::Base do
24
24
  end
25
25
  end
26
26
 
27
- describe ".all" do
27
+ describe ".values" do
28
28
  it 'should return an empty array when no values defined' do
29
- expect(define_enum.all).to eq([])
29
+ expect(define_enum.values).to eq([])
30
30
  end
31
31
 
32
32
  it 'should return an array of arrays with all values defined as [id, name]' do
@@ -34,7 +34,7 @@ describe ActiveEnum::Base do
34
34
  value :name => 'Name 1'
35
35
  value :name => 'Name 2'
36
36
  end
37
- expect(enum.all).to eq([[1,'Name 1'], [2, 'Name 2']])
37
+ expect(enum.values).to eq([[1,'Name 1'], [2, 'Name 2']])
38
38
  end
39
39
  end
40
40
 
@@ -43,28 +43,28 @@ describe ActiveEnum::Base do
43
43
  enum = define_enum do
44
44
  value :id => 1, :name => 'Name'
45
45
  end
46
- expect(enum.all).to eq([[1,'Name']])
46
+ expect(enum.values).to eq([[1,'Name']])
47
47
  end
48
48
 
49
49
  it 'should allow me to define a value with a name only' do
50
50
  enum = define_enum do
51
51
  value :name => 'Name'
52
52
  end
53
- expect(enum.all).to eq([[1,'Name']])
53
+ expect(enum.values).to eq([[1,'Name']])
54
54
  end
55
55
 
56
56
  it 'should allow me to define a value as hash with id as key and name as value' do
57
57
  enum = define_enum do
58
58
  value 1 => 'Name'
59
59
  end
60
- expect(enum.all).to eq([[1,'Name']])
60
+ expect(enum.values).to eq([[1,'Name']])
61
61
  end
62
62
 
63
63
  it 'should allow to define meta data value with extra key value pairs' do
64
64
  enum = define_enum do
65
65
  value :id => 1, :name => 'Name', :description => 'extra'
66
66
  end
67
- expect(enum.all).to eq([[1,'Name',{:description => 'extra'}]])
67
+ expect(enum.values).to eq([[1,'Name',{:description => 'extra'}]])
68
68
  end
69
69
 
70
70
  it 'should increment value ids when defined without ids' do
@@ -72,7 +72,7 @@ describe ActiveEnum::Base do
72
72
  value :name => 'Name 1'
73
73
  value :name => 'Name 2'
74
74
  end
75
- expect(enum.all).to eq([[1,'Name 1'], [2, 'Name 2']])
75
+ expect(enum.values).to eq([[1,'Name 1'], [2, 'Name 2']])
76
76
  end
77
77
 
78
78
  it 'should raise error if the id is a duplicate' do
@@ -117,7 +117,7 @@ describe ActiveEnum::Base do
117
117
  value :id => 2, :name => 'Name 2'
118
118
  value :id => 1, :name => 'Name 1'
119
119
  end
120
- expect(enum.all).to eq([[1,'Name 1'], [2, 'Name 2']])
120
+ expect(enum.values).to eq([[1,'Name 1'], [2, 'Name 2']])
121
121
  end
122
122
 
123
123
  it 'should return sorted values by id using order setting' do
@@ -126,7 +126,7 @@ describe ActiveEnum::Base do
126
126
  value :id => 1, :name => 'Name 1'
127
127
  value :id => 2, :name => 'Name 2'
128
128
  end
129
- expect(enum.all).to eq([[2, 'Name 2'], [1,'Name 1']])
129
+ expect(enum.values).to eq([[2, 'Name 2'], [1,'Name 1']])
130
130
  end
131
131
 
132
132
  it 'should return sorted values by id using order setting' do
@@ -136,7 +136,7 @@ describe ActiveEnum::Base do
136
136
  value :id => 1, :name => 'Name 1'
137
137
  value :id => 2, :name => 'Name 2'
138
138
  end
139
- expect(enum.all).to eq([[3,'Name 3'], [1,'Name 1'], [2, 'Name 2']])
139
+ expect(enum.values).to eq([[3,'Name 3'], [1,'Name 1'], [2, 'Name 2']])
140
140
  end
141
141
  end
142
142
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc3
4
+ version: 1.0.0.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Meehan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-17 00:00:00.000000000 Z
11
+ date: 2020-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport