striuct 0.4.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE.txt +21 -0
- data/README.md +20 -41
- data/lib/striuct.rb +3 -3
- data/lib/striuct/classmethods/README.md +2 -2
- data/lib/striuct/classmethods/adjustment.rb +15 -13
- data/lib/striuct/classmethods/attributes.rb +93 -91
- data/lib/striuct/classmethods/conflict_management.rb +109 -106
- data/lib/striuct/classmethods/constructor.rb +47 -54
- data/lib/striuct/classmethods/copy.rb +45 -43
- data/lib/striuct/classmethods/default.rb +23 -21
- data/lib/striuct/classmethods/enum.rb +46 -44
- data/lib/striuct/classmethods/fix.rb +23 -21
- data/lib/striuct/classmethods/hashdeepdupulicatable.rb +14 -16
- data/lib/striuct/classmethods/inner.rb +57 -64
- data/lib/striuct/classmethods/length.rb +12 -10
- data/lib/striuct/classmethods/macro.rb +109 -111
- data/lib/striuct/classmethods/names.rb +69 -65
- data/lib/striuct/classmethods/predicate.rb +131 -138
- data/lib/striuct/classmethods/requirements.rb +3 -1
- data/lib/striuct/classmethods/to_struct.rb +21 -18
- data/lib/striuct/classmethods/validation.rb +15 -13
- data/lib/striuct/instancemethods/README.md +2 -2
- data/lib/striuct/instancemethods/assign.rb +29 -27
- data/lib/striuct/instancemethods/cast.rb +28 -26
- data/lib/striuct/instancemethods/compare.rb +26 -24
- data/lib/striuct/instancemethods/default.rb +31 -29
- data/lib/striuct/instancemethods/delegate_class_methods.rb +36 -32
- data/lib/striuct/instancemethods/enum.rb +86 -84
- data/lib/striuct/instancemethods/getter.rb +39 -37
- data/lib/striuct/instancemethods/hashy.rb +99 -97
- data/lib/striuct/instancemethods/keyvalidatable.rb +8 -6
- data/lib/striuct/instancemethods/lock.rb +46 -44
- data/lib/striuct/instancemethods/object.rb +50 -48
- data/lib/striuct/instancemethods/requirements.rb +11 -9
- data/lib/striuct/instancemethods/safety.rb +11 -9
- data/lib/striuct/instancemethods/setter.rb +46 -49
- data/lib/striuct/instancemethods/to_s.rb +39 -37
- data/lib/striuct/instancemethods/validation.rb +31 -29
- data/lib/striuct/instancemethods/values.rb +52 -33
- data/lib/striuct/requirements.rb +3 -1
- data/lib/striuct/singleton_class.rb +12 -17
- data/lib/striuct/structs.rb +3 -3
- metadata +48 -186
- data/.gitignore +0 -35
- data/.travis.yml +0 -20
- data/.yardopts +0 -1
- data/Gemfile +0 -11
- data/History.old(~0.3.n).rdoc +0 -289
- data/MIT-LICENSE +0 -22
- data/Rakefile +0 -10
- data/benchmark/basics.rb +0 -56
- data/example/README.rb +0 -53
- data/example/example1.rb +0 -235
- data/example/example2.rb +0 -22
- data/example/see_trace.rb +0 -32
- data/striuct.gemspec +0 -36
- data/test/helper.rb +0 -5
- data/test/test_sglc-constructor.rb +0 -36
- data/test/test_subc-c-add_members.rb +0 -13
- data/test/test_subc-c-close_member.rb +0 -36
- data/test/test_subc-c-constructor.rb +0 -92
- data/test/test_subc-c-copy.rb +0 -71
- data/test/test_subc-c-freeze.rb +0 -36
- data/test/test_subc-c-inheritable.rb +0 -58
- data/test/test_subc-c-safety_naming.rb +0 -73
- data/test/test_subc-f-alias_member.rb +0 -54
- data/test/test_subc-f-enum.rb +0 -139
- data/test/test_subc-f-predicate.rb +0 -711
- data/test/test_subc-f-to_struct.rb +0 -61
- data/test/test_subc-f-validation_util.rb +0 -59
- data/test/test_subc-f_debug.rb +0 -39
- data/test/test_subc-f_name.rb +0 -525
- data/test/test_subc-i-accessor.rb +0 -138
- data/test/test_subc-i-adjuster.rb +0 -95
- data/test/test_subc-i-assign.rb +0 -53
- data/test/test_subc-i-basic.rb +0 -32
- data/test/test_subc-i-cast.rb +0 -27
- data/test/test_subc-i-compare.rb +0 -52
- data/test/test_subc-i-copy.rb +0 -23
- data/test/test_subc-i-default_value.rb +0 -129
- data/test/test_subc-i-freeze.rb +0 -19
- data/test/test_subc-i-hashlike.rb +0 -144
- data/test/test_subc-i-keyvalidatable.rb +0 -25
- data/test/test_subc-i-lock.rb +0 -40
- data/test/test_subc-i-must.rb +0 -30
- data/test/test_subc-i-to_s_family.rb +0 -26
- data/test/test_subc-i-validation_inference.rb +0 -51
- data/test/test_subc-i-validation_specific_conditions.rb +0 -297
- data/test/test_subc-i-validation_with_getter.rb +0 -33
- data/test/test_version.rb +0 -13
| @@ -1,14 +1,16 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 3 | 
            +
            class Striuct
         | 
