Class: Kibuvits_krl171bt4_msgc

Inherits:
Object
  • Object
show all
Defined in:
lib/kibuvits_ruby_library_krl171bt4_.rb

Overview

msgc stands for “msg container”, where “msg” stands for “message”.

Messages, including error messages, are often just strings, often written only in one language, usually English. The Kibuvits_krl171bt4_msgc is meant to bundle different language versions of the messages together and it also bundles a message code with the strings, thus simplifying the implementation of message specific control flow.

If a message in a given language is not available, a default version is returned. The Kibuvits_krl171bt4_msgc is meant to be used in conjunction with the Kibuvits_krl171bt4_msgc_stack.

Constant Summary collapse

@@lc_ht_empty_and_frozen =
Hash.new.freeze
@@s_version =

The field s_version is a freeform string that depicts a signature to all of the rest of the fields in the package, recursively. That is to say the s_version has to change whenever the class of the serializable instance changes or the serialization format changes.

"2:ProgFTE".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s_default_msg = $kibuvits_krl171bt4_lc_emptystring, s_message_id = "message code not set", b_failure = true, s_default_language = $kibuvits_krl171bt4_lc_English, s_location_marker_GUID = $kibuvits_krl171bt4_lc_emptystring) ⇒ Kibuvits_krl171bt4_msgc



3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3061

def initialize(s_default_msg=$kibuvits_krl171bt4_lc_emptystring,s_message_id="message code not set",
   b_failure=true,s_default_language=$kibuvits_krl171bt4_lc_English,
   s_location_marker_GUID=$kibuvits_krl171bt4_lc_emptystring)
   @fdr_instantiation_timestamp=Time.now.to_r
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_default_msg
      kibuvits_krl171bt4_typecheck bn, String, s_message_id
      kibuvits_krl171bt4_typecheck bn, [TrueClass, FalseClass], b_failure
      kibuvits_krl171bt4_typecheck bn, String, s_default_language
      kibuvits_krl171bt4_assert_string_min_length(bn,s_default_language,2,
      "\nGUID='380a5cd3-9ed0-4c62-a2e1-c13290a118e7'")
   end # if
   @s_instance_id="msgc_"+Kibuvits_krl171bt4_wholenumberID_generator.generate.to_s+"_"+
   Kibuvits_krl171bt4_GUID_generator.generate_GUID
   @s_default_language=$kibuvits_krl171bt4_lc_emptystring+s_default_language
   @ht_msgs=Hash.new
   @ht_msgs[@s_default_language]=($kibuvits_krl171bt4_lc_emptystring+
   s_default_msg).freeze
   @s_message_id=s_message_id.freeze
   @b_failure=b_failure
   @mx=Mutex.new
   @ob_instantiation_time=Time.now
   @x_data=nil

   @s_location_marker_GUID=s_location_marker_GUID.freeze
   if @s_location_marker_GUID!=$kibuvits_krl171bt4_lc_emptystring
      rgx=Regexp.new($kibuvits_krl171bt4_lc_GUID_regex_core_t1)
      md_candidate=@s_location_marker_GUID.match(rgx)
      if md_candidate==nil
         kibuvits_krl171bt4_throw("\nThe s_location_marker_GUID(=="+
         s_location_marker_GUID+")\nis not a GUID."+
         "\nCurrent exception location GUID=='45e86ac5-3969-4415-86b1-c13290a118e7'\n\n");
      end # if
   end # if
end

Instance Attribute Details

#b_failureObject

Returns the value of attribute b_failure.



3056
3057
3058
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3056

def b_failure
  @b_failure
end

#fdr_instantiation_timestampObject (readonly)

Returns the value of attribute fdr_instantiation_timestamp.



3057
3058
3059
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3057

def fdr_instantiation_timestamp
  @fdr_instantiation_timestamp
end

#s_instance_idObject (readonly)

Returns the value of attribute s_instance_id.



3055
3056
3057
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3055

def s_instance_id
  @s_instance_id
end

#s_location_marker_GUIDObject (readonly)

Returns the value of attribute s_location_marker_GUID.



3058
3059
3060
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3058

def s_location_marker_GUID
  @s_location_marker_GUID
end

Class Method Details

.ob_deserialize(s_progfte) ⇒ Object



3329
3330
3331
3332
3333
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3329

def Kibuvits_krl171bt4_msgc.ob_deserialize(s_progfte)
   msgc=Kibuvits_krl171bt4_msgc.new
   msgc.send(:ob_deserialize,s_progfte)
   return msgc
end

Instance Method Details

#[](s_language) ⇒ Object




3146
3147
3148
3149
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3146

def [](s_language)
   s=self.to_s s_language
   return s
end

#[]=(s_language, s_message) ⇒ Object



3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3152

def []=(s_language, s_message)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_language
      kibuvits_krl171bt4_typecheck bn, String, s_message
   end # if
   @ht_msgs[$kibuvits_krl171bt4_lc_emptystring+s_language]=$kibuvits_krl171bt4_lc_emptystring+
   s_message # The "" is to avoid s.downcase!
   return nil
