onoma 0.2.2 → 0.4.1

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.
Files changed (154) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -0
  3. data/.gitlab-ci.yml +14 -0
  4. data/Gemfile +2 -0
  5. data/Rakefile +3 -6
  6. data/bin/rake +29 -0
  7. data/config/locales/arb.yml +77 -293
  8. data/config/locales/cmn.yml +69 -193
  9. data/config/locales/deu.yml +61 -1113
  10. data/config/locales/eng.yml +3146 -2987
  11. data/config/locales/fra.yml +629 -478
  12. data/config/locales/ita.yml +63 -1168
  13. data/config/locales/jpn.yml +80 -232
  14. data/config/locales/por.yml +63 -975
  15. data/config/locales/spa.yml +70 -616
  16. data/db/migrate/20170904223101_add_cultivable_zone_registry.xml +4 -0
  17. data/db/migrate/20171106085357_update_account_numbers.xml +431 -0
  18. data/db/migrate/20171212081801_add_fiscal_positions.xml +12 -0
  19. data/db/migrate/20180408190101_add_new_plant_variants.xml +7 -0
  20. data/db/migrate/20180409130101_add_common_crop.xml +4 -0
  21. data/db/migrate/20180418085027_add-hour-counter-indicator.xml +9 -0
  22. data/db/migrate/20180709134310_add_centralizing_field_to_accounts.xml +22 -0
  23. data/db/migrate/20180711093131_review_all_accounts_number_and_fallbacks.xml +431 -0
  24. data/db/migrate/20180806080646_edit_centralizing_field_accounts.xml +17 -0
  25. data/db/migrate/20180814184001_add_missing_categories.xml +12 -0
  26. data/db/migrate/20180907160001_edit_accounts_to_unlock_first_run.xml +21 -0
  27. data/db/migrate/20181004220301_add_journal_ledger.xml +4 -0
  28. data/db/migrate/20181205162401_add_intra_vat.xml +6 -0
  29. data/db/migrate/20181213153405_fix_accounting_systems.xml +7 -0
  30. data/db/migrate/20181217155149_fiscal_position_refers_to_accounting_system.xml +10 -0
  31. data/db/migrate/20181217173101_fiscal_position_reference_typo.xml +4 -0
  32. data/db/migrate/20190315154040_add_suspense_account.xml +4 -0
  33. data/db/migrate/20190326110849_add_asset_fixable_to_product_nature_categories.xml +25 -0
  34. data/db/migrate/20190326135443_change_product_nature_category_cultivable_zone_into_land.xml +21 -0
  35. data/db/migrate/20190329133808_change_land_fixed_assets_account_usage.xml +7 -0
  36. data/db/migrate/20190405120711_delete_land_sales_account_and_assign_land_parcels_sell_revenues_to_land.xml +5 -0
  37. data/db/migrate/20190412071057_add_new_fixed_assets_andn_depreciable_accounts.xml +22 -0
  38. data/db/migrate/20190509092804_add_account_exceptional_depreciations_imputations_expenses_for_fixed_assets.xml +4 -0
  39. data/db/migrate/20190514084753_add_approved_input_volume.xml +9 -0
  40. data/db/migrate/20190520072403_add_new_accounts.xml +58 -0
  41. data/db/migrate/20190521170601_add_missing_taxes.xml +7 -0
  42. data/db/migrate/20190611101014_change_deductible_vat_account.xml +5 -0
  43. data/db/migrate/20190620092151_fix_conflicts_in_new_accounts.xml +6 -0
  44. data/db/migrate/20190625152636_change_mixture_seed_product_nature_variant.xml +4 -0
  45. data/db/migrate/20190718130243_remove_services_expenses.xml +5 -0
  46. data/db/migrate/20190801142431_remove_accounts_from_pcg82.xml +5 -0
  47. data/db/migrate/20190807125202_add_nature_to_product_natures.xml +326 -0
  48. data/db/migrate/20190823091727_fix-cubic-meter-per-hectare-symbol.xml +5 -0
  49. data/db/migrate/20190909150402_add_staff_supply_stock_account.xml +4 -0
  50. data/db/migrate/20190913102036_add_caliber_indicator.xml +4 -0
  51. data/db/migrate/20190917161215_add_missing_mass_area_density_units.xml +21 -0
  52. data/db/migrate/20190917161216_update_quintal_symbol.xml +4 -0
  53. data/db/migrate/20190917161217_adds_more_info_to_units.xml +133 -0
  54. data/db/migrate/20190918074757_add_new_accounts.xml +8 -0
  55. data/db/migrate/20191001122750_add_accounts_fixed_assets_related.xml +10 -0
  56. data/db/migrate/20191016152118_add_missing_document_templates.xml +6 -0
  57. data/db/migrate/20191028175001_add_short_balance_sheet.xml +4 -0
  58. data/db/migrate/20191029131921_add_vine_equipments.xml +117 -0
  59. data/db/migrate/20191112132413_remove_roller_from_product_natures.xml +5 -0
  60. data/db/migrate/20191113134626_add_nature_to_new_product_natures.xml +11 -0
  61. data/db/migrate/20191125133327_add_missing_units_and_indicators.xml +5 -0
  62. data/db/migrate/20200107095554_add_signed_field_to_document_nature.xml +9 -0
  63. data/db/migrate/20200305160358_add_varieties_for_phytosanitary.xml +11 -0
  64. data/db/migrate/20200421123503_add_type_to_categories_and_variants.xml +1136 -0
  65. data/db/migrate/20200514092205_add_liter_per_hectoliter_unit.xml +4 -0
  66. data/db/migrate/20200722091859_triticale_derivative_of.xml +5 -0
  67. data/db/reference.xml +1934 -1676
  68. data/lib/onoma.rb +82 -24
  69. data/lib/onoma/item.rb +19 -3
  70. data/lib/onoma/migration/actions/base.rb +1 -5
  71. data/lib/onoma/migration/actions/item_change.rb +1 -5
  72. data/lib/onoma/migration/actions/item_creation.rb +2 -6
  73. data/lib/onoma/migration/actions/item_merging.rb +1 -5
  74. data/lib/onoma/migration/actions/item_removal.rb +1 -1
  75. data/lib/onoma/migration/actions/nomenclature_change.rb +1 -1
  76. data/lib/onoma/migration/actions/nomenclature_creation.rb +1 -1
  77. data/lib/onoma/migration/actions/nomenclature_removal.rb +1 -5
  78. data/lib/onoma/migration/actions/property_creation.rb +4 -4
  79. data/lib/onoma/migration/base.rb +38 -0
  80. data/lib/onoma/migrator.rb +13 -0
  81. data/lib/onoma/migrator/reference.rb +71 -0
  82. data/lib/onoma/migrator/translation.rb +76 -0
  83. data/lib/onoma/models/ability.rb +4 -0
  84. data/lib/onoma/models/account.rb +4 -0
  85. data/lib/onoma/models/accounting_system.rb +12 -0
  86. data/lib/onoma/models/activity_family.rb +4 -0
  87. data/lib/onoma/models/administrative_area.rb +4 -0
  88. data/lib/onoma/models/administrative_area_nature.rb +4 -0
  89. data/lib/onoma/models/analysis_nature.rb +4 -0
  90. data/lib/onoma/models/animal_life_state.rb +4 -0
  91. data/lib/onoma/models/cation_exchange_capacity_analysis_method.rb +4 -0
  92. data/lib/onoma/models/certification.rb +4 -0
  93. data/lib/onoma/models/certification_label.rb +4 -0
  94. data/lib/onoma/models/chemical_classification.rb +4 -0
  95. data/lib/onoma/models/chemical_element.rb +4 -0
  96. data/lib/onoma/models/country.rb +4 -0
  97. data/lib/onoma/models/crop_set.rb +4 -0
  98. data/lib/onoma/models/currency.rb +4 -0
  99. data/lib/onoma/models/delivery_mode.rb +4 -0
  100. data/lib/onoma/models/dimension.rb +4 -0
  101. data/lib/onoma/models/document_category.rb +4 -0
  102. data/lib/onoma/models/document_nature.rb +4 -0
  103. data/lib/onoma/models/entity_link_nature.rb +4 -0
  104. data/lib/onoma/models/event_nature.rb +4 -0
  105. data/lib/onoma/models/fence_perimeter.rb +4 -0
  106. data/lib/onoma/models/figure.rb +4 -0
  107. data/lib/onoma/models/fiscal_position.rb +4 -0
  108. data/lib/onoma/models/guide_nature.rb +4 -0
  109. data/lib/onoma/models/identifier_nature.rb +4 -0
  110. data/lib/onoma/models/indicator.rb +7 -0
  111. data/lib/onoma/models/issue_nature.rb +4 -0
  112. data/lib/onoma/models/land.rb +4 -0
  113. data/lib/onoma/models/language.rb +4 -0
  114. data/lib/onoma/models/mammalia_birth_condition.rb +4 -0
  115. data/lib/onoma/models/mammalia_reproduction_state.rb +4 -0
  116. data/lib/onoma/models/molecule.rb +4 -0
  117. data/lib/onoma/models/net_service.rb +4 -0
  118. data/lib/onoma/models/opportunity_origin.rb +4 -0
  119. data/lib/onoma/models/phosphorus_analysis_method.rb +4 -0
  120. data/lib/onoma/models/plant_life_state.rb +4 -0
  121. data/lib/onoma/models/plant_reproduction_state.rb +4 -0
  122. data/lib/onoma/models/plants_growth_level.rb +4 -0
  123. data/lib/onoma/models/procedure_action.rb +4 -0
  124. data/lib/onoma/models/procedure_category.rb +4 -0
  125. data/lib/onoma/models/procedure_nature.rb +4 -0
  126. data/lib/onoma/models/procedure_role.rb +4 -0
  127. data/lib/onoma/models/product_nature.rb +4 -0
  128. data/lib/onoma/models/product_nature_category.rb +4 -0
  129. data/lib/onoma/models/product_nature_variant.rb +4 -0
  130. data/lib/onoma/models/production_nature.rb +4 -0
  131. data/lib/onoma/models/production_system.rb +4 -0
  132. data/lib/onoma/models/production_usage.rb +4 -0
  133. data/lib/onoma/models/residue_elimination_method.rb +4 -0
  134. data/lib/onoma/models/role.rb +4 -0
  135. data/lib/onoma/models/running_cost.rb +4 -0
  136. data/lib/onoma/models/sex.rb +4 -0
  137. data/lib/onoma/models/soil_cultural_state.rb +4 -0
  138. data/lib/onoma/models/soil_nature.rb +4 -0
  139. data/lib/onoma/models/spatial_reference_system.rb +4 -0
  140. data/lib/onoma/models/tax.rb +4 -0
  141. data/lib/onoma/models/tax_nature.rb +4 -0
  142. data/lib/onoma/models/unit.rb +4 -0
  143. data/lib/onoma/models/variety.rb +31 -0
  144. data/lib/onoma/models/working_set.rb +4 -0
  145. data/lib/onoma/nomenclature.rb +19 -23
  146. data/lib/onoma/{database.rb → nomenclature_set.rb} +25 -57
  147. data/lib/onoma/{property.rb → property_nature.rb} +5 -8
  148. data/lib/onoma/record/base.rb +15 -0
  149. data/lib/onoma/reflection.rb +3 -3
  150. data/lib/onoma/version.rb +3 -1
  151. data/onoma.gemspec +19 -20
  152. metadata +156 -39
  153. data/lib/onoma/migration.rb +0 -122
  154. data/lib/onoma/migration/actions.rb +0 -9