| 4 | 
            +
              module ClassMethods
         | 
| 5 | 
            +
                # @group Length/Size
         | 
| 4 6 |  | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
              
         | 
| 10 | 
            -
              alias_method :size, :length
         | 
| 7 | 
            +
                # @return [Integer]
         | 
| 8 | 
            +
                def length
         | 
| 9 | 
            +
                  @autonyms.length
         | 
| 10 | 
            +
                end
         | 
| 11 11 |  | 
| 12 | 
            -
             | 
| 12 | 
            +
                alias_method :size, :length
         | 
| 13 13 |  | 
| 14 | 
            -
             | 
| 14 | 
            +
                # @endgroup
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
            end
         | 
| @@ -1,122 +1,120 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
                 | 
| 10 | 
            -
                 | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
                   | 
| 48 | 
            -
             | 
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Striuct
         | 
| 4 | 
            +
              module ClassMethods
         | 
| 5 | 
            +
                # @group Macro for Member Definition
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                ANYTHING = ::Validation::Condition.anything
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                # @return [Class]
         | 
| 10 | 
            +
                ADD_MEMBER_OptArg = OptionalArgument.define {
         | 
| 11 | 
            +
                  opt(:default_value, aliases: [:default])
         | 
| 12 | 
            +
                  opt(:default_proc, aliases: [:lazy_default])
         | 
| 13 | 
            +
                  conflict(:default_value, :default_proc)
         | 
| 14 | 
            +
                  opt(:must, default: false)
         | 
| 15 | 
            +
                  opt(:setter_validation, aliases: [:writer_validation], default: true)
         | 
| 16 | 
            +
                  opt(:getter_validation, aliases: [:reader_validation], default: false)
         | 
| 17 | 
            +
                }
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                private
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                # @param [Symbol, String, #to_sym] autonym
         | 
| 22 | 
            +
                # @param [#===, Proc, Method] condition
         | 
| 23 | 
            +
                # @param [Hash] options
         | 
| 24 | 
            +
                # @option options [BasicObject] :default
         | 
| 25 | 
            +
                # @option options [Proc] :default_proc
         | 
| 26 | 
            +
                # @option options [Boolean] :must
         | 
| 27 | 
            +
                # @option options [Boolean] :reader_validation
         | 
| 28 | 
            +
                # @option options [Boolean] :getter_validation
         | 
| 29 | 
            +
                # @option options [Boolean] :writer_validation
         | 
| 30 | 
            +
                # @option options [Boolean] :setter_validation
         | 
| 31 | 
            +
                # @return [nil]
         | 
| 32 | 
            +
                def add_member(autonym, condition=anything, options={}, &adjuster)
         | 
| 33 | 
            +
                  _check_frozen
         | 
| 34 | 
            +
                  _check_closed
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  options = ADD_MEMBER_OptArg.parse(options)
         | 
| 37 | 
            +
                  autonym = autonym.to_sym # First definition for an autonym
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  raise ArgumentError, %Q!already exist name "#{autonym}"! if member?(autonym)
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  _check_safety_naming(autonym)
         | 
