Module: EnumExt::Annotated
- Included in:
- EnumWrapper
- Defined in:
- lib/enum_ext/annotated.rb
Overview
I wanted to add some quick live annotation to what’s defined and how it could be used but have no idea how to do this in a super-neat way, so it a little bit chaotic and experimental
Instance Method Summary collapse
- #describe(short = true) ⇒ Object
-
#describe_basic ⇒ Object
call it to see what’s your enum current options are.
-
#describe_enum_i(output = true) ⇒ Object
——————————————————————– ————- per helpers describers ——————————- ——————————————————————–.
- #describe_humanizations(output = true) ⇒ Object
-
#describe_long ⇒ Object
call it to see which enum extensions are defined.
- #describe_mass_assign_enum(output = true) ⇒ Object
- #describe_multi_enum_scopes(output = true) ⇒ Object
- #describe_short ⇒ Object
- #describe_supersets(output = true) ⇒ Object
- #describe_translations(output = true) ⇒ Object
Instance Method Details
#describe(short = true) ⇒ Object
25 26 27 28 |
# File 'lib/enum_ext/annotated.rb', line 25 def describe(short = true) describe_basic short ? describe_short : describe_long end |
#describe_basic ⇒ Object
call it to see what’s your enum current options are
6 7 8 9 |
# File 'lib/enum_ext/annotated.rb', line 6 def describe_basic puts yellow( "Basic #{enum_name} definition: \n" ) print_hash(enum_values) end |
#describe_enum_i(output = true) ⇒ Object
————- per helpers describers ——————————-
46 47 48 49 50 51 52 53 54 |
# File 'lib/enum_ext/annotated.rb', line 46 def describe_enum_i(output = true) description = basic_helpers_usage_header(:enum_i) description << " \#{black(\"instance\")}.\#{cyan( enabled_features[:enum_i] )} \n # output will be same as \#{base_class.to_s}.\#{enum_name}[:\#{enabled_features[:key_sample]}]\n ENUM_I\n\n output ? puts(description) : description\nend\n" if enabled_features[:enum_i] |
#describe_humanizations(output = true) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/enum_ext/annotated.rb', line 113 def describe_humanizations(output = true) description = if enabled_features[:humanization].blank? red( "\nHumanization not used!\n" ) else red( "\nHumanization definitions (will skip instance dependent humanization)\n" ) << inspect_hash(enabled_features[:humanization]) end output ? puts(description) : description end |
#describe_long ⇒ Object
call it to see which enum extensions are defined.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/enum_ext/annotated.rb', line 12 def describe_long puts yellow( "\n\nEnumExt extensions:" ) puts [ describe_enum_i(false), describe_mass_assign_enum(false), describe_multi_enum_scopes(false), describe_supersets(false), describe_translations(false), describe_humanizations(false) ].join( "\n" + "-" * 100 + "\n" ) end |
#describe_mass_assign_enum(output = true) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/enum_ext/annotated.rb', line 56 def describe_mass_assign_enum(output = true) description = basic_helpers_usage_header(:mass_assign_enum) description << " # To assign \#{enabled_features[:key_sample]} to all elements of any_scope or relation call:\n \#{black(base_class.to_s)}.any_scope.\#{cyan( enabled_features[:mass_assign_enum] )}\n MASS_ASSIGN\n\n output ? puts(description) : description\nend\n" if enabled_features[:mass_assign_enum] |
#describe_multi_enum_scopes(output = true) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/enum_ext/annotated.rb', line 66 def describe_multi_enum_scopes(output = true) description = basic_helpers_usage_header(:multi_enum_scopes) description << " # Two scopes: with_\#{enum_name} and without_\#{enum_name} are defined\n # To get elements with a given enums or supersets values call:\n \#{black(base_class.to_s)}.\#{cyan(\"with_\#{enum_name}\")}(:\#{keys.sample(2).join(\", :\")})\n \\n# To get all elements except for the ones with enums or supersets values call:\n \#{black(base_class.to_s)}.\#{cyan(\"without_\#{enum_name}\")}(:\#{keys.sample(2).join(\", :\")})\n MULTI_SCOPES\n\n output ? puts(description) : description\nend\n" if enabled_features[:multi_enum_scopes] |
#describe_short ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/enum_ext/annotated.rb', line 30 def describe_short enabled, disabled = enabled_features.except(:key_sample).partition{!_2.blank?}.map{ |prt| prt.map(&:shift) } puts " \#{yellow(\"EnumExt extensions:\")}\n \#{cyan(\"Enabled\")}: \#{enabled.join(\", \")}\n \#{red(\"Disabled\")}: \#{disabled.join(\", \")}\n SHORT\n\n print_short(:supersets)\n print_short(:translations)\n print_short(:humanization)\nend\n" |
#describe_supersets(output = true) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/enum_ext/annotated.rb', line 79 def describe_supersets(output = true) description = if enabled_features[:supersets].blank? red( "\nSupersets not used!\n" ) else superset_method = enabled_features[:supersets].keys.first red( "\nSupersets definitions:\n" ) << inspect_hash(enabled_features[:supersets]) << " \n # Instance methods added: \#{enabled_features[:supersets].keys.join(\"?, \")}?\n # Usage:\n \#{black(\"instance\")}.\#{cyan(superset_method)}?\n # Will be equal true if any of: \#{supersets_raw[superset_method].join(\"?, \")}? is true\n \n # Class level methods/scopes added: \#{enabled_features[:supersets].keys.join(\", \")}\n # Usage:\n \#{black(base_class.to_s)}.\#{cyan(superset_method)}\n # Will be getting all instances with \#{enum_name} equals to any of: \#{supersets_raw[superset_method].join(\", \")}\n\n SUPERSETS\n end\n\n output ? puts(description) : description\nend\n" |
#describe_translations(output = true) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/enum_ext/annotated.rb', line 102 def describe_translations(output = true) description = if enabled_features[:translations].blank? red( "\nTranslations not used!\n" ) else red( "\nTranslations definitions (will skip instance dependent translation)\n" ) << inspect_hash(enabled_features[:translations]) end output ? puts(description) : description end |