@@ -0,0 +1,31 @@
1
+ module Onoma
2
+ class Variety < Onoma::Record::Base
3
+ TOPLEVEL_VARIETIES = %w[bioproduct immatter matter product product_group].freeze
4
+
5
+ class << self
6
+ def parent_variety(variety)
7
+ v = find(variety)
8
+
9
+ if v.nil?
10
+ nil
11
+ elsif (toplevel = toplevel_parent(v)).present?
12
+ toplevel.name
13
+ else
14
+ v.name
15
+ end
16
+ end
17
+
18
+ def toplevel_parent(variety)
19
+ ancestors(variety).last
20
+ end
21
+
22
+ def ancestors(variety)
23
+ if variety.parent.nil? || TOPLEVEL_VARIETIES.include?(variety.parent.name)
24
+ []
25
+ else
26
+ [variety.parent, *ancestors(variety.parent)]
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ module Onoma
2
+ class WorkingSet < Onoma::Record::Base
3
+ end
4
+ end
@@ -1,6 +1,3 @@
1
- require 'bigdecimal'
2
- require 'bigdecimal/util'
3
-
4
1
  module Onoma
5
2
  # This class represents a nomenclature
6
3
  class Nomenclature
@@ -12,10 +9,10 @@ module Onoma
12
9
  def initialize(name, options = {})