| 42 | 
            +
                  _add_autonym(autonym)
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  _attributes_for(autonym).safety_setter = !!options.setter_validation
         | 
| 45 | 
            +
                  _attributes_for(autonym).safety_getter = !!options.getter_validation
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                  if options.must
         | 
| 48 | 
            +
                    _attributes_for(autonym).must = true
         | 
| 49 | 
            +
                  end
         | 
| 49 50 |  | 
| 50 | 
            -
             | 
| 51 | 
            -
                   | 
| 51 | 
            +
                  _def_getter(autonym)
         | 
| 52 | 
            +
                  _def_setter(autonym, condition, &adjuster)
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  case
         | 
| 55 | 
            +
                  when options.default_value?
         | 
| 56 | 
            +
                    set_default_value(autonym, options.default_value)
         | 
| 57 | 
            +
                  when options.default_proc?
         | 
| 58 | 
            +
                    set_default_value(autonym, &options.default_proc)
         | 
| 59 | 
            +
                  end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                  nil
         | 
| 52 62 | 
             
                end
         | 
| 53 63 |  | 
| 54 | 
            -
                 | 
| 55 | 
            -
             | 
| 56 | 
            -
                
         | 
| 57 | 
            -
                 | 
| 58 | 
            -
                 | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
                   | 
| 64 | 
            +
                alias_method :member, :add_member
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                # @param [Symbol, String, #to_sym] autonym
         | 
| 67 | 
            +
                # @param [Symbol, String, #to_sym] autonyms
         | 
| 68 | 
            +
                # @return [nil]
         | 
| 69 | 
            +
                def add_members(autonym, *autonyms)
         | 
| 70 | 
            +
                  _check_frozen
         | 
| 71 | 
            +
                  _check_closed
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                  [autonym, *autonyms].each { |name| add_member(name) }
         | 
| 74 | 
            +
                  nil
         | 
| 62 75 | 
             
                end
         | 
| 63 | 
            -
                
         | 
| 64 | 
            -
                nil
         | 
| 65 | 
            -
              end
         | 
| 66 76 |  | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
             | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 77 | 
            +
                # @param [Symbol, String, #to_sym] aliased
         | 
| 78 | 
            +
                # @param [Symbol, String, #to_sym] autonym
         | 
| 79 | 
            +
                # @return [nil]
         | 
| 80 | 
            +
                def alias_member(aliased, autonym)
         | 
| 81 | 
            +
                  _check_frozen
         | 
| 82 | 
            +
                  _check_closed
         | 
| 83 | 
            +
                  autonym = autonym_for_member(autonym)
         | 
| 84 | 
            +
                  aliased = aliased.to_sym
         | 
| 85 | 
            +
                  raise ArgumentError, %Q!already exist name "#{aliased}"! if member?(aliased)
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                  _check_safety_naming(aliased)
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                  alias_method(aliased, autonym)
         | 
| 90 | 
            +
                  alias_method(:"#{aliased}=", :"#{autonym}=")
         | 
| 91 | 
            +
                  @aliases[aliased] = autonym
         | 
| 92 | 
            +
                  nil
         | 
| 93 | 
            +
                end
         | 
| 79 94 |  | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 96 | 
            -
              
         | 
| 97 | 
            -
              # @param [Symbol, String, #to_sym] name
         | 
| 98 | 
            -
              # @return [nil]
         | 
| 99 | 
            -
              def set_default_value(name, value=nil, &block)
         | 
| 100 | 
            -
                _check_frozen
         | 
| 101 | 
            -
                _check_closed
         | 
| 102 | 
            -
                autonym = autonym_for_member name
         | 
| 103 | 
            -
                raise "already settled default value for #{name}" if with_default? autonym
         | 
| 104 | 
            -
             | 
| 105 | 
            -
                if block_given?
         | 
| 106 | 
            -
                  unless value.nil?
         | 
| 107 | 
            -
                    raise ArgumentError, 'can not use default-value with default-proc'
         | 
| 95 | 
            +
                # @param [Symbol, String, #to_sym] name
         | 
| 96 | 
            +
                # @return [nil]
         | 
