onoma 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Rakefile +11 -9
- data/bin/console +3 -3
- data/config/locales/arb.yml +6455 -4930
- data/config/locales/cmn.yml +7227 -0
- data/config/locales/deu.yml +7227 -0
- data/config/locales/eng.yml +2073 -534
- data/config/locales/fra.yml +2093 -452
- data/config/locales/ita.yml +7227 -0
- data/config/locales/jpn.yml +6412 -4887
- data/config/locales/por.yml +6261 -4736
- data/config/locales/spa.yml +6076 -4551
- data/db/migrate/20151211114316_add_beta_varieties.xml +1 -1
- data/db/migrate/20151211124757_add_allium_schoenoprasum_varieties.xml +2 -2
- data/db/migrate/20151211153218_add_zea_mays_varieties.xml +1 -1
- data/db/migrate/20151216100708_add_lifter_equipment_variants.xml +1 -1
- data/db/migrate/20151223164501_update_organic_fertilizer.xml +4 -0
- data/db/migrate/20151223171801_update_indicators.xml +4 -0
- data/db/migrate/20160104145418_add_matters.xml +14 -0
- data/db/migrate/20160104160843_change_product_nature_variants_drain.xml +4 -0
- data/db/migrate/20160105095120_add_plugin_cap_varieties.xml +261 -0
- data/db/migrate/20160106095232_add_orchard_plugin_cap_varieties.xml +405 -0
- data/db/migrate/20160108142009_add_product_nature_variants_nematicide.xml +6 -0
- data/db/migrate/20160113144856_update_prunus_avium_parent.xml +32 -0
- data/db/migrate/20160115090243_change_plant_varieties.xml +7 -0
- data/db/migrate/20160119115401_add_shipping_note_document.xml +4 -0
- data/db/migrate/20160128093149_fixes_invalid_parent.xml +102 -0
- data/db/migrate/20160128154202_add_product_natures_protective_canvas.xml +6 -0
- data/db/migrate/20160204115942_change_protective_net_nature.xml +4 -0
- data/db/migrate/20160204122030_change_cover_implanter_abilities.xml +6 -0
- data/db/migrate/20160206163031_simplifies_activity_families.xml +135 -0
- data/db/migrate/20160207142352_fix_spelling_mistakes_on_associate_accounts.xml +7 -0
- data/db/migrate/20160210124624_fix_invalid_abilities_on_product_natures.xml +5 -0
- data/db/migrate/20160224234901_add_seedling_sorting.xml +4 -0
- data/db/migrate/20160310145038_add_rhodes_grass.xml +5 -0
- data/db/migrate/20160315152217_remove_exchange_natures.xml +4 -0
- data/db/migrate/20160402125244_add_some_heavy_equipment.xml +14 -0
- data/db/migrate/20160408223901_change_zea_variety.xml +14 -0
- data/db/migrate/20160410082230_add_chemical_classifications.xml +486 -0
- data/db/migrate/20160425100840_add_product_nature_corn_topper.xml +6 -0
- data/db/migrate/20160427115742_add_production_systems.xml +9 -0
- data/db/migrate/20160428085808_add_rows_count_indicator.xml +4 -0
- data/db/migrate/20160503131928_add_equipment_indicators.xml +34 -0
- data/db/migrate/20160503155351_fix_taxes.xml +15 -0
- data/db/migrate/20160504143733_add_units.xml +6 -0
- data/db/migrate/20160509100749_change_item_corn_topper.xml +4 -0
- data/db/migrate/20160516075201_add_plant_analysis.xml +4 -0
- data/db/migrate/20160520144901_update_plant_analysis.xml +5 -0
- data/db/migrate/20160525073342_update_spreader_trailer_product_nature.xml +4 -0
- data/db/migrate/20160526075245_update_spreader_trailer_abilities.xml +4 -0
- data/db/migrate/20160526092246_update_product_natures_and_variants_for_vegetables.xml +37 -0
- data/db/migrate/20160527090330_update_product_natures_seed.xml +5 -0
- data/db/migrate/20160531071525_add_procedure_actions.xml +6 -0
- data/db/migrate/20160531094927_add_items_for_pollination_pocedure.xml +9 -0
- data/db/migrate/20160605122001_add_worker_register.xml +4 -0
- data/db/migrate/20160608075549_update_spatial_reference_systems.xml +5437 -0
- data/db/migrate/20160608202134_add_missing_procedure_actions.xml +6 -0
- data/db/migrate/20160613154204_add_product_nature_variants_hoe_weeder.xml +6 -0
- data/db/migrate/20160615121350_add_pivots_in_nomenclature.xml +11 -0
- data/db/migrate/20160615122805_add_daily_average_working_time_indicator_and_lifespan_indicators.xml +6 -0
- data/db/migrate/20160617142409_add_items_for_hay_bales.xml +8 -0
- data/db/migrate/20160622121241_add_procedure_action_conservation_plowing.xml +4 -0
- data/db/migrate/20160624073237_add_musca_varieties.xml +5 -0
- data/db/migrate/20160627095008_add_weeding_kit.xml +5 -0
- data/db/migrate/20160630075849_update_product_nature_additive.xml +4 -0
- data/db/migrate/20160630124401_fix_coop_variants.xml +9 -0
- data/db/migrate/20160719094049_add_new_procedure_actions.xml +6 -0
- data/db/migrate/20160719100836_add_issue_nature.xml +4 -0
- data/db/migrate/20160720144130_update_equipment_varieties.xml +33 -0
- data/db/migrate/20160721124220_update_product_natures_varieties.xml +58 -0
- data/db/migrate/20160725182008_fix_abilities_on_old_equipment.xml +4 -0
- data/db/migrate/20160726173309_rename_equipments_to_equipment.xml +6 -0
- data/db/migrate/20160727092830_update_malus_pumila_variety_name.xml +4 -0
- data/db/migrate/20160802123639_update_unit_name_for_equipment_product_nature_variants.xml +39 -0
- data/db/migrate/20160816083232_add_issue_natures.xml +6 -0
- data/db/migrate/20160819082951_Add_plant_varieties.xml +10 -0
- data/db/migrate/20160829072846_add_procedure_action.xml +4 -0
- data/db/migrate/20160830153251_add_new_varieties.xml +6 -0
- data/db/migrate/20160909225801_add_missing_stock_variation_accounts.xml +17 -0
- data/db/migrate/20160911091901_update_product_nature_categories.xml +53 -0
- data/db/migrate/20160912182501_fix_product_nature_categories.xml +5 -0
- data/db/migrate/20160914114043_add_tool_maintaining_support.xml +7 -0
- data/db/migrate/20160915143142_add_pest_related_indicators.xml +5 -0
- data/db/migrate/20160919210501_add_transportation_actions.xml +4 -0
- data/db/migrate/20160928113101_add_missing_general_accounts.xml +108 -0
- data/db/migrate/20160930091201_add_missing_tax_natures.xml +17 -0
- data/db/migrate/20161017090516_fix_product_nature_categories_stock_movement_account.xml +5 -0
- data/db/migrate/20161019133613_add_ednotif_eu_country_code.xml +33 -0
- data/db/migrate/20161019145441_add_ednotif_animal_indicators.xml +22 -0
- data/db/migrate/20161022103401_add_portuguese_chart_of_account.xml +34 -0
- data/db/migrate/20161024115013_add_ednotif_indicators_to_cow_product_natures.xml +7 -0
- data/db/migrate/20161030174001_add_missing_cap_2016_varieties.xml +13 -0
- data/db/migrate/20161103111303_add_plants_sorting_action.xml +4 -0
- data/db/migrate/20161202083820_add_new_plant_varieties.xml +13 -0
- data/db/migrate/20161212181852_add_procedure_categories.xml +5 -0
- data/db/migrate/20161214093347_add_procedure_actions.xml +10 -0
- data/db/migrate/20161219171601_add_missing_vat_accounts.xml +4 -0
- data/db/migrate/20161219231801_add_outgoing_payment_report.xml +4 -0
- data/db/migrate/20170104161824_add_indicators_for_plant_analysis.xml +6 -0
- data/db/migrate/20170201180806_set_animal_group_population_counting_to_unitary.xml +23 -0
- data/db/migrate/20170203132125_update_momenclature_for_animal_housing_mulching_procedure.xml +7 -0
- data/db/migrate/20170206125311_update_nomenclature_for_animal_housing_disinfection_procedure.xml +5 -0
- data/db/migrate/20170206163322_update_disinfectant_product_variant.xml +4 -0
- data/db/migrate/20170214125925_clean_cow_indicators.xml +8 -0
- data/db/migrate/20170216100144_add_algerian_vat.xml +10 -0
- data/db/migrate/20170219210901_add_fixed_asset_registry.xml +4 -0
- data/db/migrate/20170220211447_add_procedure_category.xml +4 -0
- data/db/migrate/20170220222412_add_procedure_action.xml +4 -0
- data/db/migrate/20170221102405_add_milking_robot_in_nomenclature.xml +6 -0
- data/db/migrate/20170222113119_add_animal_varieties.xml +29 -0
- data/db/migrate/20170306154901_add_missing_outstanding_account.xml +4 -0
- data/db/migrate/20170308232701_add_fr_pcga_profit_and_loss.xml +4 -0
- data/db/migrate/20170312112401_add_fr_pcga_balance_sheet.xml +4 -0
- data/db/migrate/20170312172301_add_fr_pcg82_balance_sheet.xml +5 -0
- data/db/migrate/20170320073301_add_journal_entry_sheet.xml +8 -0
- data/db/migrate/20170320144338_add_sundry_debtors_and_creditors_usage.xml +4 -0
- data/db/migrate/20170322223101_add_loan_registry.xml +4 -0
- data/db/migrate/20170324084701_add_fixed_asset_sheet.xml +4 -0
- data/db/migrate/20170328144501_add_pnt_loan_accounts.xml +5 -0
- data/db/migrate/20170328165900_update_foliar_spray_product_nature.xml +4 -0
- data/db/migrate/20170328170000_add_indicator.xml +4 -0
- data/db/migrate/20170328170100_update_product_nature_seedling.xml +6 -0
- data/db/migrate/20170328170200_add_indicators.xml +4 -0
- data/db/migrate/20170328170300_add_indicators2.xml +4 -0
- data/db/migrate/20170328170400_update_seedling_product_natures.xml +4 -0
- data/db/migrate/20170405135101_add_account_journal_entry_sheet.xml +4 -0
- data/db/migrate/20170407214236_add_portuguese_account_config.xml +4 -0
- data/db/migrate/20170524094443_add_urtica_variety.xml +5 -0
- data/db/migrate/20170614130921_add_varieties.xml +117 -0
- data/db/migrate/20170627075545_add_varieties2.xml +37 -0
- data/db/migrate/20170627081533_add_pending_deposit_payments_account_number_for_pt_accounting_system.xml +4 -0
- data/db/migrate/20170718131724_add_issue_natures.xml +54 -0
- data/db/migrate/20170803164344_add_procedure_nature_and_category.xml +5 -0
- data/db/reference.xml +7904 -939
- data/lib/onoma/database.rb +77 -32
- data/lib/onoma/item.rb +74 -24
- data/lib/onoma/migration/actions/base.rb +1 -1
- data/lib/onoma/migration/actions/item_change.rb +5 -5
- data/lib/onoma/migration/actions/item_creation.rb +4 -4
- data/lib/onoma/migration/actions/item_merging.rb +5 -1
- data/lib/onoma/migration/actions/item_removal.rb +1 -1
- data/lib/onoma/migration/actions/nomenclature_change.rb +3 -3
- data/lib/onoma/migration/actions/nomenclature_creation.rb +4 -4
- data/lib/onoma/migration/actions/nomenclature_removal.rb +3 -3
- data/lib/onoma/migration/actions/property_creation.rb +2 -2
- data/lib/onoma/migration.rb +114 -3
- data/lib/onoma/nomenclature.rb +79 -49
- data/lib/onoma/property.rb +14 -14
- data/lib/onoma/reference.rb +1 -1
- data/lib/onoma/reflection.rb +8 -3
- data/lib/onoma/relation.rb +25 -3
- data/lib/onoma/version.rb +1 -1
- data/lib/onoma.rb +31 -62
- data/onoma.gemspec +15 -15
- metadata +123 -7
- data/lib/onoma/migration/base.rb +0 -45
- data/lib/onoma/migrator/reference.rb +0 -77
- data/lib/onoma/migrator/translation.rb +0 -30
- data/lib/onoma/migrator.rb +0 -3
data/lib/onoma/database.rb
CHANGED
@@ -2,24 +2,26 @@ module Onoma
|
|
2
2
|
# This class represents a set of nomenclature like the reference DB
|
3
3
|
class Database
|
4
4
|
attr_accessor :version
|
5
|
+
attr_reader :path
|
5
6
|
|
6
|
-
def initialize
|
7
|
+
def initialize(path)
|
8
|
+
@path = Pathname.new(path)
|
7
9
|
@nomenclatures = ActiveSupport::HashWithIndifferentAccess.new
|
8
10
|
@version = 0
|
9
11
|
end
|
10
12
|
|
11
|
-
def self.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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)
|
21
|
+
end
|
22
|
+
|
23
|
+
def copy(path)
|
24
|
+
File.write(path, to_xml)
|
23
25
|
end
|
24
26
|
|
25
27
|
def nomenclature_names
|
@@ -34,8 +36,8 @@ module Onoma
|
|
34
36
|
def [](nomenclature_name)
|
35
37
|
@nomenclatures[nomenclature_name]
|
36
38
|
end
|
37
|
-
|
38
|
-
|
39
|
+
alias find []
|
40
|
+
alias nomenclature []
|
39
41
|
|
40
42
|
# Find item
|
41
43
|
def item(nomenclature_name, item_name)
|
@@ -51,7 +53,7 @@ module Onoma
|
|
51
53
|
|
52
54
|
def find!(name)
|
53
55
|
unless nomenclature = @nomenclatures[name]
|
54
|
-
|
56
|
+
raise "Nomenclature #{name} does not exist"
|
55
57
|
end
|
56
58
|
nomenclature
|
57
59
|
end
|
@@ -82,16 +84,20 @@ module Onoma
|
|
82
84
|
xml.nomenclatures(xmlns: Onoma::XMLNS, version: @version) do
|
83
85
|
@nomenclatures.values.sort.each do |nomenclature|
|
84
86
|
xml.nomenclature(nomenclature.to_xml_attrs) do
|
85
|
-
|
86
|
-
|
87
|
-
|
87
|
+
if nomenclature.properties.any?
|
88
|
+
xml.properties do
|
89
|
+
nomenclature.properties.values.sort.each do |property|
|
90
|
+
xml.property(property.to_xml_attrs)
|
91
|
+
end
|
88
92
|
end
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
+
end
|
94
|
+
if nomenclature.items.any?
|
95
|
+
xml.items do
|
96
|
+
nomenclature.items.values.sort_by(&:name).each do |item|
|
97
|
+
xml.item(item.to_xml_attrs)
|
98
|
+
end
|
93
99
|
end
|
94
|
-
end
|
100
|
+
end
|
95
101
|
end
|
96
102
|
end
|
97
103
|
end
|
@@ -99,22 +105,42 @@ module Onoma
|
|
99
105
|
builder.to_xml
|
100
106
|
end
|
101
107
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
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
|
105
131
|
end
|
106
132
|
|
107
133
|
def add_nomenclature(name, options = {})
|
108
|
-
|
134
|
+
raise "Nomenclature #{name} already exists" if @nomenclatures[name]
|
109
135
|
options[:set] = self
|
110
136
|
@nomenclatures[name] = Nomenclature.new(name, options)
|
111
137
|
end
|
112
138
|
|
113
139
|
def move_nomenclature(old_name, new_name)
|
114
140
|
unless @nomenclatures[old_name]
|
115
|
-
|
141
|
+
raise "Nomenclature #{old_name} does not exist"
|
116
142
|
end
|
117
|
-
|
143
|
+
raise "Nomenclature #{new_name} already exists" if @nomenclatures[new_name]
|
118
144
|
@nomenclatures[new_name] = @nomenclatures.delete(old_name)
|
119
145
|
@nomenclatures[new_name]
|
120
146
|
end
|
@@ -139,11 +165,11 @@ module Onoma
|
|
139
165
|
end
|
140
166
|
|
141
167
|
def change_property(_nomenclature_name, _property_name, _updates = {})
|
142
|
-
|
168
|
+
raise NotImplementedError
|
143
169
|
end
|
144
170
|
|
145
171
|
def remove_property(_nomenclature_name, _property_name, _options = {})
|
146
|
-
|
172
|
+
raise NotImplementedError
|
147
173
|
end
|
148
174
|
|
149
175
|
def add_item(nomenclature_name, item_name, options = {})
|
@@ -167,5 +193,24 @@ module Onoma
|
|
167
193
|
nomenclature = find!(nomenclature_name)
|
168
194
|
nomenclature.remove_item(item_name)
|
169
195
|
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
|
170
215
|
end
|
171
216
|
end
|
data/lib/onoma/item.rb
CHANGED
@@ -3,7 +3,7 @@ module Onoma
|
|
3
3
|
class Item
|
4
4
|
attr_reader :nomenclature, :left, :right, :depth, :aliases, :parent_name
|
5
5
|
attr_accessor :name, :attributes
|
6
|
-
|
6
|
+
alias properties attributes
|
7
7
|
|
8
8
|
# New item
|
9
9
|
def initialize(nomenclature, name, options = {})
|
@@ -18,6 +18,7 @@ module Onoma
|
|
18
18
|
self.parent = parent
|
19
19
|
end
|
20
20
|
@attributes = ActiveSupport::HashWithIndifferentAccess.new
|
21
|
+
@children = Set.new
|
21
22
|
options.each do |k, v|
|
22
23
|
set(k, v)
|
23
24
|
end
|
@@ -29,6 +30,7 @@ module Onoma
|
|
29
30
|
|
30
31
|
def parent=(item)
|
31
32
|
old_parent_name = @parent_name
|
33
|
+
old_parent = @parent
|
32
34
|
if item.nil?
|
33
35
|
@parent = nil
|
34
36
|
@parent_name = nil
|
@@ -37,15 +39,27 @@ module Onoma
|
|
37
39
|
item = nomenclature.find!(item.to_s)
|
38
40
|
end
|
39
41
|
if item.nomenclature != nomenclature
|
40
|
-
|
42
|
+
raise 'Item must come from same nomenclature'
|
41
43
|
end
|
42
|
-
if item.parents.
|
43
|
-
|
44
|
+
if item.parents.any? { |p| self == p } || self == item
|
45
|
+
raise 'Circular dependency. Item can be parent of itself.'
|
44
46
|
end
|
45
47
|
@parent = item
|
46
48
|
@parent_name = @parent.name.to_s
|
47
49
|
end
|
48
|
-
|
50
|
+
if old_parent_name != @parent_name
|
51
|
+
old_parent.delete_child(self) if old_parent
|
52
|
+
@parent.add_child(self) if @parent
|
53
|
+
@nomenclature.rebuild_tree!
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_child(item)
|
58
|
+
@children << item
|
59
|
+
end
|
60
|
+
|
61
|
+
def delete_child(item)
|
62
|
+
@children.delete(item)
|
49
63
|
end
|
50
64
|
|
51
65
|
# Changes parent without rebuilding
|
@@ -59,7 +73,28 @@ module Onoma
|
|
59
73
|
end
|
60
74
|
|
61
75
|
def parent
|
62
|
-
@parent
|
76
|
+
return @parent if @parent
|
77
|
+
@parent = find_parent
|
78
|
+
@parent.add_child(self) if @parent
|
79
|
+
@parent
|
80
|
+
end
|
81
|
+
alias fetch_parent parent
|
82
|
+
|
83
|
+
def find_parent
|
84
|
+
@nomenclature.find(@parent_name)
|
85
|
+
end
|
86
|
+
|
87
|
+
def degree_of_kinship_with(other)
|
88
|
+
other_item = item_for_comparison(other)
|
89
|
+
a = self_and_parents.reverse
|
90
|
+
b = other_item.self_and_parents.reverse
|
91
|
+
return nil if a.first != b.first
|
92
|
+
common_lineage = 0
|
93
|
+
a.size.times do |index|
|
94
|
+
break if a[index].nil? || b[index].nil? || a[index] != b[index]
|
95
|
+
common_lineage += 1
|
96
|
+
end
|
97
|
+
a.size + b.size - 2 * common_lineage
|
63
98
|
end
|
64
99
|
|
65
100
|
def original_nomenclature_name
|
@@ -71,11 +106,9 @@ module Onoma
|
|
71
106
|
def children(options = {})
|
72
107
|
if options[:index].is_a?(FalseClass)
|
73
108
|
if options[:recursively].is_a?(FalseClass)
|
74
|
-
|
75
|
-
(item.parent == self)
|
76
|
-
end
|
109
|
+
@children.to_a
|
77
110
|
else
|
78
|
-
|
111
|
+
children(index: false, recursive: false).each_with_object([]) do |item, list|
|
79
112
|
list << item
|
80
113
|
list += item.children(index: false, recursive: true)
|
81
114
|
list
|
@@ -83,12 +116,12 @@ module Onoma
|
|
83
116
|
end
|
84
117
|
else
|
85
118
|
if options[:recursively].is_a?(FalseClass)
|
86
|
-
|
119
|
+
nomenclature.list.select do |item|
|
87
120
|
@left < item.left && item.right < @right && item.depth == @depth + 1
|
88
121
|
end
|
89
122
|
else
|
90
123
|
# @children ||=
|
91
|
-
|
124
|
+
nomenclature.list.select do |item|
|
92
125
|
@left < item.left && item.right < @right
|
93
126
|
end
|
94
127
|
end
|
@@ -96,7 +129,7 @@ module Onoma
|
|
96
129
|
end
|
97
130
|
|
98
131
|
def root
|
99
|
-
|
132
|
+
parent? ? parent.root : self
|
100
133
|
end
|
101
134
|
|
102
135
|
# Returns direct parents from the closest to the farthest
|
@@ -112,6 +145,12 @@ module Onoma
|
|
112
145
|
[self] + parents
|
113
146
|
end
|
114
147
|
|
148
|
+
def rise(&block)
|
149
|
+
result = yield(self)
|
150
|
+
return result if result
|
151
|
+
parent ? parent.rise(&block) : nil
|
152
|
+
end
|
153
|
+
|
115
154
|
# Computes left/right value for nested set
|
116
155
|
# Returns right index
|
117
156
|
def rebuild_tree!
|
@@ -139,7 +178,9 @@ module Onoma
|
|
139
178
|
def human_name(options = {})
|
140
179
|
"nomenclatures.#{nomenclature.name}.items.#{name}".t(options.merge(default: ["items.#{name}".to_sym, "enumerize.#{nomenclature.name}.#{name}".to_sym, "labels.#{name}".to_sym, name.humanize]))
|
141
180
|
end
|
142
|
-
|
181
|
+
alias humanize human_name
|
182
|
+
alias localize human_name
|
183
|
+
alias l localize
|
143
184
|
|
144
185
|
def human_notion_name(notion_name, options = {})
|
145
186
|
"nomenclatures.#{nomenclature.name}.notions.#{notion_name}.#{name}".t(options.merge(default: ["labels.#{name}".to_sym]))
|
@@ -190,7 +231,7 @@ module Onoma
|
|
190
231
|
def to_xml_attrs
|
191
232
|
attrs = {}
|
192
233
|
attrs[:name] = name
|
193
|
-
attrs[:parent] = @parent_name if
|
234
|
+
attrs[:parent] = @parent_name if parent?
|
194
235
|
properties.each do |pname, pvalue|
|
195
236
|
if p = nomenclature.properties[pname.to_s]
|
196
237
|
if p.type == :decimal
|
@@ -206,11 +247,12 @@ module Onoma
|
|
206
247
|
|
207
248
|
# Returns property value
|
208
249
|
def property(name)
|
250
|
+
return @name.to_sym if name == :name
|
209
251
|
property = @nomenclature.properties[name]
|
210
252
|
value = @attributes[name]
|
211
253
|
if property
|
212
254
|
if value.nil? && property.fallbacks
|
213
|
-
|
255
|
+
property.fallbacks.each do |fallback|
|
214
256
|
value ||= @attributes[fallback]
|
215
257
|
break if value
|
216
258
|
end
|
@@ -227,11 +269,15 @@ module Onoma
|
|
227
269
|
["nomenclatures.#{@nomenclature.name}.item_lists.#{self.name}.#{name}.#{i}".t, i]
|
228
270
|
end
|
229
271
|
elsif property.nomenclature?
|
230
|
-
|
272
|
+
target_nomenclature = Onoma.find(property(name).to_sym)
|
273
|
+
unless target_nomenclature
|
274
|
+
raise "Cannot find nomenclature: for #{property(name).inspect}"
|
275
|
+
end
|
276
|
+
return target_nomenclature.list.collect do |i|
|
231
277
|
[i.human_name, i.name]
|
232
278
|
end
|
233
279
|
else
|
234
|
-
|
280
|
+
raise StandardError, 'Cannot call selection for a non-list property'
|
235
281
|
end
|
236
282
|
end
|
237
283
|
|
@@ -247,12 +293,16 @@ module Onoma
|
|
247
293
|
end
|
248
294
|
|
249
295
|
def set(name, value)
|
250
|
-
|
251
|
-
# TODO: check format
|
252
|
-
if property = nomenclature.properties[name]
|
253
|
-
|
296
|
+
raise "Invalid property: #{name.inspect}" if %i[name parent].include?(name.to_sym)
|
297
|
+
# # TODO: check format
|
298
|
+
# if property = nomenclature.properties[name]
|
299
|
+
# value ||= [] if property.list?
|
300
|
+
# end
|
301
|
+
if value.nil?
|
302
|
+
@attributes.delete(name)
|
303
|
+
else
|
304
|
+
@attributes[name] = value
|
254
305
|
end
|
255
|
-
@attributes[name] = value
|
256
306
|
end
|
257
307
|
|
258
308
|
private
|
@@ -264,7 +314,7 @@ module Onoma
|
|
264
314
|
def item_for_comparison(other)
|
265
315
|
item = nomenclature[other.is_a?(Item) ? other.name : other]
|
266
316
|
unless item
|
267
|
-
|
317
|
+
raise StandardError, "Invalid operand to compare: #{other.inspect} not in #{nomenclature.name}"
|
268
318
|
end
|
269
319
|
item
|
270
320
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Onoma
|
2
|
-
|
2
|
+
class Migration
|
3
3
|
module Actions
|
4
4
|
class ItemChange < Onoma::Migration::Actions::Base
|
5
5
|
attr_reader :nomenclature, :name, :changes
|
@@ -8,9 +8,9 @@ module Onoma
|
|
8
8
|
@nomenclature = name.first
|
9
9
|
@name = name.second
|
10
10
|
@changes = element.attributes.delete_if do |k, _v|
|
11
|
-
%w
|
11
|
+
%w[item].include?(k)
|
12
12
|
end.each_with_object({}) do |(k, v), h|
|
13
|
-
h[k.to_sym] = v.to_s
|
13
|
+
h[k.to_sym] = (v.to_s.blank? ? nil : v.to_s)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -23,9 +23,9 @@ module Onoma
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def label
|
26
|
-
"change_item #{@nomenclature}##{@name}(" + changes.simple_print +
|
26
|
+
"change_item #{@nomenclature}##{@name}(" + changes.simple_print + ')'
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def human_name
|
30
30
|
"Change item #{@nomenclature}##{@name} with " + changes.inspect
|
31
31
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module Onoma
|
2
|
-
|
2
|
+
class Migration
|
3
3
|
module Actions
|
4
4
|
class ItemCreation < Onoma::Migration::Actions::Base
|
5
5
|
attr_reader :nomenclature, :name, :options
|
6
6
|
def initialize(element)
|
7
|
-
|
7
|
+
raise 'Need item attribute' unless element['item']
|
8
8
|
name = element['item'].split('#')
|
9
9
|
@nomenclature = name.first
|
10
10
|
@name = name.second
|
11
11
|
@options = element.attributes.delete_if do |k, _v|
|
12
|
-
k =~ /name(:[a-z]{3})?/ || %w
|
12
|
+
k =~ /name(:[a-z]{3})?/ || %w[item parent nomenclature].include?(k)
|
13
13
|
end.each_with_object({}) do |(k, v), h|
|
14
14
|
h[k.to_sym] = v.to_s
|
15
15
|
end
|
@@ -23,7 +23,7 @@ module Onoma
|
|
23
23
|
def label
|
24
24
|
"create_item #{@nomenclature}##{@name}" + (@options.any? ? "(#{@options.simple_print})" : '')
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def human_name
|
28
28
|
updates = []
|
29
29
|
updates << "#{@name} as name"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Onoma
|
2
|
-
|
2
|
+
class Migration
|
3
3
|
module Actions
|
4
4
|
class ItemMerging < Onoma::Migration::Actions::Base
|
5
5
|
attr_reader :nomenclature, :name, :into
|
@@ -10,6 +10,10 @@ module Onoma
|
|
10
10
|
@into = element['into'].to_s
|
11
11
|
end
|
12
12
|
|
13
|
+
def label
|
14
|
+
"merge_item #{@nomenclature}##{@name} into " + @into.to_s
|
15
|
+
end
|
16
|
+
|
13
17
|
def human_name
|
14
18
|
"Merge item #{@nomenclature}##{@name} into #{@into}"
|
15
19
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Onoma
|
2
|
-
|
2
|
+
class Migration
|
3
3
|
module Actions
|
4
4
|
class NomenclatureChange < Onoma::Migration::Actions::Base
|
5
5
|
attr_reader :nomenclature, :changes
|
6
6
|
|
7
7
|
def initialize(element)
|
8
|
-
|
8
|
+
raise 'No given name' unless element.key?('nomenclature')
|
9
9
|
@nomenclature = element['nomenclature'].to_s
|
10
10
|
@changes = {}
|
11
11
|
@changes[:name] = element['name'].to_s if element.key?('name')
|
@@ -13,7 +13,7 @@ module Onoma
|
|
13
13
|
@changes[:notions] = element.attr('notions').to_s.split(/\s*\,\s*/).map(&:to_sym)
|
14
14
|
end
|
15
15
|
if element.key?('translateable')
|
16
|
-
@changes[:translateable] =
|
16
|
+
@changes[:translateable] = element.attr('translateable').to_s != 'false'
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module Onoma
|
2
|
-
|
2
|
+
class Migration
|
3
3
|
module Actions
|
4
4
|
class NomenclatureCreation < Onoma::Migration::Actions::Base
|
5
5
|
attr_reader :nomenclature, :options
|
6
6
|
|
7
7
|
def initialize(element)
|
8
8
|
@nomenclature = element.key?('nomenclature') ? element['nomenclature'].to_s : element.key?('name') ? element['name'].to_s : nil
|
9
|
-
|
9
|
+
raise 'No given name' unless @nomenclature
|
10
10
|
@options = {}
|
11
11
|
notions = element.attr('notions').to_s.split(/\s*\,\s*/).map(&:to_sym)
|
12
12
|
@options[:notions] = notions if notions.any?
|
13
|
-
@options[:translateable] =
|
13
|
+
@options[:translateable] = element.attr('translateable').to_s != 'false'
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
alias name nomenclature
|
17
17
|
|
18
18
|
def human_name
|
19
19
|
"Create nomenclature #{@name}"
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module Onoma
|
2
|
-
|
2
|
+
class Migration
|
3
3
|
module Actions
|
4
4
|
class NomenclatureRemoval < Onoma::Migration::Actions::Base
|
5
5
|
attr_reader :nomenclature
|
6
6
|
|
7
7
|
def initialize(element)
|
8
8
|
@nomenclature = element['nomenclature']
|
9
|
-
|
9
|
+
raise 'No given nomenclature' if @nomenclature.blank?
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
alias name nomenclature
|
13
13
|
|
14
14
|
def label
|
15
15
|
"remove_nomenclature #{@name}"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Onoma
|
2
|
-
|
2
|
+
class Migration
|
3
3
|
module Actions
|
4
4
|
class PropertyCreation < Onoma::Migration::Actions::Base
|
5
5
|
attr_reader :nomenclature, :name, :type, :options
|
@@ -9,7 +9,7 @@ module Onoma
|
|
9
9
|
@name = name.second
|
10
10
|
@type = element['type'].to_sym
|
11
11
|
unless Property::TYPES.include?(@type)
|
12
|
-
|
12
|
+
raise ArgumentError, "Property #{name} type is unknown: #{@type.inspect}"
|
13
13
|
end
|
14
14
|
@options = {}
|
15
15
|
if element.has_attribute?('fallbacks')
|