13
10
  @name = name.to_sym
14
11
  @set = options.delete(:set)
15
- @items = ActiveSupport::HashWithIndifferentAccess.new
12
+ @items = HashWithIndifferentAccess.new
16
13
  @forest_right = 0
17
14
  @roots = []
18
- @properties = ActiveSupport::HashWithIndifferentAccess.new
15
+ @properties = {}.with_indifferent_access
19
16
  @translateable = !options[:translateable].is_a?(FalseClass)
20
17
  @notions = options[:notions] || []
21
18
  end
@@ -116,7 +113,7 @@ module Onoma
116
113
  if element.has_attribute?('default')
117
114
  options[:default] = element.attr('default').to_sym
118
115
  end
119
- options[:required] = !!(element.attr('required').to_s != 'true')
116
+ options[:required] = element.attr('required').to_s == 'true'
120
117
  # options[:inherit] = !!(element.attr('inherit').to_s == 'true')
121
118
  if type == :list
122
119
  type = element.has_attribute?('nomenclature') ? :item_list : :choice_list
@@ -138,7 +135,7 @@ module Onoma
138
135
  raise MissingChoices, "[#{@name}] Property #{name} must have nomenclature as choices"
139
136
  end
140
137
  end
141
- unless Property::TYPES.include?(type)
138
+ unless Onoma::PROPERTY_TYPES.include?(type)
142
139
  raise ArgumentError, "Property #{name} type is unknown: #{type.inspect}"
143
140
  end
144
141
  add_property(name, type, options)
@@ -231,7 +228,7 @@ module Onoma
231
228
 
232
229
  # Add an property to the nomenclature
233
230
  def add_property(name, type, options = {})
234
- p = Property.new(self, name, type, options)
231
+ p = PropertyNature.new(self, name, type, options)
235
232
  if @properties[p.name]
236
233
  raise "Property #{p.name} is already defined in nomenclature #{@name}"
237
234
  end
@@ -248,11 +245,11 @@ module Onoma
248
245
  # Check properties
249
246
  @properties.values.each do |property|
250
247
  if property.choices_nomenclature && !property.inline_choices? && !Onoma[property.choices_nomenclature.to_s]
251
- raise InvalidProperty, "[#{name}] #{property.name} nomenclature property must refer to an existing nomenclature. Got #{property.choices_nomenclature.inspect}. Expecting: #{Onoma.names.inspect}"
248
+ raise InvalidPropertyNature, "[#{name}] #{property.name} nomenclature property must refer to an existing nomenclature. Got #{property.choices_nomenclature.inspect}. Expecting: #{Onoma.names.inspect}"
252
249
  end
253
250
  next unless property.type == :choice && property.default
254
251
  unless property.choices.include?(property.default)
255
- raise InvalidProperty, "The default choice #{property.default.inspect} is invalid (in #{name}##{property.name}). Pick one from #{property.choices.sort.inspect}."
252
+ raise InvalidPropertyNature, "The default choice #{property.default.inspect} is invalid (in #{name}##{property.name}). Pick one from #{property.choices.sort.inspect}."
256
253
  end
257
254
  end
258
255
 