| 97 | 
            +
                def set_default_value(name, value=nil, &block)
         | 
| 98 | 
            +
                  _check_frozen
         | 
| 99 | 
            +
                  _check_closed
         | 
| 100 | 
            +
                  autonym = autonym_for_member(name)
         | 
| 101 | 
            +
                  raise "already settled default value for #{name}" if with_default?(autonym)
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                  if block
         | 
| 104 | 
            +
                    unless value.nil?
         | 
| 105 | 
            +
                      raise ArgumentError, 'can not use default-value with default-proc'
         | 
| 106 | 
            +
                    end
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                    _attributes_for(autonym).set_default(block, :lazy)
         | 
| 109 | 
            +
                  else
         | 
| 110 | 
            +
                    _attributes_for(autonym).set_default(value, :value)
         | 
| 108 111 | 
             
                  end
         | 
| 109 112 |  | 
| 110 | 
            -
                   | 
| 111 | 
            -
                else
         | 
| 112 | 
            -
                  _attributes_for(autonym).set_default value, :value
         | 
| 113 | 
            +
                  nil
         | 
| 113 114 | 
             
                end
         | 
| 114 | 
            -
                
         | 
| 115 | 
            -
                nil
         | 
| 116 | 
            -
              end
         | 
| 117 | 
            -
              
         | 
| 118 | 
            -
              alias_method :default, :set_default_value
         | 
| 119 115 |  | 
| 120 | 
            -
             | 
| 116 | 
            +
                alias_method :default, :set_default_value
         | 
| 121 117 |  | 
| 122 | 
            -
             | 
| 118 | 
            +
                # @endgroup
         | 
| 119 | 
            +
              end
         | 
| 120 | 
            +
            end
         | 
| @@ -1,75 +1,79 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 3 | 
            +
            class Striuct
         | 
| 4 | 
            +
              module ClassMethods
         | 
| 5 | 
            +
                # @group Named
         | 
| 4 6 |  | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 7 | 
            +
                # @return [Array<Symbol>]
         | 
| 8 | 
            +
                def autonyms
         | 
| 9 | 
            +
                  @autonyms.dup
         | 
| 10 | 
            +
                end
         | 
| 9 11 |  | 
| 10 | 
            -
             | 
| 11 | 
            -
              
         | 
| 12 | 
            -
              # @return [Array<Symbol>]
         | 
| 13 | 
            -
              def all_members
         | 
| 14 | 
            -
                @autonyms + @aliases.keys
         | 
| 15 | 
            -
              end
         | 
| 16 | 
            -
             
         | 
| 17 | 
            -
              # @param [Symbol, String, #to_sym] als
         | 
| 18 | 
            -
              # @return [Symbol]
         | 
| 19 | 
            -
              def autonym_for_alias(als) 
         | 
| 20 | 
            -
                @aliases.fetch als.to_sym
         | 
| 21 | 
            -
              rescue NoMethodError
         | 
| 22 | 
            -
                raise TypeError
         | 
| 23 | 
            -
              rescue KeyError
         | 
| 24 | 
            -
                raise NameError
         | 
| 25 | 
            -
              end
         | 
| 12 | 
            +
                alias_method :members, :autonyms
         | 
| 26 13 |  | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
                 | 
| 31 | 
            -
                name = name.to_sym
         | 
| 32 | 
            -
                
         | 
| 33 | 
            -
                @autonyms.include?(name) ? name : autonym_for_alias(name)
         | 
| 34 | 
            -
              end
         | 
| 14 | 
            +
                # @return [Array<Symbol>]
         | 
| 15 | 
            +
                def all_members
         | 
| 16 | 
            +
                  @autonyms + @aliases.keys
         | 
| 17 | 
            +
                end
         | 
| 35 18 |  | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 19 | 
            +
                # @param [Symbol, String, #to_sym] als
         | 
| 20 | 
            +
                # @return [Symbol]
         | 
| 21 | 
            +
                def autonym_for_alias(als)
         | 
| 22 | 
            +
                  @aliases.fetch(als.to_sym)
         | 
| 23 | 
            +
                rescue NoMethodError
         | 
| 24 | 
            +
                  raise TypeError
         | 
| 25 | 
            +
                rescue KeyError
         | 
