rails_core_extensions 0.13.2 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abf2a60c82dfb1b0eab8b44ce552adc6541a2cde2b02749e6e3fabcf1781ac71
|
4
|
+
data.tar.gz: 1b453d160782af795a187f15004c874b7794092396daec131e9e3f1c06f98ebf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 965728be60a5bd63fe324c32a2e72c487c9871a0d71778dca58bae6588dc1bbf33ff9beb1c9de6899fde75b3ec1d6bad1a0a9c61de384f25bb8c55cda7ca0224
|
7
|
+
data.tar.gz: 6dca302b72068a256a70c4b61bc0498b532c67348af7df9585aaa7781ff0809fea5b76a0224d2042916422df042c60136b10699f6a583ccfdcaf9500b6ec0635
|
data/CHANGELOG.md
CHANGED
@@ -9,28 +9,6 @@ module ActiveRecordExtensions
|
|
9
9
|
establish_connection("#{key}_#{Rails.env}")
|
10
10
|
end
|
11
11
|
|
12
|
-
def enum_int(field, values, options = {})
|
13
|
-
const_set("#{field.to_s.upcase}_OPTIONS", values)
|
14
|
-
|
15
|
-
select_options = values.map.with_index{|v, i| [v.to_s.humanize, i]}
|
16
|
-
const_set("#{field.to_s.upcase}_SELECT_OPTIONS", select_options)
|
17
|
-
|
18
|
-
values.each.with_index do |value, i|
|
19
|
-
const_set("#{field.to_s.upcase}_#{value.to_s.upcase}", i)
|
20
|
-
method_name = options[:short_name] ? "#{value}?" : "#{field}_#{value}?"
|
21
|
-
class_eval <<-ENUM
|
22
|
-
def #{method_name}
|
23
|
-
#{field} == #{i}
|
24
|
-
end
|
25
|
-
ENUM
|
26
|
-
end
|
27
|
-
class_eval <<-ENUM
|
28
|
-
def #{field}_name
|
29
|
-
#{field.to_s.upcase}_OPTIONS[#{field}]
|
30
|
-
end
|
31
|
-
ENUM
|
32
|
-
end
|
33
|
-
|
34
12
|
def optional_fields(*possible_fields)
|
35
13
|
@optional_fields_loader = possible_fields.pop if possible_fields.last.is_a?(Proc)
|
36
14
|
|
@@ -22,52 +22,6 @@ describe "optional_fields" do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
describe 'enum_int' do
|
26
|
-
let(:model_class) {
|
27
|
-
Class.new(ActiveRecord::Base) do
|
28
|
-
enum_int :category_id, %w(one two thr)
|
29
|
-
end
|
30
|
-
}
|
31
|
-
before do
|
32
|
-
connect_to_sqlite
|
33
|
-
stub_const 'Model', model_class
|
34
|
-
end
|
35
|
-
let(:one) { Model.new(category_id: 'one') }
|
36
|
-
|
37
|
-
it 'should define constants' do
|
38
|
-
expect(Model::CATEGORY_ID_OPTIONS).to eq %w(one two thr)
|
39
|
-
expect(Model::CATEGORY_ID_ONE).to eq 0
|
40
|
-
expect(Model::CATEGORY_ID_TWO).to eq 1
|
41
|
-
expect(Model::CATEGORY_ID_THR).to eq 2
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'should define methods' do
|
45
|
-
expect(one.category_id_one?).to be true
|
46
|
-
expect(one.category_id_two?).to be false
|
47
|
-
expect(one.category_id_thr?).to be false
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should define select options' do
|
51
|
-
expect(Model::CATEGORY_ID_SELECT_OPTIONS).to eq([
|
52
|
-
['One', 0], ['Two', 1], ['Thr', 2]
|
53
|
-
])
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'when short name' do
|
57
|
-
let(:model_class) {
|
58
|
-
Class.new(ActiveRecord::Base) do
|
59
|
-
enum_int :category_id, %w(one two thr), short_name: true
|
60
|
-
end
|
61
|
-
}
|
62
|
-
|
63
|
-
it 'should define methods' do
|
64
|
-
expect(one.one?).to be true
|
65
|
-
expect(one.two?).to be false
|
66
|
-
expect(one.thr?).to be false
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
25
|
describe RailsCoreExtensions::ActionControllerSortable do
|
72
26
|
class NormalController < ActionController::Base
|
73
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_core_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Noack
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-12-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|