code-box 1.1.3 → 2.0.pre1

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: 00d38d11fd72eecfe95c9addc855d4ddaf964663342e4e8f46822fda84518f67
4
- data.tar.gz: 0131057470abd1e47400b93b812e712c5adc3e1a291a84003624e7ab5519b647
3
+ metadata.gz: b5afe4ddbba5d1d56cbc3138bf18f2f90362bbe847c1012f70f4e20246d6605b
4
+ data.tar.gz: d193e966b4d7aad65ac25e03ebe8b7c4ccebcf17b5581b292840b12118c93540
5
5
  SHA512:
6
- metadata.gz: db8c592630921f36d79000ae7c2062644fe112d33b3afec5c7b4d5d8b17881d038becf40fcfcadc9cf59eda1fc58206dcb88e2c4432294fa72dbc751f13e9563
7
- data.tar.gz: 83379416834c3d6b237b1ea0399454d54cb828bde2b7afd020c34d21d9570f0b2f7d525977e18b4094ca011bf94fba376ccf7326435829ab8c455d96539c586f
6
+ metadata.gz: 53f339272afdd05eb062555f81a9a145308d060eaef3252cca5bd5e66c9526191b616332d07d1eeb6871c2a7972b714d6474ade829e2f075a582110117a9ab4a
7
+ data.tar.gz: 5d80e4739ef4722b273e34ae6321e40d9c3e3e684587b797437ad3bd10931ec64237e36809f2757c97a9cd608ccc933b2d79d1e94ee22d9ec322e7115ad0cab7
data/Gemfile.lock CHANGED
@@ -6,41 +6,36 @@ PATH
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activemodel (4.2.11.3)
10
- activesupport (= 4.2.11.3)
11
- builder (~> 3.1)
12
- activerecord (4.2.11.3)
13
- activemodel (= 4.2.11.3)
14
- activesupport (= 4.2.11.3)
15
- arel (~> 6.0)
16
- activesupport (4.2.11.3)
17
- i18n (~> 0.7)
18
- minitest (~> 5.1)
19
- thread_safe (~> 0.3, >= 0.3.4)
20
- tzinfo (~> 1.1)
21
- arel (6.0.4)
22
- bigdecimal (1.4.4)
23
- builder (3.2.4)
24
- concurrent-ruby (1.1.9)
25
- i18n (0.9.5)
9
+ activemodel (7.0.4.1)
10
+ activesupport (= 7.0.4.1)
11
+ activerecord (7.0.4.1)
12
+ activemodel (= 7.0.4.1)
13
+ activesupport (= 7.0.4.1)
14
+ activesupport (7.0.4.1)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ tzinfo (~> 2.0)
19
+ bigdecimal (3.1.3)
20
+ concurrent-ruby (1.1.10)
21
+ i18n (1.12.0)
26
22
  concurrent-ruby (~> 1.0)
27
- minitest (5.15.0)
23
+ minitest (5.17.0)
28
24
  rake (13.0.6)
29
- sqlite3 (1.3.13)
30
- thread_safe (0.3.6)
31
- tzinfo (1.2.9)
32
- thread_safe (~> 0.1)
25
+ sqlite3 (1.6.0-x86_64-darwin)
26
+ tzinfo (2.0.5)
27
+ concurrent-ruby (~> 1.0)
33
28
 
34
29
  PLATFORMS
35
30
  x86_64-darwin-21
36
31
 
37
32
  DEPENDENCIES
38
- activerecord (~> 4.0)
39
- bigdecimal (~> 1.4.4)
33
+ activerecord (~> 7.0)
34
+ bigdecimal
40
35
  code-box!
41
36
  minitest
42
37
  rake
43
- sqlite3 (~> 1.3.6)
38
+ sqlite3
44
39
 
45
40
  BUNDLED WITH
46
- 2.3.8
41
+ 2.4.1
data/code-box.gemspec CHANGED
@@ -3,9 +3,9 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require File.expand_path('../lib/code-box/version', __FILE__)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
- gem.name = 'code-box'
6
+ gem.name = "code-box"
7
7
  gem.version = CodeBox::VERSION
8
- gem.license = 'BSD-2-Clause'
8
+ gem.license = "BSD-2-Clause"
9
9
 
10
10
  gem.authors = ["Martin Schweizer"]
11
11
  gem.email = ["contact@verticonaut.me"]
@@ -13,16 +13,15 @@ Gem::Specification.new do |gem|
13
13
  gem.summary = %q{Specify attributes as code and provide lookup by I18n-, cache- or associated and support for building code classes.}