| 26 | 
            +
                  raise NameError
         | 
| 27 | 
            +
                end
         | 
| 41 28 |  | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
              rescue NameError, IndexError, TypeError
         | 
| 47 | 
            -
                raise KeyError
         | 
| 48 | 
            -
              end
         | 
| 29 | 
            +
                # @param [Symbol, String, #to_sym] name - autonym / aliased
         | 
| 30 | 
            +
                # @return [Symbol]
         | 
| 31 | 
            +
                def autonym_for_member(name)
         | 
| 32 | 
            +
                  raise TypeError unless name.respond_to?(:to_sym)
         | 
| 49 33 |  | 
| 50 | 
            -
             | 
| 51 | 
            -
              # @return [Array<Symbol>]
         | 
| 52 | 
            -
              def aliases_for_autonym(autonym)
         | 
| 53 | 
            -
                raise TypeError unless autonym.respond_to?(:to_sym)
         | 
| 54 | 
            -
                autonym = autonym.to_sym
         | 
| 55 | 
            -
                raise NameError unless with_aliases? autonym
         | 
| 34 | 
            +
                  name = name.to_sym
         | 
| 56 35 |  | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
              
         | 
| 60 | 
            -
              # @return [Hash] alias => autonym
         | 
| 61 | 
            -
              def aliases
         | 
| 62 | 
            -
                @aliases.dup
         | 
| 63 | 
            -
              end
         | 
| 64 | 
            -
              
         | 
| 65 | 
            -
              private
         | 
| 36 | 
            +
                  @autonyms.include?(name) ? name : autonym_for_alias(name)
         | 
| 37 | 
            +
                end
         | 
| 66 38 |  | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
              
         | 
| 73 | 
            -
              # @endgroup
         | 
| 39 | 
            +
                # @param [Index, #to_int] index
         | 
| 40 | 
            +
                # @return [Symbol] autonym
         | 
| 41 | 
            +
                def autonym_for_index(index)
         | 
| 42 | 
            +
                  @autonyms.fetch(index)
         | 
| 43 | 
            +
                end
         | 
| 74 44 |  | 
| 75 | 
            -
             | 
| 45 | 
            +
                # @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
         | 
| 46 | 
            +
                # @return [Symbol] autonym
         | 
| 47 | 
            +
                def autonym_for_key(key)
         | 
| 48 | 
            +
                  key.respond_to?(:to_sym) ? autonym_for_member(key) : autonym_for_index(key)
         | 
| 49 | 
            +
                rescue NameError, IndexError, TypeError
         | 
| 50 | 
            +
                  raise KeyError
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                # @param [Symbol, String, #to_sym] autonym
         | 
| 54 | 
            +
                # @return [Array<Symbol>]
         | 
| 55 | 
            +
                def aliases_for_autonym(autonym)
         | 
| 56 | 
            +
                  raise TypeError unless autonym.respond_to?(:to_sym)
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                  autonym = autonym.to_sym
         | 
| 59 | 
            +
                  raise NameError unless with_aliases?(autonym)
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                  @aliases.select { |_als, aut| autonym == aut }.keys
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                # @return [Hash] alias => autonym
         | 
| 65 | 
            +
                def aliases
         | 
| 66 | 
            +
                  @aliases.dup
         | 
| 67 | 
            +
                end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                private
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                # for direct access inner data from own instance
         | 
| 72 | 
            +
                # @return [Hash] alias => autonym
         | 
| 73 | 
            +
                def _autonyms
         | 
| 74 | 
            +
                  @autonyms
         | 
| 75 | 
            +
                end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                # @endgroup
         | 
| 78 | 
            +
              end
         | 
| 79 | 
            +
            end
         | 
| @@ -1,139 +1,132 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
                 | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
                 | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
                 | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
                @ | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
                 | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
                 | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
                 | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
             | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
                 | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Striuct
         | 
| 4 | 
            +
              module ClassMethods
         | 
| 5 | 
            +
                # @group Basic Predicate
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                # @param [Symbol, String, #to_sym] name
         | 
| 8 | 
            +
                def has_autonym?(name)
         | 
| 9 | 
            +
                  name = name.to_sym
         | 
| 10 | 
            +
                rescue NoMethodError
         | 
| 11 | 
            +
                  false
         | 
| 12 | 
            +
                else
         | 
| 13 | 
            +
                  @autonyms.include?(name)
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                alias_method :autonym?, :has_autonym?
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                # @param [Symbol, String, #to_sym] als
         | 
| 19 | 
            +
                def has_alias?(als)
         | 
| 20 | 
            +
                  als = als.to_sym
         | 
| 21 | 
            +
                rescue NoMethodError
         | 
| 22 | 
            +
                  false
         | 
| 23 | 
            +
                else
         | 
| 24 | 
            +
                  @aliases.key?(als)
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                alias_method :alias?, :has_alias?
         | 
| 28 | 
            +
                alias_method :aliased?, :has_alias? # obsolete
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                # @param [Symbol, String, #to_sym] name
         | 
| 31 | 
            +
                def has_member?(name)
         | 
| 32 | 
            +
                  autonym_for_member(name)
         | 
| 33 | 
            +
                rescue Exception
         | 
| 34 | 
            +
                  false
         | 
| 35 | 
            +
                else
         | 
| 36 | 
            +
                  true
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                alias_method :member?, :has_member?
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                # @param [Integer, #to_int] index
         | 
| 42 | 
            +
                def has_index?(index)
         | 
| 43 | 
            +
                  @autonyms.fetch(index)
         | 
| 44 | 
            +
                rescue Exception
         | 
| 45 | 
            +
                  false
         | 
| 46 | 
            +
                else
         | 
| 47 | 
            +
                  true
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                alias_method :index?, :has_index?
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                # @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
         | 
| 53 | 
            +
                def has_key?(key)
         | 
| 54 | 
            +
                  has_member?(key) || has_index?(key)
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                alias_method :key?, :has_key?
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                # @param [Symbol, String, #to_sym] autonym
         | 
| 60 | 
            +
                def with_aliases?(autonym)
         | 
| 61 | 
            +
                  autonym = autonym.to_sym
         | 
| 62 | 
            +
                rescue NoMethodError
         | 
| 63 | 
            +
                  false
         | 
| 64 | 
            +
                else
         | 
| 65 | 
            +
                  @aliases.value?(autonym)
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                # @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
         | 
| 69 | 
            +
                def with_default?(key)
         | 
| 70 | 
            +
                  autonym = autonym_for_key(key)
         | 
| 71 | 
            +
                rescue Exception
         | 
| 72 | 
            +
                  false
         | 
| 73 | 
            +
                else
         | 
| 74 | 
            +
                  _attributes_for(autonym).with_default?
         | 
| 75 | 
            +
                end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                # @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
         | 
| 78 | 
            +
                def with_condition?(key)
         | 
| 79 | 
            +
                  autonym = autonym_for_key(key)
         | 
| 80 | 
            +
                rescue Exception
         | 
| 81 | 
            +
                  false
         | 
| 82 | 
            +
                else
         | 
| 83 | 
            +
                  _attributes_for(autonym).with_condition?
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                alias_method :restrict?, :with_condition?
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                # @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
         | 
| 89 | 
            +
                def with_must?(key)
         | 
| 90 | 
            +
                  autonym = autonym_for_key(key)
         | 
| 91 | 
            +
                rescue Exception
         | 
| 92 | 
            +
                  false
         | 
| 93 | 
            +
                else
         | 
| 94 | 
            +
                  _attributes_for(autonym).with_must?
         | 
| 95 | 
            +
                end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                alias_method :must?, :with_must?
         | 
| 98 | 
            +
             | 
| 99 | 
            +
                # @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
         | 
| 100 | 
            +
                def with_safety_getter?(key)
         | 
| 101 | 
            +
                  autonym = autonym_for_key(key)
         | 
| 102 | 
            +
                rescue Exception
         | 
| 103 | 
            +
                  false
         | 
| 104 | 
            +
                else
         | 
| 105 | 
            +
                  _attributes_for(autonym).with_safety_getter?
         | 
| 106 | 
            +
                end
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                alias_method :with_safety_reader?, :with_safety_getter?
         | 
| 109 | 
            +
             | 
| 110 | 
            +
                # @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
         | 
| 111 | 
            +
                def with_safety_setter?(key)
         | 
