Class: EnumExt::EnumWrapper
- Inherits:
-
Object
- Object
- EnumExt::EnumWrapper
- Includes:
- Annotated
- Defined in:
- lib/enum_ext/enum_wrapper.rb
Overview
This is an wrapper class for a basic enum. Since enum values will be freezed right after the definition, we can’t enrich enum directly functionality We can only wrap it with our own object and delegate enum base base functionality internally
Instance Attribute Summary collapse
-
#base_class ⇒ Object
readonly
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses.
-
#enum_name ⇒ Object
readonly
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses.
-
#enum_values ⇒ Object
readonly
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses.
-
#localizations ⇒ Object
(also: #t)
readonly
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses.
-
#prefix ⇒ Object
readonly
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses.
-
#suffix ⇒ Object
readonly
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses.
-
#supersets ⇒ Object
readonly
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses.
-
#supersets_raw ⇒ Object
readonly
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses.
-
#t_options_raw ⇒ Object
readonly
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses.
Instance Method Summary collapse
- #all ⇒ Object
-
#initialize(enum_values, base_class, enum_name, **options) ⇒ EnumWrapper
constructor
A new instance of EnumWrapper.
-
#superset_to_enum(*enum_or_sets) ⇒ Object
ext_sets_to_kinds( :ready_for_shipment, :delivery_set ) –> [:ready_for_shipment, :on_delivery, :delivered].
- #t_options ⇒ Object
- #t_options_i ⇒ Object
- #transform_enum_label(label) ⇒ Object
Methods included from Annotated
#describe, #describe_basic, #describe_enum_i, #describe_humanizations, #describe_long, #describe_mass_assign_enum, #describe_multi_enum_scopes, #describe_short, #describe_supersets, #describe_translations
Constructor Details
#initialize(enum_values, base_class, enum_name, **options) ⇒ EnumWrapper
Returns a new instance of EnumWrapper.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/enum_ext/enum_wrapper.rb', line 13 def initialize(enum_values, base_class, enum_name, **) @enum_values = enum_values @supersets = ActiveSupport::HashWithIndifferentAccess.new @supersets_raw = ActiveSupport::HashWithIndifferentAccess.new @t_options_raw = ActiveSupport::HashWithIndifferentAccess.new @localizations = ActiveSupport::HashWithIndifferentAccess.new @base_class = base_class @enum_name = enum_name @suffix = [:suffix] || [:_suffix] @prefix = [:prefix] || [:_prefix] end |
Instance Attribute Details
#base_class ⇒ Object (readonly)
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses
8 9 10 |
# File 'lib/enum_ext/enum_wrapper.rb', line 8 def base_class @base_class end |
#enum_name ⇒ Object (readonly)
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses
8 9 10 |
# File 'lib/enum_ext/enum_wrapper.rb', line 8 def enum_name @enum_name end |
#enum_values ⇒ Object (readonly)
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses
8 9 10 |
# File 'lib/enum_ext/enum_wrapper.rb', line 8 def enum_values @enum_values end |
#localizations ⇒ Object (readonly) Also known as: t
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses
8 9 10 |
# File 'lib/enum_ext/enum_wrapper.rb', line 8 def localizations @localizations end |
#prefix ⇒ Object (readonly)
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses
8 9 10 |
# File 'lib/enum_ext/enum_wrapper.rb', line 8 def prefix @prefix end |
#suffix ⇒ Object (readonly)
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses
8 9 10 |
# File 'lib/enum_ext/enum_wrapper.rb', line 8 def suffix @suffix end |
#supersets ⇒ Object (readonly)
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses
8 9 10 |
# File 'lib/enum_ext/enum_wrapper.rb', line 8 def supersets @supersets end |
#supersets_raw ⇒ Object (readonly)
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses
8 9 10 |
# File 'lib/enum_ext/enum_wrapper.rb', line 8 def supersets_raw @supersets_raw end |
#t_options_raw ⇒ Object (readonly)
supersets is storing exact definitions, if you need a raw mapping use class.statuses.superset_statuses
8 9 10 |
# File 'lib/enum_ext/enum_wrapper.rb', line 8 def @t_options_raw end |
Instance Method Details
#all ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/enum_ext/enum_wrapper.rb', line 37 def all { **enum_values, supersets: { **send(:supersets_raw) } } end |
#superset_to_enum(*enum_or_sets) ⇒ Object
ext_sets_to_kinds( :ready_for_shipment, :delivery_set ) –>
[:ready_for_shipment, :on_delivery, :delivered]
29 30 31 32 33 34 35 |
# File 'lib/enum_ext/enum_wrapper.rb', line 29 def superset_to_enum( *enum_or_sets ) return [] if enum_or_sets.blank? enum_or_sets_strs = enum_or_sets.map(&:to_s) next_level_deeper = supersets.slice( *enum_or_sets_strs ).values.flatten (enum_or_sets_strs & enum_values.keys | send(:superset_to_enum, *next_level_deeper)).uniq end |
#t_options ⇒ Object
50 51 52 |
# File 'lib/enum_ext/enum_wrapper.rb', line 50 def evaluate_localizations(localizations) end |
#t_options_i ⇒ Object
46 47 48 |
# File 'lib/enum_ext/enum_wrapper.rb', line 46 def evaluate_localizations_to_i(localizations) end |
#transform_enum_label(label) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/enum_ext/enum_wrapper.rb', line 56 def transform_enum_label(label) _prefix = if prefix prefix == true ? "#{enum_name}_" : "#{prefix}_" end _suffix = if suffix suffix == true ? "_#{enum_name}" : "_#{suffix}" end "#{_prefix}#{label}#{_suffix}" end |