Class: Labimotion::Utils
- Inherits:
-
Object
- Object
- Labimotion::Utils
- Defined in:
- lib/labimotion/utils/utils.rb
Overview
Generic Utils
Class Method Summary collapse
- .col_by_element(name) ⇒ Object
- .element_name(name) ⇒ Object
- .element_name_dc(name) ⇒ Object
- .elname_by_collection(name) ⇒ Object
- .find_field(properties, field_path, separator = '.') ⇒ Object
- .find_options_val(field, properties) ⇒ Object
- .klass_by_collection(name) ⇒ Object
- .next_version(release, current_version) ⇒ Object
- .pkg(pkg) ⇒ Object
Class Method Details
.col_by_element(name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/labimotion/utils/utils.rb', line 31 def self.col_by_element(name) names = name.split('::') if names.size == 1 "collections_#{name.underscore.pluralize}" else "collections_#{names.last.underscore.pluralize}" end rescue StandardError => e Labimotion.log_exception(e) name..underscore.pluralize end |
.element_name(name) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/labimotion/utils/utils.rb', line 43 def self.element_name(name) names = name.split('::') if names.size == 1 name else names.last end rescue StandardError => e Labimotion.log_exception(e) name end |
.element_name_dc(name) ⇒ Object
55 56 57 |
# File 'lib/labimotion/utils/utils.rb', line 55 def self.element_name_dc(name) Labimotion::Utils.element_name(name)&.downcase end |
.elname_by_collection(name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/labimotion/utils/utils.rb', line 19 def self.elname_by_collection(name) names = name.split('::') if names.size == 1 name[11..].underscore else names.last[11..].underscore end rescue StandardError => e Labimotion.log_exception(e) name.constantize end |
.find_field(properties, field_path, separator = '.') ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/labimotion/utils/utils.rb', line 83 def self.find_field(properties, field_path, separator = '.') return if properties.nil? || field_path.nil? layer_name, field_name = field_path.split(separator) fields = properties.dig(Labimotion::Prop::LAYERS, layer_name, Labimotion::Prop::FIELDS) return unless fields fields.find { |f| f['field'] == field_name } end |
.find_options_val(field, properties) ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/labimotion/utils/utils.rb', line 93 def self.(field, properties) return if field.nil? || properties.nil? || field['option_layers'].nil? || field['value'].nil? option_layers = properties.dig(Labimotion::Prop::SEL_OPTIONS, field['option_layers']) = option_layers && option_layers['options'] return if .nil? sel_option = .find { |o| o['key'] == field['value'] } sel_option && sel_option['label'] end |
.klass_by_collection(name) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/labimotion/utils/utils.rb', line 7 def self.klass_by_collection(name) names = name.split('::') if names.size == 1 name[11..] else "#{names[0]}::#{names.last[11..]}" end rescue StandardError => e Labimotion.log_exception(e, current_user) name end |
.next_version(release, current_version) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/labimotion/utils/utils.rb', line 59 def self.next_version(release, current_version) case release when 'draft' current_version when 'major' if current_version.nil? || current_version.split('.').length < 2 '1.0' else "#{current_version&.split('.').first.to_i + 1}.0" end when 'minor' if current_version.nil? || current_version&.split('.').length < 2 '0.1' else "#{current_version&.split('.').first.to_i.to_s}.#{current_version&.split('.').last.to_i + 1}" end else current_version end rescue StandardError => e Labimotion.log_exception(e) current_version end |
.pkg(pkg) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/labimotion/utils/utils.rb', line 104 def self.pkg(pkg) pkg = {} if pkg.nil? pkg['eln'] = Chemotion::Application.config.version pkg['labimotion'] = Labimotion::VERSION pkg end |