@@ -283,7 +280,7 @@ module Onoma
283
280
  end
284
281
 
285
282
  def inspect
286
- "Nomen::#{name.to_s.classify}"
283
+ "Onoma::#{name.to_s.classify}"
287
284
  end
288
285
 
289
286
  def table_name
@@ -301,8 +298,7 @@ module Onoma
301
298
 
302
299
  # Return human name
303
300
  def human_name(options = {})
304
- I18n.translate("nomenclatures.#{name}.name",
305
- options.merge(default: ["labels.#{name}".to_sym, name.to_s.humanize]))
301
+ I18n.t("nomenclatures.#{Onoma.escape_key(name)}.name", options.merge(default: ["labels.#{Onoma.escape_key(name)}".to_sym, name.to_s.humanize]))
306
302
  end
307
303
  alias humanize human_name
308
304
 
@@ -370,7 +366,7 @@ module Onoma
370
366
 
371
367
  # Returns a list for select, without specified items
372
368
  def select_without(already_imported)
373
- ActiveSupport::Deprecation.warn 'Nomen::Nomenclature#select_without method is deprecated. Please use Nomen::Nomenclature#without method instead.'
369
+ ActiveSupport::Deprecation.warn 'Onoma::Nomenclature#select_without method is deprecated. Please use Onoma::Nomenclature#without method instead.'
374
370
  select_options = @items.values.collect do |item|
375
371
  [item.human_name, item.name.to_s] unless already_imported[item.name.to_s]
376
372
  end
@@ -401,7 +397,7 @@ module Onoma
401
397
  end
402
398
  alias item find
403
399
 
404
- # Return the Item for the given name. Raises Nomen::ItemNotFound if no item
400
+ # Return the Item for the given name. Raises Onoma::ItemNotFound if no item
405
401
  # found in nomenclature
406
402
  def find!(item_name)
407
403
  i = find(item_name)
@@ -412,7 +408,7 @@ module Onoma
412
408
  # Returns +true+ if an item exists in the nomenclature that matches the
413
409
  # name, or +false+ otherwise. The argument can take two forms:
414
410
  # * String/Symbol - Find an item with this primary name
415
- # * Nomen::Item - Find an item with the same name of the item
411
+ # * Onoma::Item - Find an item with the same name of the item
416
412
  def exists?(item)
417
413
  @items[item.respond_to?(:name) ? item.name : item].present?
418
414
  end
@@ -433,8 +429,8 @@ module Onoma
433
429
  end
434
430
 
435
431
  # List items with properties filtering
436
- def where(properties)
437
- list.select do |item|
432
+ def where(properties, collection = list)
433
+ collection.select do |item|
438
434
  valid = true
439
435
  properties.each do |name, value|
440
436
  item_value = item.property(name)
@@ -461,7 +457,7 @@ module Onoma
461
457
  def without(*names)
462
458
  excluded = names.flatten.compact.map(&:to_sym)
463
459
  list.reject do |item|
464
- excluded.include?(item.name)
460
+ excluded.include?(item.name.to_sym)
465
461
  end
466
462
  end
467
463
 
@@ -505,7 +501,7 @@ module Onoma
505
501
  if property = properties[name]
506
502
  if property.type == :choice || property.type == :item
507
503
  if value =~ /\,/
508
- raise InvalidProperty, 'A property nature of choice type cannot contain commas'
504
+ raise InvalidPropertyNature, 'A property nature of choice type cannot contain commas'
509
505
  end
510
506
  value = value.strip.to_sym
511
507
  elsif property.list?
@@ -513,14 +509,14 @@ module Onoma
513
509
  elsif property.type == :boolean
514
510
  value = (value == 'true' ? true : value == 'false' ? false : nil)
515
511
  elsif property.type == :decimal
516
- value = value.to_d
512
+ value = BigDecimal(value)
517
513
  elsif property.type == :integer
518
514
  value = value.to_i
519
515
  elsif property.type == :date
520
- value = (value.blank? ? nil : value.to_date)
516
+ value = (value.blank? ? nil : Date.parse(value))
521
517
  elsif property.type == :symbol
522
518
  unless value =~ /\A\w+\z/
523
- raise InvalidProperty, "A property '#{name}' must contains a symbol. /[a-z0-9_]/ accepted. No spaces. Got #{value.inspect}"
519
+ raise InvalidPropertyNature, "A property '#{name}' must contains a symbol. /[a-z0-9_]/ accepted. No spaces. Got #{value.inspect}"
524
520
  end
525
521
  value = value.to_sym
526
522
  end
@@ -1,27 +1,34 @@
1
1
  module Onoma
2
2
  # This class represents a set of nomenclature like the reference DB
3
- class Database
3
+ class NomenclatureSet
4
4
  attr_accessor :version
5
- attr_reader :path
6
5
 
7
- def initialize(path)
8
- @path = Pathname.new(path)
9
- @nomenclatures = ActiveSupport::HashWithIndifferentAccess.new
6
+ def initialize
7
+ @nomenclatures = {}.with_indifferent_access
10
8
  @version = 0
11
9
  end
12
10
 
13
- def self.open(path)
14
- db = new(path)
15
- db.send(:parse_file, path) if path.exist?
16
- db
17
- end
18
-
19
- def write
20
- File.write(@path, to_xml)
11
+ def load_data_from_xml(nomenclature_name)
12
+ Rails.logger.info "Loading #{nomenclature_name}..."
13
+ start = Time.now
14
+ element = Onoma.reference_document.xpath("/xmlns:nomenclatures/xmlns:nomenclature[@name='#{nomenclature_name}']")
15
+ nomenclature = harvest_nomenclature(element)
16
+ Rails.logger.info "Loaded #{nomenclature_name} in #{(Time.now - start).round(2)} seconds..."
17
+ nomenclature
21
18
  end
22
19
 
23
- def copy(path)
24
- File.write(path, to_xml)
20
+ def self.load_file(file)
21
+ set = new
22
+ f = File.open(file, 'rb')
23
+ document = Nokogiri::XML(f) do |config|
24
+ config.strict.nonet.noblanks.noent
25
+ end
26
+ f.close
27
+ document.root.children.each do |nomenclature|
28
+ set.harvest_nomenclature(nomenclature)
29
+ end
30
+ set.version = document.root['version'].to_i
31
+ set
25
32
  end
26
33
 
27
34
  def nomenclature_names
@@ -105,29 +112,9 @@ module Onoma
105
112
  builder.to_xml
106
113
  end
107
114
 
108
- def exec_action(action)
109
- case action.action_name.to_sym
110
- when :nomenclature_creation
111
- add_nomenclature(action.name, action.options)
112
- when :nomenclature_change
113
- change_nomenclature(action.nomenclature, action.changes)
114
- when :nomenclature_removal
115
- remove_nomenclature(action.nomenclature)
116
- when :property_creation
117
- add_property(action.nomenclature, action.name, action.type, action.options)
118
- when :property_change
119
- add_property(action.nomenclature, action.name, action.changes)
120
- when :item_creation
121
- add_item(action.nomenclature, action.name, action.options)
122
- when :item_change
123
- change_item(action.nomenclature, action.name, action.changes)
124
- when :item_merging
125
- merge_item(action.nomenclature, action.name, action.into)
126
- when :item_removal
127
- remove_item(action.nomenclature, action.name)
128
- else
129
- raise "Unknown action: #{action.action_name}"
130
- end
115
+ def harvest_nomenclature(element)
116
+ nomenclature = Nomenclature.harvest(element, set: self)
117
+ @nomenclatures[nomenclature.name] = nomenclature
131
118
  end
132
119
 
133
120
  def add_nomenclature(name, options = {})
@@ -193,24 +180,5 @@ module Onoma
193
180
  nomenclature = find!(nomenclature_name)
194
181
  nomenclature.remove_item(item_name)
195
182
  end
196
-
197
- protected
198
-
199
- def harvest_nomenclature(element)
200
- nomenclature = Nomenclature.harvest(element, set: self)
201
- @nomenclatures[nomenclature.name] = nomenclature
202
- end
203
-
204
- def parse_file(file)
205
- f = File.open(file, 'rb')
206
- document = Nokogiri::XML(f) do |config|
207
- config.strict.nonet.noblanks.noent
208
- end
209
- f.close
210
- document.root.children.each do |nomenclature|
211
- harvest_nomenclature(nomenclature)
212
- end
213
- self.version = document.root.attr('version').to_i
214
- end
215
183
  end
216
184
  end
@@ -1,8 +1,5 @@
1
1
  module Onoma
2
- class Property
3
- TYPES = %i[boolean item item_list choice choice_list string_list
4
- date decimal integer nomenclature string symbol].freeze
5
-
2
+ class PropertyNature
6
3
  attr_reader :nomenclature, :name, :type, :fallbacks, :default, :source
7
4
 
8
5
  # New item
@@ -10,14 +7,14 @@ module Onoma
10
7
  @nomenclature = nomenclature
11
8
  @name = name.to_sym
12
9
  @type = type
13
- raise "Invalid type: #{@type.inspect}" unless TYPES.include?(@type)
10
+ raise "Invalid type: #{@type.inspect}" unless Onoma::PROPERTY_TYPES.include?(@type)
14
11
  @fallbacks = options[:fallbacks] if options[:fallbacks]
15
12
  @default = options[:default] if options[:default]
16
13
  @required = !!options[:required]
17
14
  @source = options[:choices] if reference? && options[:choices]
18
15
  end
19
16
 
20
- TYPES.each do |type|
17
+ Onoma::PROPERTY_TYPES.each do |type|
21
18
  define_method "#{type}?" do
22
19
  @type == type
23
20
  end
@@ -77,7 +74,7 @@ module Onoma
77
74
  def selection
78
75
  if inline_choices?
79
76
  choices.collect do |c|
80
- [c, c]
77
+ ["nomenclatures.#{@nomenclature.name}.choices.#{name}.#{c}".t, c]
81
78
  end
82
79
  elsif item_reference?
83
80
  @nomenclature.sibling(@source).selection
@@ -86,7 +83,7 @@ module Onoma
86
83
 
87
84
  # Return human name of property
88
85
  def human_name
89
- "nomenclatures.#{nomenclature.name}.properties.#{name}".t(default: ["nomenclatures.#{nomenclature.name}.properties.#{name}".to_sym, "properties.#{name}".to_sym, "enumerize.#{nomenclature.name}.#{name}".to_sym, "labels.#{name}".to_sym, name.humanize])
86
+ I18n.t("nomenclatures.#{nomenclature.name}.property_natures.#{name}", default: ["nomenclatures.#{nomenclature.name}.properties.#{name}".to_sym, "properties.#{name}".to_sym, "enumerize.#{nomenclature.name}.#{name}".to_sym, "labels.#{name}".to_sym, name.humanize])
90
87
  end
91
88
 
92
89
  alias humanize human_name
@@ -0,0 +1,15 @@
1
+ module Onoma
2
+ module Record
3
+ class Base
4
+ class << self
5
+ def method_missing(*args, &block)
6
+ Onoma.find_or_initialize(name.tableize.sub(/\Aonoma\//, '')).send(*args, &block)
7
+ end
8
+
9
+ def respond_to?(method_name)
10
+ Onoma.find_or_initialize(name.tableize.sub(/\Aonoma\//, '')).respond_to?(method_name) || super
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -4,7 +4,7 @@ module Onoma
4
4
 
5
5
  # name: things
6
6
  # class_name: Thing
7
- # klass: Nomen::Thing
7
+ # klass: Onoma::Thing
8
8
  def initialize(active_record, name, options = {})
9
9
  @options = options
10
10
  @name = name.to_s
@@ -12,8 +12,8 @@ module Onoma
12
12
  @class_name = options[:class_name] || name.to_s.classify
13
13
  @foreign_key = (options[:foreign_key] || name).to_s
14
14
  @scope = options[:scope]
15
- @nomenclature = class_name.underscore.pluralize
16
- @klass = Onoma.find(@nomenclature)
15
+ @nomenclature = class_name.tableize
16
+ @klass = "Onoma::#{@class_name}".constantize
17
17
  end
18
18
 
19
19
  alias model active_record
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Onoma
2
- VERSION = '0.2.2'.freeze
4
+ VERSION = '0.4.1'
3
5
  end
@@ -1,29 +1,28 @@
1
-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'onoma/version'
1
+ require_relative 'lib/onoma/version'
5
2
 
6
3
  Gem::Specification.new do |spec|
7
- spec.name = 'onoma'
8
- spec.version = Onoma::VERSION
9
- spec.authors = ['Brice TEXIER']
10
- spec.email = ['brice@ekylibre.com']
4
+ spec.name = 'onoma'
5
+ spec.version = Onoma::VERSION
6
+ spec.required_ruby_version = '>= 2.4.4'
7
+ spec.authors = ['Brice TEXIER']
8
+ spec.email = ['brice@ekylibre.com']
11
9
 
12
- spec.summary = 'Provides open nomenclature data in a gem'
13
- spec.description = 'Actual support Open-Nomenclature data and gem for use'
14
- spec.homepage = 'https://github.com/ekylibre/onoma'
15
- spec.license = 'MIT'
10
+ spec.summary = 'Provides open nomenclature data in a gem'
11
+ spec.description = 'Actual support Open-Nomenclature data and gem for use'
12
+ spec.homepage = 'https://gitlab.com/ekylibre/onoma'
13
+ spec.license = 'MIT'
16
14
 
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = 'exe'
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = 'exe'
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
18
  spec.require_paths = ['lib']
21
19
 
22
- spec.add_development_dependency 'bundler', '~> 1.10'
23
- spec.add_development_dependency 'colored'
24
- spec.add_development_dependency 'rake', '~> 10.0'
20
+ spec.add_development_dependency 'bundler', '> 1.15'
21
+ spec.add_development_dependency 'rake', '> 12.0'
25
22
  spec.add_development_dependency 'minitest'
26
23
  spec.add_development_dependency 'i18n-tasks'
27
- spec.add_dependency 'activesupport'
28
- spec.add_dependency 'nokogiri'
24
+
25
+ spec.add_dependency 'activesupport', '>= 4.2'
26
+ spec.add_dependency 'zeitwerk', '~> 2.4.0'
27
+ spec.add_dependency 'nokogiri', '>= 1.10.4'
29
28
  end
metadata CHANGED
@@ -1,57 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onoma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brice TEXIER
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-21 00:00:00.000000000 Z
11
+ date: 2020-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
19
+ version: '1.15'
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: '1.10'
27
- - !ruby/object:Gem::Dependency
28
- name: colored
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '1.15'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - "~>"
31
+ - - ">"
46
32
  - !ruby/object:Gem::Version
47
- version: '10.0'
33
+ version: '12.0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - "~>"
38
+ - - ">"
53
39
  - !ruby/object:Gem::Version
54
- version: '10.0'
40
+ version: '12.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: minitest
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -86,28 +72,42 @@ dependencies:
86
72
  requirements:
87
73
  - - ">="
88
74
  - !ruby/object:Gem::Version
89
- version: '0'
75
+ version: '4.2'
90
76
  type: :runtime
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - ">="
95
81
  - !ruby/object:Gem::Version
96
- version: '0'
82
+ version: '4.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: zeitwerk
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.4.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.4.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: nokogiri
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 1.10.4
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 1.10.4
111
111
  description: Actual support Open-Nomenclature data and gem for use
112
112
  email:
113
113
  - brice@ekylibre.com
@@ -116,6 +116,7 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
+ - ".gitlab-ci.yml"
119
120
  - ".travis.yml"
120
121
  - CODE_OF_CONDUCT.md
121
122
  - Gemfile
@@ -123,6 +124,7 @@ files:
123
124
  - README.md
124
125
  - Rakefile
125
126
  - bin/console
127
+ - bin/rake
126
128
  - bin/setup
127
129
  - config/locales/arb.yml
128
130
  - config/locales/cmn.yml
@@ -318,14 +320,62 @@ files:
318
320
  - db/migrate/20170627081533_add_pending_deposit_payments_account_number_for_pt_accounting_system.xml
319
321
  - db/migrate/20170718131724_add_issue_natures.xml
320
322
  - db/migrate/20170803164344_add_procedure_nature_and_category.xml
323
+ - db/migrate/20170904223101_add_cultivable_zone_registry.xml
321
324
  - db/migrate/20170914083358_add_new_product_nature_variants.xml
322
325
  - db/migrate/20170927144852_add_kiwi_varieties.xml
326
+ - db/migrate/20171106085357_update_account_numbers.xml
327
+ - db/migrate/20171212081801_add_fiscal_positions.xml
328
+ - db/migrate/20180408190101_add_new_plant_variants.xml
329
+ - db/migrate/20180409130101_add_common_crop.xml
330
+ - db/migrate/20180418085027_add-hour-counter-indicator.xml
331
+ - db/migrate/20180709134310_add_centralizing_field_to_accounts.xml
332
+ - db/migrate/20180711093131_review_all_accounts_number_and_fallbacks.xml
333
+ - db/migrate/20180806080646_edit_centralizing_field_accounts.xml
334
+ - db/migrate/20180814184001_add_missing_categories.xml
335
+ - db/migrate/20180907160001_edit_accounts_to_unlock_first_run.xml
336
+ - db/migrate/20181004220301_add_journal_ledger.xml
337
+ - db/migrate/20181205162401_add_intra_vat.xml
338
+ - db/migrate/20181213153405_fix_accounting_systems.xml
339
+ - db/migrate/20181217155149_fiscal_position_refers_to_accounting_system.xml
340
+ - db/migrate/20181217173101_fiscal_position_reference_typo.xml
341
+ - db/migrate/20190315154040_add_suspense_account.xml
342
+ - db/migrate/20190326110849_add_asset_fixable_to_product_nature_categories.xml
343
+ - db/migrate/20190326135443_change_product_nature_category_cultivable_zone_into_land.xml
344
+ - db/migrate/20190329133808_change_land_fixed_assets_account_usage.xml
345
+ - db/migrate/20190405120711_delete_land_sales_account_and_assign_land_parcels_sell_revenues_to_land.xml
346
+ - db/migrate/20190412071057_add_new_fixed_assets_andn_depreciable_accounts.xml
347
+ - db/migrate/20190509092804_add_account_exceptional_depreciations_imputations_expenses_for_fixed_assets.xml
348
+ - db/migrate/20190514084753_add_approved_input_volume.xml
349
+ - db/migrate/20190520072403_add_new_accounts.xml
350
+ - db/migrate/20190521170601_add_missing_taxes.xml
351
+ - db/migrate/20190611101014_change_deductible_vat_account.xml
352
+ - db/migrate/20190620092151_fix_conflicts_in_new_accounts.xml
353
+ - db/migrate/20190625152636_change_mixture_seed_product_nature_variant.xml
354
+ - db/migrate/20190718130243_remove_services_expenses.xml
355
+ - db/migrate/20190801142431_remove_accounts_from_pcg82.xml
356
+ - db/migrate/20190807125202_add_nature_to_product_natures.xml
357
+ - db/migrate/20190823091727_fix-cubic-meter-per-hectare-symbol.xml
358
+ - db/migrate/20190909150402_add_staff_supply_stock_account.xml
359
+ - db/migrate/20190913102036_add_caliber_indicator.xml
360
+ - db/migrate/20190917161215_add_missing_mass_area_density_units.xml
361
+ - db/migrate/20190917161216_update_quintal_symbol.xml
362
+ - db/migrate/20190917161217_adds_more_info_to_units.xml
363
+ - db/migrate/20190918074757_add_new_accounts.xml
364
+ - db/migrate/20191001122750_add_accounts_fixed_assets_related.xml
365
+ - db/migrate/20191016152118_add_missing_document_templates.xml
366
+ - db/migrate/20191028175001_add_short_balance_sheet.xml
367
+ - db/migrate/20191029131921_add_vine_equipments.xml
368
+ - db/migrate/20191112132413_remove_roller_from_product_natures.xml
369
+ - db/migrate/20191113134626_add_nature_to_new_product_natures.xml
370
+ - db/migrate/20191125133327_add_missing_units_and_indicators.xml
371
+ - db/migrate/20200107095554_add_signed_field_to_document_nature.xml
372
+ - db/migrate/20200305160358_add_varieties_for_phytosanitary.xml
373
+ - db/migrate/20200421123503_add_type_to_categories_and_variants.xml
374
+ - db/migrate/20200514092205_add_liter_per_hectoliter_unit.xml
375
+ - db/migrate/20200722091859_triticale_derivative_of.xml
323
376
  - db/reference.xml
324
377
  - lib/onoma.rb
325
- - lib/onoma/database.rb
326
378
  - lib/onoma/item.rb
327
- - lib/onoma/migration.rb
328
- - lib/onoma/migration/actions.rb
329
379
  - lib/onoma/migration/actions/base.rb
330
380
  - lib/onoma/migration/actions/item_change.rb
331
381
  - lib/onoma/migration/actions/item_creation.rb
@@ -335,18 +385,86 @@ files:
335
385
  - lib/onoma/migration/actions/nomenclature_creation.rb
336
386
  - lib/onoma/migration/actions/nomenclature_removal.rb
337
387
  - lib/onoma/migration/actions/property_creation.rb
388
+ - lib/onoma/migration/base.rb
389
+ - lib/onoma/migrator.rb
390
+ - lib/onoma/migrator/reference.rb
391
+ - lib/onoma/migrator/translation.rb
392
+ - lib/onoma/models/ability.rb
393
+ - lib/onoma/models/account.rb
394
+ - lib/onoma/models/accounting_system.rb
395
+ - lib/onoma/models/activity_family.rb
396
+ - lib/onoma/models/administrative_area.rb
397
+ - lib/onoma/models/administrative_area_nature.rb
398
+ - lib/onoma/models/analysis_nature.rb
399
+ - lib/onoma/models/animal_life_state.rb
400
+ - lib/onoma/models/cation_exchange_capacity_analysis_method.rb
401
+ - lib/onoma/models/certification.rb
402
+ - lib/onoma/models/certification_label.rb
403
+ - lib/onoma/models/chemical_classification.rb
404
+ - lib/onoma/models/chemical_element.rb
405
+ - lib/onoma/models/country.rb
406
+ - lib/onoma/models/crop_set.rb
407
+ - lib/onoma/models/currency.rb
408
+ - lib/onoma/models/delivery_mode.rb
409
+ - lib/onoma/models/dimension.rb
410
+ - lib/onoma/models/document_category.rb
411
+ - lib/onoma/models/document_nature.rb
412
+ - lib/onoma/models/entity_link_nature.rb
413
+ - lib/onoma/models/event_nature.rb
414
+ - lib/onoma/models/fence_perimeter.rb
415
+ - lib/onoma/models/figure.rb
416
+ - lib/onoma/models/fiscal_position.rb
417
+ - lib/onoma/models/guide_nature.rb
418
+ - lib/onoma/models/identifier_nature.rb
419
+ - lib/onoma/models/indicator.rb
420
+ - lib/onoma/models/issue_nature.rb
421
+ - lib/onoma/models/land.rb
422
+ - lib/onoma/models/language.rb
423
+ - lib/onoma/models/mammalia_birth_condition.rb
424
+ - lib/onoma/models/mammalia_reproduction_state.rb
425
+ - lib/onoma/models/molecule.rb
426
+ - lib/onoma/models/net_service.rb
427
+ - lib/onoma/models/opportunity_origin.rb
428
+ - lib/onoma/models/phosphorus_analysis_method.rb
429
+ - lib/onoma/models/plant_life_state.rb
430
+ - lib/onoma/models/plant_reproduction_state.rb
431
+ - lib/onoma/models/plants_growth_level.rb
432
+ - lib/onoma/models/procedure_action.rb
433
+ - lib/onoma/models/procedure_category.rb
434
+ - lib/onoma/models/procedure_nature.rb
435
+ - lib/onoma/models/procedure_role.rb
436
+ - lib/onoma/models/product_nature.rb
437
+ - lib/onoma/models/product_nature_category.rb
438
+ - lib/onoma/models/product_nature_variant.rb
439
+ - lib/onoma/models/production_nature.rb
440
+ - lib/onoma/models/production_system.rb
441
+ - lib/onoma/models/production_usage.rb
442
+ - lib/onoma/models/residue_elimination_method.rb
443
+ - lib/onoma/models/role.rb
444
+ - lib/onoma/models/running_cost.rb
445
+ - lib/onoma/models/sex.rb
446
+ - lib/onoma/models/soil_cultural_state.rb
447
+ - lib/onoma/models/soil_nature.rb
448
+ - lib/onoma/models/spatial_reference_system.rb
449
+ - lib/onoma/models/tax.rb
450
+ - lib/onoma/models/tax_nature.rb
451
+ - lib/onoma/models/unit.rb
452
+ - lib/onoma/models/variety.rb
453
+ - lib/onoma/models/working_set.rb
338
454
  - lib/onoma/nomenclature.rb
339
- - lib/onoma/property.rb
455
+ - lib/onoma/nomenclature_set.rb
456
+ - lib/onoma/property_nature.rb
457
+ - lib/onoma/record/base.rb
340
458
  - lib/onoma/reference.rb
341
459
  - lib/onoma/reflection.rb
342
460
  - lib/onoma/relation.rb
343
461
  - lib/onoma/version.rb
344
462
  - onoma.gemspec
345
- homepage: https://github.com/ekylibre/onoma
463
+ homepage: https://gitlab.com/ekylibre/onoma
346
464
  licenses:
347
465
  - MIT
348
466
  metadata: {}
349
- post_install_message:
467
+ post_install_message:
350
468
  rdoc_options: []
351
469
  require_paths:
352
470
  - lib
@@ -354,16 +472,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
354
472
  requirements:
355
473
  - - ">="
356
474
  - !ruby/object:Gem::Version
357
- version: '0'
475
+ version: 2.4.4
358
476
  required_rubygems_version: !ruby/object:Gem::Requirement
359
477
  requirements:
360
478
  - - ">="
361
479
  - !ruby/object:Gem::Version
362
480
  version: '0'
363
481
  requirements: []
364
- rubyforge_project:
365
- rubygems_version: 2.5.2
366
- signing_key:
482
+ rubygems_version: 3.0.3
483
+ signing_key:
367
484
  specification_version: 4
368
485
  summary: Provides open nomenclature data in a gem
369
486
  test_files: []