code-box 1.1.2 → 2.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b5afe4ddbba5d1d56cbc3138bf18f2f90362bbe847c1012f70f4e20246d6605b
4
+ data.tar.gz: d193e966b4d7aad65ac25e03ebe8b7c4ccebcf17b5581b292840b12118c93540
5
+ SHA512:
6
+ metadata.gz: 53f339272afdd05eb062555f81a9a145308d060eaef3252cca5bd5e66c9526191b616332d07d1eeb6871c2a7972b714d6474ade829e2f075a582110117a9ab4a
7
+ data.tar.gz: 5d80e4739ef4722b273e34ae6321e40d9c3e3e684587b797437ad3bd10931ec64237e36809f2757c97a9cd608ccc933b2d79d1e94ee22d9ec322e7115ad0cab7
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-1.9.3-p362
1
+ ruby-2.7.4
data/Gemfile.lock CHANGED
@@ -1,44 +1,41 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-box (1.1.2)
4
+ code-box (1.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activemodel (4.0.0)
10
- activesupport (= 4.0.0)
11
- builder (~> 3.1.0)
12
- activerecord (4.0.0)
13
- activemodel (= 4.0.0)
14
- activerecord-deprecated_finders (~> 1.0.2)
15
- activesupport (= 4.0.0)
16
- arel (~> 4.0.0)
17
- activerecord-deprecated_finders (1.0.3)
18
- activesupport (4.0.0)
19
- i18n (~> 0.6, >= 0.6.4)
20
- minitest (~> 4.2)
21
- multi_json (~> 1.3)
22
- thread_safe (~> 0.1)
23
- tzinfo (~> 0.3.37)
24
- arel (4.0.0)
25
- atomic (1.1.14)
26
- builder (3.1.4)
27
- i18n (0.6.5)
28
- minitest (4.7.5)
29
- multi_json (1.8.0)
30
- rake (10.1.0)
31
- sqlite3 (1.3.8)
32
- thread_safe (0.1.3)
33
- atomic
34
- tzinfo (0.3.37)
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)
22
+ concurrent-ruby (~> 1.0)
23
+ minitest (5.17.0)
24
+ rake (13.0.6)
25
+ sqlite3 (1.6.0-x86_64-darwin)
26
+ tzinfo (2.0.5)
27
+ concurrent-ruby (~> 1.0)
35
28
 
36
29
  PLATFORMS
37
- ruby
30
+ x86_64-darwin-21
38
31
 
39
32
  DEPENDENCIES
40
- activerecord (~> 4.0)
33
+ activerecord (~> 7.0)
34
+ bigdecimal
41
35
  code-box!
42
36
  minitest
43
37
  rake
44
38
  sqlite3
39
+
40
+ BUNDLED WITH
41
+ 2.4.1
data/code-box.gemspec CHANGED
@@ -3,8 +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
9
 
9
10
  gem.authors = ["Martin Schweizer"]
10
11
  gem.email = ["contact@verticonaut.me"]
@@ -12,15 +13,15 @@ Gem::Specification.new do |gem|
12
13
  gem.summary = %q{Specify attributes as code and provide lookup by I18n-, cache- or associated and support for building code classes.}