14
14
  gem.homepage = %q{http://github.com/verticonaut/code-box}
15
15
 
16
- gem.add_development_dependency "activerecord", "~> 4.0"
17
- gem.add_development_dependency "sqlite3", "~> 1.3.6"
16
+ gem.add_development_dependency "activerecord", "~> 7.0"
17
+ gem.add_development_dependency "sqlite3"
18
18
  gem.add_development_dependency "rake"
19
19
  gem.add_development_dependency "minitest"
20
- gem.add_development_dependency "bigdecimal", "~> 1.4.4"
20
+ gem.add_development_dependency "bigdecimal"
21
21
 
22
22
  gem.files = `git ls-files`.split($\)
23
23
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
24
24
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
25
25
  gem.require_paths = ["lib"]
26
- gem.rdoc_options << '--charset' << 'UTF-8' << '--line-numbers'
26
+ gem.rdoc_options << "--charset" << "UTF-8" << "--line-numbers"
27
27
  end
28
-
@@ -1,5 +1,4 @@
1
-
2
- # encoding: utf-8
1
+ # frozen_string_literal: true
3
2
 
4
3
  module CodeBox
5
4
 
@@ -34,8 +33,8 @@ module CodeBox
34
33
  instance_eval <<-RUBY_
35
34
  class << base
36
35
  def _code_box_i18n_model_segment
37
- return CodeBox.i18n_model_segment if "#{self._code_box_i18n_model_segment}".empty?
38
- "#{self._code_box_i18n_model_segment}"
36
+ return CodeBox.i18n_model_segment if "#{_code_box_i18n_model_segment}".empty?
37
+ "#{_code_box_i18n_model_segment}"
39
38
  end
40
39
  end
41
40
  RUBY_
@@ -47,11 +46,11 @@ module CodeBox
47
46
 
48
47
  module ClassMethods
49
48
  DefaultOptions = {
50
- code_attribute: 'code',
51
- sti: false,
52
- uniqueness_case_sensitive: true,
53
- position_attr: :position,
54
- define_test_methods: true,
49
+ code_attribute: "code",
50
+ sti: false,
51
+ uniqueness_case_sensitive: true,
52
+ position_attr: :position,
53
+ define_test_methods: true,
55
54
  }
56
55
 
57
56
  def acts_as_code(*codes_and_or_options)
@@ -63,7 +62,7 @@ module CodeBox
63
62
  case_sensitive = opts[:uniqueness_case_sensitive]
64
63
  define_test_methods = opts[:define_test_methods]
65
64
 
66
- model_type = self.ancestors.include?('ActiveRecord::Base'.constantize) ? :active_record : :poro
65
+ model_type = ancestors.include?("ActiveRecord::Base".constantize) ? :active_record : :poro
67
66
 
68
67
  class_eval <<-RUBY_
69
68
  def translated_#{code_attr}(locale = I18n.locale, *options)
@@ -123,7 +122,7 @@ module CodeBox
123
122
  # If starts with 'i18n.' it is considered an I18n key, else the label itself
124
123
  options = translate_#{code_attr}(codes, build: :zip)
125
124
  if include_empty
126
- label = I18n.t(label[5..-1], locale: locale) if label.starts_with?('i18n.')
125
+ label = I18n.t(label[5..-1], locale: locale) if label.start_with?('i18n.')
127
126
  options.unshift [label, value]
128
127
  end
129
128
 
@@ -138,7 +137,7 @@ module CodeBox
138
137
  instance_eval <<-CODE
139
138
  class << self
140
139
  def _code_box_code_attr_name
141
- '#{code_attr.to_s}'
140
+ code_attr.to_s
142
141
  end
143
142
 
144
143
  def code_cache
@@ -155,7 +154,7 @@ module CodeBox
155
154
  when :active_record
156
155
 
157
156
  order_expression = if self.attribute_names.include?(position_attr) then
158
- "coalesce(#{position_attr.to_s}, #{code_attr.to_s})"
157
+ "coalesce(#{position_attr}, #{code_attr})"
159
158
  else
160
159
  code_attr.to_s
161
160
  end
@@ -168,7 +167,7 @@ module CodeBox
168
167
  CODE
169
168
 
170
169
  when :poro
171
- order_attr = position_attr ? position_attr.to_s : code_attr.to_s
170
+ _order_attr = position_attr ? position_attr.to_s : code_attr.to_s
172
171
 
173
172
  class_eval <<-CODE
174
173
  attr_accessor :#{code_attr}
@@ -202,11 +201,11 @@ module CodeBox
202
201
 
203
202
  def define_codes(*codes, define_test_methods)
204
203
  # --- Define the code constants...
205
- code_attr = self._code_box_code_attr_name
206
- model_type = self.ancestors.include?('ActiveRecord::Base'.constantize) ? :active_record : :poro
204
+ code_attr = _code_box_code_attr_name
205
+ model_type = ancestors.include?("ActiveRecord::Base".constantize) ? :active_record : :poro
207
206
 
208
207
  module_name = code_attr.pluralize.camelize
209
- codes_module = const_set(module_name, Module.new)
208
+ codes_module = const_set(module_name, Module.new)
210
209
 
211
210
  # Create a constant for each code
212
211
  constants = {}
@@ -216,7 +215,7 @@ module CodeBox
216
215
  constants[constant_name] = constant
217
216
  end
218
217
 
219
- codes_module.const_set('All', constants.values.compact)
218
+ codes_module.const_set("All", constants.values.compact)
220
219
 
221
220
 
222
221
  # Define test methods for each code like e.g.
@@ -243,12 +242,12 @@ module CodeBox
243
242
 
244
243
  constants = {}
245
244
  codes.each do |code|
246
- constant_name = "#{code.to_s.camelize}"
247
- constant = const_set(constant_name, self.new(code.to_s))
245
+ constant_name = code.to_s.camelize
246
+ constant = const_set(constant_name, new(code.to_s))
248
247
  constants[constant_name] = constant
249
248
  end
250
249
 
251
- const_set('All', constants.values.compact)
250
+ const_set("All", constants.values.compact)
252
251
 
253
252
  class_eval <<-CODE
254
253
  def self.all
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module CodeBox
4
- VERSION = "1.1.3"
4
+ VERSION = "2.0.pre1"
5
5
  end
data/test/helper.rb CHANGED
@@ -8,14 +8,12 @@ require 'logger'
8
8
  # Setup AR environment
9
9
  # ------------------------------------------------------
10
10
 
11
- # Define connection info
12
- ActiveRecord::Base.configurations = {
13
- "test" => {
14
- :adapter => 'sqlite3',
15
- :database => ':memory:'
11
+ ActiveRecord::Base.establish_connection(
12
+ {
13
+ adapter: "sqlite3",
14
+ database: ":memory:",
16
15
  }
17
- }
18
- ActiveRecord::Base.establish_connection("test")
16
+ )
19
17
 
20
18
  # Setup logger
21
19
  tmp = File.expand_path('../../tmp', __FILE__)
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # ------------------------------------------------------
2
4
  # Defined the respective AR Models
3
5
  # ------------------------------------------------------
4
6
  module Codes
5
-
6
7
  class SampleClass < ActiveRecord::Base
7
8
  self.table_name = :codes_sample_class
8
9
 
@@ -10,23 +11,23 @@ module Codes
10
11
 
11
12
  # i18n codes
12
13
  code_attribute :gender
13
- code_attribute :country, :lookup_type => :i18n, :code_attribute_suffix => 'iso'
14
+ code_attribute :country, lookup_type: :i18n, code_attribute_suffix: "iso"
14
15
 
15
16
  # lookup codes
16
- code_attribute :civil_status, :lookup_type => :lookup, :class_name => 'Codes::CivilStatus'
17
- code_attribute :ager_type, :lookup_type => :lookup, :foreign_code_attribute => 'code_id'
17
+ code_attribute :civil_status, lookup_type: :lookup, class_name: "Codes::CivilStatus"
18
+ code_attribute :ager_type, lookup_type: :lookup, foreign_code_attribute: "code_id"
18
19
 
19
- code_attribute :country_2, :lookup_type => :associated, :class_name => 'Codes::Country'
20
+ code_attribute :country_2, lookup_type: :associated, class_name: "Codes::Country"
20
21
 
21
- code_attribute :countries, :lookup_type => :lookup, :class_name => 'Codes::Country', :enum => :set
22
+ code_attribute :countries, lookup_type: :lookup, class_name: "Codes::Country", enum: :set
22
23
  end
23
24
 
24
25
  class CivilStatus
25
- include CodeBox::ActsAsCode['single', 'married', :type => :poro]
26
+ include CodeBox::ActsAsCode["single", "married", type: :poro]
26
27
  end
27
28
 
28
29
  class CivilStatusUseDefine
29
- include CodeBox::ActsAsCode[:type => :poro]
30
+ include CodeBox::ActsAsCode[type: :poro]
30
31
 
31
32
  define_codes(:single, :married)
32
33
  end
@@ -53,23 +54,22 @@ module Codes
53
54
  self.table_name = :codes_country
54
55
 
55
56
  def self.for_code(code)
56
- where('code= ?', code).first
57
+ where("code= ?", code).first
57
58
  end
58
59
  end
59
60
 
60
61
 
61
62
  class ArCode < ActiveRecord::Base
62
63
  self.table_name = :codes_ar_code
63
- include CodeBox::ActsAsCode[:type => :active_record]
64
+ include CodeBox::ActsAsCode[type: :active_record]
64
65
  end
65
66
 
66
67
  class SegmentModel
67
- include CodeBox::CodeAttribute[:i18n_model_segment => :model]
68
+ include CodeBox::CodeAttribute[i18n_model_segment: :model]
68
69
 
69
70
  attr_accessor :gender_code
70
71
 
71
72
  # i18n codes
72
73
  code_attribute :gender
73
74
  end
74
-
75
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-box
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 2.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Schweizer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-10 00:00:00.000000000 Z
11
+ date: 2023-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '7.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '7.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sqlite3
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.3.6
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.3.6
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: bigdecimal
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 1.4.4
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 1.4.4
82
+ version: '0'
83
83
  description: Specify attributes as code and provide lookup by I18n-, cache- or associated
84
84
  and support for building code classes.
85
85
  email:
@@ -129,9 +129,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  requirements:
132
- - - ">="
132
+ - - ">"
133
133
  - !ruby/object:Gem::Version
134
- version: '0'
134
+ version: 1.3.1
135
135
  requirements: []
136
136
  rubygems_version: 3.3.8
137
137
  signing_key: