Class: CvList
- Inherits:
-
Object
- Object
- CvList
- Defined in:
- backend/app/lib/bulk_import/cv_list.rb
Constant Summary collapse
- CREATE_NEW_VALUES_FOR =
for these enums, don’t throw an error if values are referenced
["instance_instance_type", "container_type"]
Instance Attribute Summary collapse
-
#which ⇒ Object
readonly
Returns the value of attribute which.
Instance Method Summary collapse
-
#add_value_to_enum(new_value) ⇒ Object
-
#initialize(which, current_user) ⇒ CvList
constructor
A new instance of CvList.
-
#length ⇒ Object
-
#renew ⇒ Object
-
#value(label) ⇒ Object
Constructor Details
#initialize(which, current_user) ⇒ CvList
Returns a new instance of CvList.
19 20 21 22 23 |
# File 'backend/app/lib/bulk_import/cv_list.rb', line 19 def initialize(which, current_user) @which = which @current_user = current_user renew end |
Instance Attribute Details
#which ⇒ Object (readonly)
Returns the value of attribute which
17 18 19 |
# File 'backend/app/lib/bulk_import/cv_list.rb', line 17 def which @which end |
Instance Method Details
#add_value_to_enum(new_value) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'backend/app/lib/bulk_import/cv_list.rb', line 61 def add_value_to_enum(new_value) enum = Enumeration.find(:name => @which) if enum.editable === 1 || enum.editable == true unless @validate_only new_position = enum.enumeration_value.length + 1 enum.add_enumeration_value(:value => new_value, :position => new_position) renew end end end |
#length ⇒ Object
39 40 41 |
# File 'backend/app/lib/bulk_import/cv_list.rb', line 39 def length @list.length end |
#renew ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'backend/app/lib/bulk_import/cv_list.rb', line 43 def renew @list = [] list_hash = {} enums = handle_raw_listing(Enumeration, { :name => @which }, @current_user) enums[0]["values"].each do |v| if !v["suppressed"] trans = I18n.t("enumerations.#{@which}.#{v}", default: v) if !list_hash[trans] list_hash[trans] = v @list.push v else Log.warn(I18n.t("bulk_import.warn.dup", :which => @which, :trans => trans, :used => list_hash[trans])) end end end @list_hash = list_hash end |
#value(label) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'backend/app/lib/bulk_import/cv_list.rb', line 25 def value(label) if @list_hash[label] v = @list_hash[label] elsif @list.index(label) v = label end if !v and !CvList::CREATE_NEW_VALUES_FOR.include?(@which) raise Exception.new(I18n.t("bulk_import.error.enum", label: label, which: @which, valid_values: @list.join(', '))) end v end |