end

#assert_lack_of_failures(s_optional_error_message_suffix = nil) ⇒ Object

Throws, if self.b_failure==true



3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3130

def assert_lack_of_failures(s_optional_error_message_suffix=nil)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, [NilClass,String], s_optional_error_message_suffix
   end # if
   if b_failure
      s_msg=$kibuvits_krl171bt4_lc_linebreak+to_s()+$kibuvits_krl171bt4_lc_linebreak
      if s_optional_error_message_suffix.class==String
         s_msg<<(s_optional_error_message_suffix+$kibuvits_krl171bt4_lc_linebreak)
      end # if
      kibuvits_krl171bt4_throw(s_msg)
   end # if
end

#cloneObject

Creates a new Kibuvits_krl171bt4_msgc instance that has the same message values and s_message_id value, but a different s_instance_id.

To clone a Kibuvits_krl171bt4_msgc instance so that the s_instance_id of a clone matches that of the original, one should serialize the original and then instantiate the clone by using deserialization.



3171
3172
3173
3174
3175
3176
3177
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3171

def clone
   x_out=Kibuvits_krl171bt4_msgc.new(@ht_msgs[@s_default_language],
   @s_message_id, @b_failure, @s_default_language)
   @ht_msgs.each_pair {|s_language,s_msg| x_out[s_language]=s_msg}
   x_out.instance_variable_set(:@x_data,@x_data)
   return x_out
end

#s_message_idObject




3181
3182
3183
3184
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3181

def s_message_id
   s_out=$kibuvits_krl171bt4_lc_emptystring+@s_message_id
   return s_out
end

#s_message_id=(s_whatever_string) ⇒ Object

s_message_id



3186
3187
3188
3189
3190
3191
3192
3193
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3186

def s_message_id=(s_whatever_string)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_whatever_string
   end # if
   @s_message_id=$kibuvits_krl171bt4_lc_emptystring+s_whatever_string
   return nil
end

#s_serializeObject




3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3214

def s_serialize
   ht=Hash.new
   s_ht_msgs_progfte=nil
   @mx.synchronize do
      ht["s_message_id"]=@s_message_id
      if @b_failure
         ht["sb_failure"]="t"
      else
         ht["sb_failure"]="f"
      end # if
      ht["s_instance_id"]=@s_instance_id
      #-------------
      ht["x_data"]=$kibuvits_krl171bt4_lc_emptystring
      ht["x_data_class"]=nil.class.to_s
      x_data_class=@x_data.class
      if x_data_class==String
         ht["x_data"]=@x_data
      else
         if @x_data.respond_to? "s_serialize"
            ht["x_data"]=@x_data.s_serialize
         end # if
      end # if
      ht["x_data_class"]=x_data_class.to_s if ht["x_data"]!=nil
      #-------------
      ht["s_default_language"]=@s_default_language
      s_ht_msgs_progfte=Kibuvits_krl171bt4_ProgFTE.from_ht(@ht_msgs)
   end # synchronize
   ht["s_ht_msgs_progfte"]=s_ht_msgs_progfte
   s_instance_progfte=Kibuvits_krl171bt4_ProgFTE.from_ht(ht)
   ht_container=Hash.new
   ht_container[$kibuvits_krl171bt4_lc_s_version]=@@s_version
   ht_container[$kibuvits_krl171bt4_lc_s_type]="Kibuvits_krl171bt4_msgc"
   ht_container[$kibuvits_krl171bt4_lc_s_serialized]=s_instance_progfte
   s_progfte=Kibuvits_krl171bt4_ProgFTE.from_ht(ht_container)
   return s_progfte
end

#to_s(s_language = nil) ⇒ Object

b_failure=



3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3109

def to_s(s_language=nil)
   # The "s_language=nil" in the input parameters list is due to the
   # Kibuvits_krl171bt4_msgc_stack to_s implementation
   if KIBUVITS_krl171bt4_b_DEBUG
      kibuvits_krl171bt4_typecheck binding(), [NilClass,String], s_language
   end # if
   if s_language==nil
      s_language=@s_default_language
   else
      s_language=@s_default_language if !@ht_msgs.has_key? s_language
   end # if
   s=@ht_msgs[s_language]
   if 0<@s_location_marker_GUID.length
      s=s+("\nGUID='"+@s_location_marker_GUID+"'\n")
   end # if
   return $kibuvits_krl171bt4_lc_emptystring+s # The "" is to avoid s.downcase!
end

#x_dataObject




3197
3198
3199
3200
3201
3202
3203
3204
3205
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3197

def x_data
   x_out=nil
   if @x_data.class==String
      x_out=$kibuvits_krl171bt4_lc_emptystring+@x_data
   else
      x_out=@x_data
   end # if
   return x_out
end

#x_data=(x_data) ⇒ Object



3208
3209
3210
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 3208

def x_data=(x_data)
   @x_data=x_data
end