| 112 | 
            +
                  autonym = autonym_for_key(key)
         | 
| 113 | 
            +
                rescue Exception
         | 
| 114 | 
            +
                  false
         | 
| 115 | 
            +
                else
         | 
| 116 | 
            +
                  _attributes_for(autonym).with_safety_setter?
         | 
| 117 | 
            +
                end
         | 
| 118 | 
            +
             | 
| 119 | 
            +
                alias_method :with_safety_writer?, :with_safety_setter?
         | 
| 120 | 
            +
             | 
| 121 | 
            +
                # @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
         | 
| 122 | 
            +
                def with_adjuster?(key)
         | 
| 123 | 
            +
                  autonym = autonym_for_key(key)
         | 
| 124 | 
            +
                rescue Exception
         | 
| 125 | 
            +
                  false
         | 
| 126 | 
            +
                else
         | 
| 127 | 
            +
                  _attributes_for(autonym).with_adjuster?
         | 
| 128 | 
            +
                end
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                # @endgroup
         | 
| 82 131 | 
             
              end
         | 
| 83 | 
            -
             | 
| 84 | 
            -
              alias_method :restrict?, :with_condition?  
         | 
| 85 | 
            -
             | 
| 86 | 
            -
              # @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
         | 
| 87 | 
            -
              def with_inference?(key)
         | 
| 88 | 
            -
                autonym = autonym_for_key key
         | 
| 89 | 
            -
              rescue Exception
         | 
| 90 | 
            -
                false
         | 
| 91 | 
            -
              else
         | 
| 92 | 
            -
                _attributes_for(autonym).with_inference?
         | 
| 93 | 
            -
              end
         | 
| 94 | 
            -
             | 
| 95 | 
            -
              # @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
         | 
| 96 | 
            -
              def with_must?(key)
         | 
| 97 | 
            -
                autonym = autonym_for_key key
         | 
| 98 | 
            -
              rescue Exception
         | 
| 99 | 
            -
                false
         | 
| 100 | 
            -
              else
         | 
| 101 | 
            -
                _attributes_for(autonym).with_must?
         | 
| 102 | 
            -
              end
         | 
| 103 | 
            -
             | 
| 104 | 
            -
              alias_method :must?, :with_must?
         | 
| 105 | 
            -
             | 
| 106 | 
            -
              # @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
         | 
| 107 | 
            -
              def with_safety_getter?(key)
         | 
| 108 | 
            -
                autonym = autonym_for_key key
         | 
| 109 | 
            -
              rescue Exception
         | 
| 110 | 
            -
                false
         | 
| 111 | 
            -
              else
         | 
| 112 | 
            -
                _attributes_for(autonym).with_safety_getter?
         | 
| 113 | 
            -
              end
         | 
| 114 | 
            -
              
         | 
| 115 | 
            -
              alias_method :with_safety_reader?, :with_safety_getter?
         | 
| 116 | 
            -
              
         | 
| 117 | 
            -
              # @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
         | 
| 118 | 
            -
              def with_safety_setter?(key)
         | 
| 119 | 
            -
                autonym = autonym_for_key key
         | 
| 120 | 
            -
              rescue Exception
         | 
| 121 | 
            -
                false
         | 
| 122 | 
            -
              else
         | 
| 123 | 
            -
                _attributes_for(autonym).with_safety_setter?
         | 
| 124 | 
            -
              end
         | 
| 125 | 
            -
             | 
| 126 | 
            -
              alias_method :with_safety_writer?, :with_safety_setter?
         | 
| 127 | 
            -
             | 
| 128 | 
            -
              # @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
         | 
| 129 | 
            -
              def with_adjuster?(key)
         | 
| 130 | 
            -
                autonym = autonym_for_key key
         | 
| 131 | 
            -
              rescue Exception
         | 
| 132 | 
            -
                false
         | 
| 133 | 
            -
              else
         | 
| 134 | 
            -
                _attributes_for(autonym).with_adjuster?
         | 
| 135 | 
            -
              end
         | 
| 136 | 
            -
             | 
| 137 | 
            -
              # @endgroup
         | 
| 138 | 
            -
             | 
| 139 | 
            -
            end; end
         | 
| 132 | 
            +
            end
         |