13
14
  gem.homepage = %q{http://github.com/verticonaut/code-box}
14
15
 
15
- gem.add_development_dependency "activerecord", "~> 4.0"
16
+ gem.add_development_dependency "activerecord", "~> 7.0"
16
17
  gem.add_development_dependency "sqlite3"
17
18
  gem.add_development_dependency "rake"
18
19
  gem.add_development_dependency "minitest"
20
+ gem.add_development_dependency "bigdecimal"
19
21
 
20
22
  gem.files = `git ls-files`.split($\)
21
23
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
22
24
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
23
25
  gem.require_paths = ["lib"]
24
- gem.rdoc_options << '--charset' << 'UTF-8' << '--line-numbers'
26
+ gem.rdoc_options << "--charset" << "UTF-8" << "--line-numbers"
25
27
  end
26
-
@@ -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
@@ -69,7 +69,9 @@ module CodeBox
69
69
  class_eval <<-RUBY_
70
70
  # getter
71
71
  def #{code_name}
72
- codes = #{code_attr_name}.split(',').map(&:strip)
72
+ code_value = #{code_attr_name}
73
+ return [] if code_value.nil?
74
+ codes = code_value.split(',').map(&:strip)
73
75
  codes.map{ |code| #{code_class_name}.for_code(code) }
74
76
  end
75
77
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module CodeBox
4
- VERSION = "1.1.2"
4
+ VERSION = "2.0.pre1"
5
5
  end
@@ -69,6 +69,7 @@ class TestActsAsCode < MiniTest::Unit::TestCase
69
69
 
70
70
  def test_code_translation
71
71
  code = Codes::CivilStatus.new('married')
72
+ I18n.locale = :en
72
73
 
73
74
  assert_equal code.translated_code, 'married'
74
75
  assert_equal code.translated_code(:de), 'verheiratet'
@@ -80,27 +81,27 @@ class TestActsAsCode < MiniTest::Unit::TestCase
80
81
 
81
82
  options_array = Codes::CivilStatus.build_select_options(include_empty: true)
82
83
  assert_equal options_array.size, 3
83
- assert_equal options_array.first[1], nil
84
+ assert_equal options_array.first[1], nil
84
85
  end
85
86
 
86
87
  def test_options_building_with_text_label
87
88
  options_array = Codes::CivilStatus.build_select_options(include_empty: { label: 'MyLabel' })
88
89
  assert_equal options_array.size, 3
89
- assert_equal options_array.first[0], 'MyLabel'
90
- assert_equal options_array.first[1], nil
90
+ assert_equal options_array.first[0], 'MyLabel'
91
+ assert_equal options_array.first[1], nil
91
92
  end
92
93
 
93
94
  def test_options_building_with_custom_value
94
95
  options_array = Codes::CivilStatus.build_select_options(include_empty: { value: 'all' })
95
96
  assert_equal options_array.size, 3
96
- assert_equal options_array.first[1], 'all'
97
+ assert_equal options_array.first[1], 'all'
97
98
  end
98
99
 
99
100
  def test_options_building_with_custom_label_and_value
100
101
  options_array = Codes::CivilStatus.build_select_options(include_empty: { label: 'Yaiii', value: 'all' })
101
102
  assert_equal options_array.size, 3
102
- assert_equal options_array.first[0], 'Yaiii'
103
- assert_equal options_array.first[1], 'all'
103
+ assert_equal options_array.first[0], 'Yaiii'
104
+ assert_equal options_array.first[1], 'all'
104
105
  end
105
106
 
106
107
  end
@@ -98,6 +98,8 @@ class TestCodeAttribute <MiniTest::Unit::TestCase
98
98
 
99
99
  # :type => :associated ----------------------------------------------------------------
100
100
  def test_code_attribute_lookup_associated
101
+ Codes::Country.delete_all
102
+
101
103
  code_ch = Codes::Country.create(:code => 'CH', :name => 'Switzerland')
102
104
  code_de = Codes::Country.create(:code => 'DE', :name => 'Germany')
103
105
 
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,78 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-box
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
5
- prerelease:
4
+ version: 2.0.pre1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Martin Schweizer
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-12-05 00:00:00.000000000 Z
11
+ date: 2023-01-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '4.0'
19
+ version: '7.0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '4.0'
26
+ version: '7.0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: sqlite3
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: minitest
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bigdecimal
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
76
81
  - !ruby/object:Gem::Version
77
82
  version: '0'
78
83
  description: Specify attributes as code and provide lookup by I18n-, cache- or associated
@@ -83,9 +88,9 @@ executables: []
83
88
  extensions: []
84
89
  extra_rdoc_files: []
85
90
  files:
86
- - .gitignore
87
- - .ruby-version
88
- - .travis.yml
91
+ - ".gitignore"
92
+ - ".ruby-version"
93
+ - ".travis.yml"
89
94
  - Gemfile
90
95
  - Gemfile.lock
91
96
  - LICENSE
@@ -107,37 +112,30 @@ files:
107
112
  - test/resources/models.rb
108
113
  - test/resources/schema.rb
109
114
  homepage: http://github.com/verticonaut/code-box
110
- licenses: []
111
- post_install_message:
115
+ licenses:
116
+ - BSD-2-Clause
117
+ metadata: {}
118
+ post_install_message:
112
119
  rdoc_options:
113
- - --charset
120
+ - "--charset"
114
121
  - UTF-8
115
- - --line-numbers
122
+ - "--line-numbers"
116
123
  require_paths:
117
124
  - lib
118
125
  required_ruby_version: !ruby/object:Gem::Requirement
119
- none: false
120
126
  requirements:
121
- - - ! '>='
127
+ - - ">="
122
128
  - !ruby/object:Gem::Version
123
129
  version: '0'
124
- segments:
125
- - 0
126
- hash: -2951990761497190642
127
130
  required_rubygems_version: !ruby/object:Gem::Requirement
128
- none: false
129
131
  requirements:
130
- - - ! '>='
132
+ - - ">"
131
133
  - !ruby/object:Gem::Version
132
- version: '0'
133
- segments:
134
- - 0
135
- hash: -2951990761497190642
134
+ version: 1.3.1
136
135
  requirements: []
137
- rubyforge_project:
138
- rubygems_version: 1.8.23
139
- signing_key:
140
- specification_version: 3
136
+ rubygems_version: 3.3.8
137
+ signing_key:
138
+ specification_version: 4
141
139
  summary: Specify attributes as code and provide lookup by I18n-, cache- or associated
142
140
  and support for building code classes.
143
141
  test_files: