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
    
        data/MIT-LICENSE
    DELETED
    
    | @@ -1,22 +0,0 @@ | |
| 1 | 
            -
            (The MIT X11 License)
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            Copyright (c) 2011 Kenichi Kamiya
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 6 | 
            -
            a copy of this software and associated documentation files (the
         | 
| 7 | 
            -
            'Software'), to deal in the Software without restriction, including
         | 
| 8 | 
            -
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 9 | 
            -
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 10 | 
            -
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 11 | 
            -
            the following conditions:
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            The above copyright notice and this permission notice shall be
         | 
| 14 | 
            -
            included in all copies or substantial portions of the Software.
         | 
| 15 | 
            -
             | 
| 16 | 
            -
            THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
         | 
| 17 | 
            -
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 18 | 
            -
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
         | 
| 19 | 
            -
            IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
         | 
| 20 | 
            -
            CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
         | 
| 21 | 
            -
            TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
         | 
| 22 | 
            -
            SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/Rakefile
    DELETED
    
    
    
        data/benchmark/basics.rb
    DELETED
    
    | @@ -1,56 +0,0 @@ | |
| 1 | 
            -
            #/usr/bin/ruby -w
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            require 'benchmark'
         | 
| 4 | 
            -
            require_relative '../lib/striuct'
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            XStruct = Struct.new :any, :no_use1, :no_use2
         | 
| 7 | 
            -
             | 
| 8 | 
            -
            XStriuct = Striuct.define do
         | 
| 9 | 
            -
              member :any
         | 
| 10 | 
            -
              member :int, Integer
         | 
| 11 | 
            -
              member :truthy, ->v{v}
         | 
| 12 | 
            -
            end
         | 
| 13 | 
            -
             | 
| 14 | 
            -
            xstruct = XStruct.new
         | 
| 15 | 
            -
            xstriuct = XStriuct.new
         | 
| 16 | 
            -
             | 
| 17 | 
            -
            TIMES = 100000
         | 
| 18 | 
            -
            OBJ = 123
         | 
| 19 | 
            -
             | 
| 20 | 
            -
            Benchmark.bm do |bm|
         | 
| 21 | 
            -
              bm.report 'Struct(equal Noguard): Setter' do
         | 
| 22 | 
            -
                TIMES.times do
         | 
| 23 | 
            -
                  xstruct.any = OBJ
         | 
| 24 | 
            -
                end
         | 
| 25 | 
            -
              end
         | 
| 26 | 
            -
              
         | 
| 27 | 
            -
              bm.report 'Struct: Reader' do
         | 
| 28 | 
            -
                TIMES.times do
         | 
| 29 | 
            -
                  xstruct.any
         | 
| 30 | 
            -
                end
         | 
| 31 | 
            -
              end
         | 
| 32 | 
            -
              
         | 
| 33 | 
            -
              bm.report 'Striuct(when Noguard): Setter' do
         | 
| 34 | 
            -
                TIMES.times do
         | 
| 35 | 
            -
                  xstriuct.any = OBJ
         | 
| 36 | 
            -
                end
         | 
| 37 | 
            -
              end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
              bm.report 'Striuct(guard under class): Setter' do
         | 
| 40 | 
            -
                TIMES.times do
         | 
| 41 | 
            -
                  xstriuct.int = OBJ
         | 
| 42 | 
            -
                end
         | 
| 43 | 
            -
              end
         | 
| 44 | 
            -
              
         | 
| 45 | 
            -
              bm.report 'Striuct(guard under function)' do
         | 
| 46 | 
            -
                TIMES.times do
         | 
| 47 | 
            -
                  xstriuct.truthy = OBJ
         | 
| 48 | 
            -
                end
         | 
| 49 | 
            -
              end
         | 
| 50 | 
            -
              
         | 
| 51 | 
            -
              bm.report 'Striuct: Reader' do
         | 
| 52 | 
            -
                TIMES.times do
         | 
| 53 | 
            -
                  xstriuct.any
         | 
| 54 | 
            -
                end
         | 
| 55 | 
            -
              end
         | 
| 56 | 
            -
            end
         | 
    
        data/example/README.rb
    DELETED
    
    | @@ -1,53 +0,0 @@ | |
| 1 | 
            -
            $VERBOSE = true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            require_relative '../lib/striuct'
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            class Person < Striuct
         | 
| 6 | 
            -
              member :fullname, AND(String, /\A.+\z/)     # Flexible Validation
         | 
| 7 | 
            -
              alias_member :name, :fullname               # Use other name
         | 
| 8 | 
            -
            end
         | 
| 9 | 
            -
             | 
| 10 | 
            -
            class User < Person                           # Inheritable
         | 
| 11 | 
            -
              member :id, Integer,                        # Looks typed validation
         | 
| 12 | 
            -
                          default_proc: ->{User.next_id}  # With default value
         | 
| 13 | 
            -
             | 
| 14 | 
            -
              @id = 0
         | 
| 15 | 
            -
              def self.next_id
         | 
| 16 | 
            -
                @id += 1
         | 
| 17 | 
            -
              end
         | 
| 18 | 
            -
            end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
            john = User.new 'john'
         | 
| 21 | 
            -
            p john[:name]      #=> 'john' 
         | 
| 22 | 
            -
            #~ p john.name = ''  #=> error
         | 
| 23 | 
            -
            p john.id          #=> 1
         | 
| 24 | 
            -
            ken = User[name: 'ken']                       # Construct from hash
         | 
| 25 | 
            -
            p ken.id           #=> 2
         | 
| 26 | 
            -
             | 
| 27 | 
            -
            class Foo < Striuct
         | 
| 28 | 
            -
              member :foo
         | 
| 29 | 
            -
              member :bar, Numeric,
         | 
| 30 | 
            -
                           inference: true
         | 
| 31 | 
            -
              member :with_adjuster, Integer,
         | 
| 32 | 
            -
                                     &->v{Integer v}
         | 
| 33 | 
            -
            end
         | 
| 34 | 
            -
             | 
| 35 | 
            -
            foo = Foo.new
         | 
| 36 | 
            -
            p foo.foo           #=> nil
         | 
| 37 | 
            -
            p foo.assigned?(:foo) #=> false
         | 
| 38 | 
            -
            foo.foo = nil
         | 
| 39 | 
            -
            p foo.assigned?(:foo) #=> true
         | 
| 40 | 
            -
            foo.lock(:foo)
         | 
| 41 | 
            -
            #~ foo.foo = nil       #=> error
         | 
| 42 | 
            -
            foo.bar = 1.2
         | 
| 43 | 
            -
            #~ foo.bar = 1          #=> error
         | 
| 44 | 
            -
             | 
| 45 | 
            -
            foo.with_adjuster = '5'
         | 
| 46 | 
            -
            p foo.with_adjuster
         | 
| 47 | 
            -
             | 
| 48 | 
            -
            class UseMustOption < Striuct
         | 
| 49 | 
            -
              member :foo, Integer, must: true
         | 
| 50 | 
            -
            end
         | 
| 51 | 
            -
             | 
| 52 | 
            -
            #~ p UseMustOption.new #=> InvalidOperationError
         | 
| 53 | 
            -
            p UseMustOption.new(1)
         | 
    
        data/example/example1.rb
    DELETED
    
    | @@ -1,235 +0,0 @@ | |
| 1 | 
            -
            #/usr/bin/ruby -w
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            require_relative '../lib/striuct'
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            def debug(message)
         | 
| 6 | 
            -
              puts "line: #{caller.first.slice(/:(\w+)/, 1)}"
         | 
| 7 | 
            -
              puts message.inspect, '-' * 80
         | 
| 8 | 
            -
            end
         | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
            # 1. Struct+ "Secure"
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            # macro "member" provides to use condtions
         | 
| 14 | 
            -
            class User < Striuct.new
         | 
| 15 | 
            -
              member :id,   Integer
         | 
| 16 | 
            -
              member :age,  (20..140)
         | 
| 17 | 
            -
              member :name, OR(/\A\w+\z/, /\A\w+ \w+\z/)
         | 
| 18 | 
            -
            end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
            user = User.new 128381, 20
         | 
| 21 | 
            -
            debug user
         | 
| 22 | 
            -
             | 
| 23 | 
            -
            user.age = 30
         | 
| 24 | 
            -
            user[2] = 'taro yamada'
         | 
| 25 | 
            -
            debug user
         | 
| 26 | 
            -
             | 
| 27 | 
            -
            # fail (Exception  Striuct::ConditionError)
         | 
| 28 | 
            -
            begin
         | 
| 29 | 
            -
              user[:id] = 10.0
         | 
| 30 | 
            -
            rescue
         | 
| 31 | 
            -
              debug $!
         | 
| 32 | 
            -
            end
         | 
| 33 | 
            -
             | 
| 34 | 
            -
            begin
         | 
| 35 | 
            -
              user.age = 19
         | 
| 36 | 
            -
            rescue
         | 
| 37 | 
            -
              debug $!
         | 
| 38 | 
            -
            end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
            begin
         | 
| 41 | 
            -
              user[2] = 'typo! name'
         | 
| 42 | 
            -
            rescue
         | 
| 43 | 
            -
              debug $!
         | 
| 44 | 
            -
            end
         | 
| 45 | 
            -
             | 
| 46 | 
            -
            # more detail checker do you need, use functional object
         | 
| 47 | 
            -
            module Game
         | 
| 48 | 
            -
              class Character
         | 
| 49 | 
            -
              end
         | 
| 50 | 
            -
             | 
| 51 | 
            -
              class DB < Striuct.new
         | 
| 52 | 
            -
                member :monsters,   ->list{(list - characters).empty?}
         | 
| 53 | 
            -
                member :characters, GENERICS(Character)
         | 
| 54 | 
            -
              end
         | 
| 55 | 
            -
              
         | 
| 56 | 
            -
              monster = Character.new
         | 
| 57 | 
            -
              db = DB.new
         | 
| 58 | 
            -
              
         | 
| 59 | 
            -
              begin
         | 
| 60 | 
            -
                db.characters = [1, 2]
         | 
| 61 | 
            -
              rescue
         | 
| 62 | 
            -
                debug $!
         | 
| 63 | 
            -
              end
         | 
| 64 | 
            -
              
         | 
| 65 | 
            -
              db.characters = [monster, Character.new]
         | 
| 66 | 
            -
              debug db
         | 
| 67 | 
            -
              
         | 
| 68 | 
            -
              begin
         | 
| 69 | 
            -
                db.monsters = [Character.new]
         | 
| 70 | 
            -
              rescue
         | 
| 71 | 
            -
                debug $!
         | 
| 72 | 
            -
              end
         | 
| 73 | 
            -
              
         | 
| 74 | 
            -
              db.monsters = [monster]
         | 
| 75 | 
            -
              debug db
         | 
| 76 | 
            -
            end
         | 
| 77 | 
            -
             | 
| 78 | 
            -
            # through "inference", and check under first passed object class
         | 
| 79 | 
            -
            class FlexibleContainer < Striuct.new
         | 
| 80 | 
            -
              member :anything, BasicObject, inference: true
         | 
| 81 | 
            -
              member :number,   Numeric, inference: true
         | 
| 82 | 
            -
            end
         | 
| 83 | 
            -
             | 
| 84 | 
            -
            fc1, fc2 = FlexibleContainer.new, FlexibleContainer.new
         | 
| 85 | 
            -
            fc1.anything = 'str'
         | 
| 86 | 
            -
            debug fc1
         | 
| 87 | 
            -
            begin
         | 
| 88 | 
            -
              fc1.anything = :sym
         | 
| 89 | 
            -
            rescue
         | 
| 90 | 
            -
              debug $!
         | 
| 91 | 
            -
            end
         | 
| 92 | 
            -
             | 
| 93 | 
            -
            begin
         | 
| 94 | 
            -
              fc2.anything = :sym
         | 
| 95 | 
            -
            rescue
         | 
| 96 | 
            -
              debug $!
         | 
| 97 | 
            -
            end
         | 
| 98 | 
            -
             | 
| 99 | 
            -
            fc2.anything = 'string too'
         | 
| 100 | 
            -
             | 
| 101 | 
            -
            debug fc2
         | 
| 102 | 
            -
             | 
| 103 | 
            -
            begin
         | 
| 104 | 
            -
              fc1.number = 'str'
         | 
| 105 | 
            -
            rescue
         | 
| 106 | 
            -
              debug $!
         | 
| 107 | 
            -
            end
         | 
| 108 | 
            -
             | 
| 109 | 
            -
            fc1.number = 1.0
         | 
| 110 | 
            -
            debug fc1
         | 
| 111 | 
            -
             | 
| 112 | 
            -
            begin
         | 
| 113 | 
            -
              fc2.number = 1
         | 
| 114 | 
            -
            rescue
         | 
| 115 | 
            -
              debug $!
         | 
| 116 | 
            -
            end
         | 
| 117 | 
            -
             | 
| 118 | 
            -
            # Standard Struct not check member name. 
         | 
| 119 | 
            -
            NoGuard = Struct.new :__send__, :'?  !'
         | 
| 120 | 
            -
            noguard = NoGuard.new false
         | 
| 121 | 
            -
            debug noguard.__send__
         | 
| 122 | 
            -
            debug noguard.methods.include?(:'?  !') # lost!!
         | 
| 123 | 
            -
             | 
| 124 | 
            -
            # Striuct provides safety levels for naming.
         | 
| 125 | 
            -
            class SafetyNaming < Striuct.new
         | 
| 126 | 
            -
              begin
         | 
| 127 | 
            -
                member :__send__
         | 
| 128 | 
            -
              rescue
         | 
| 129 | 
            -
                debug $!
         | 
| 130 | 
            -
              end
         | 
| 131 | 
            -
              
         | 
| 132 | 
            -
              begin
         | 
| 133 | 
            -
                member :'?  !'
         | 
| 134 | 
            -
              rescue
         | 
| 135 | 
            -
                debug $!
         | 
| 136 | 
            -
              end
         | 
| 137 | 
            -
              
         | 
| 138 | 
            -
              # tempolary set lower
         | 
| 139 | 
            -
              conflict_management :struct do
         | 
| 140 | 
            -
                member :__send__, :'?  !'
         | 
| 141 | 
            -
              end
         | 
| 142 | 
            -
              
         | 
| 143 | 
            -
            end
         | 
| 144 | 
            -
             | 
| 145 | 
            -
            # 2. Struct+ "Handy"
         | 
| 146 | 
            -
             | 
| 147 | 
            -
            # to through block called "flavor"
         | 
| 148 | 
            -
            # below case for type cast
         | 
| 149 | 
            -
            class User2 < Striuct.new
         | 
| 150 | 
            -
              member :age, OR(/\A\d+\z/, Numeric) do |arg|
         | 
| 151 | 
            -
                Integer arg
         | 
| 152 | 
            -
              end
         | 
| 153 | 
            -
              
         | 
| 154 | 
            -
              member :name, ->v{v.respond_to? :to_s} do |v|
         | 
| 155 | 
            -
                v.to_s.to_sym
         | 
| 156 | 
            -
              end
         | 
| 157 | 
            -
            end
         | 
| 158 | 
            -
             | 
| 159 | 
            -
            user2 = User2.new
         | 
| 160 | 
            -
            user2.age = 9
         | 
| 161 | 
            -
            debug user2
         | 
| 162 | 
            -
             | 
| 163 | 
            -
            user2.age = 10.1
         | 
| 164 | 
            -
            debug user2
         | 
| 165 | 
            -
             | 
| 166 | 
            -
            user2.age = '10'
         | 
| 167 | 
            -
            debug user2
         | 
| 168 | 
            -
             | 
| 169 | 
            -
            user2.name = 10
         | 
| 170 | 
            -
            debug user2
         | 
| 171 | 
            -
            user2.name = Class
         | 
| 172 | 
            -
            debug user2
         | 
| 173 | 
            -
             | 
| 174 | 
            -
            # Default value
         | 
| 175 | 
            -
             | 
| 176 | 
            -
            class User3 < Striuct.new
         | 
| 177 | 
            -
              member  :lank, Fixnum
         | 
| 178 | 
            -
              default :lank, 3
         | 
| 179 | 
            -
              member  :name
         | 
| 180 | 
            -
            end
         | 
| 181 | 
            -
             | 
| 182 | 
            -
            user3 = User3.new
         | 
| 183 | 
            -
            user3
         | 
| 184 | 
            -
            debug user3
         | 
| 185 | 
            -
             | 
| 186 | 
            -
            # Standard Struct always define "nil is default". ...realy?
         | 
| 187 | 
            -
            debug user3.assigned?(:name)
         | 
| 188 | 
            -
            user3.name = nil
         | 
| 189 | 
            -
            debug user3.assigned?(:name)
         | 
| 190 | 
            -
             | 
| 191 | 
            -
            # Alias
         | 
| 192 | 
            -
             | 
| 193 | 
            -
            class User3
         | 
| 194 | 
            -
              alias_member :position, :lank
         | 
| 195 | 
            -
            end
         | 
| 196 | 
            -
             | 
| 197 | 
            -
            debug user3.lank.equal?(user3.position)
         | 
| 198 | 
            -
            debug user3[:lank].equal?(user3[:position])
         | 
| 199 | 
            -
            user3[:position] = 4
         | 
| 200 | 
            -
            debug user3.lank
         | 
| 201 | 
            -
             | 
| 202 | 
            -
            # New Constructors
         | 
| 203 | 
            -
             | 
| 204 | 
            -
            # Subclass.define reject floating object
         | 
| 205 | 
            -
            # * except if no finished assign each members
         | 
| 206 | 
            -
            # * return object is frozen
         | 
| 207 | 
            -
            user3 = User3.define do |r|
         | 
| 208 | 
            -
              r.lank = 10
         | 
| 209 | 
            -
              r.name = 'foo'
         | 
| 210 | 
            -
            end
         | 
| 211 | 
            -
             | 
| 212 | 
            -
            debug user3
         | 
| 213 | 
            -
             | 
| 214 | 
            -
            # Subclass.load_pairs easy make from Hash and like Hash
         | 
| 215 | 
            -
            user3 = User3[lank:10, name: 'foo']
         | 
| 216 | 
            -
             | 
| 217 | 
            -
            debug user3
         | 
| 218 | 
            -
             | 
| 219 | 
            -
            # 3. Keeping Struct's good interface
         | 
| 220 | 
            -
             | 
| 221 | 
            -
            Sth1 = Striuct.new do
         | 
| 222 | 
            -
              def my_special_method
         | 
| 223 | 
            -
              end
         | 
| 224 | 
            -
            end
         | 
| 225 | 
            -
             | 
| 226 | 
            -
            debug Sth1.new.respond_to?(:my_special_method)
         | 
| 227 | 
            -
             | 
| 228 | 
            -
            # to_struct
         | 
| 229 | 
            -
            MyC = Striuct.new :a, :b
         | 
| 230 | 
            -
            a =  MyC.to_struct_class
         | 
| 231 | 
            -
            p a
         | 
| 232 | 
            -
             | 
| 233 | 
            -
            p MyC.new.to_struct
         | 
| 234 | 
            -
            myc = Striuct.new :a, :b
         | 
| 235 | 
            -
            p myc.new.to_struct
         | 
    
        data/example/example2.rb
    DELETED
    
    | @@ -1,22 +0,0 @@ | |
| 1 | 
            -
            #!/usr/local/bin/ruby -w
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            $VERBOSE = true
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            require_relative '../lib/striuct'
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            User = Striuct.define do  # other way "class User < Striuct.new"
         | 
| 8 | 
            -
              member :firstname, /\w+/ # look like case syntax in Ruby
         | 
| 9 | 
            -
              member :lank, AND(Fixnum, 1..10) # easy build multiple validation
         | 
| 10 | 
            -
              default :lank, 3        # set a normal default value
         | 
| 11 | 
            -
              member :registered, Time # look like type variable
         | 
| 12 | 
            -
              default :registered, &->{Time.now} # evaluate with construction          
         | 
| 13 | 
            -
              p members #=> [firstname, lank, registered]
         | 
| 14 | 
            -
            end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
            class MyUser < User
         | 
| 17 | 
            -
              p members #=> [firstname, lank, registered]
         | 
| 18 | 
            -
              member :foo # no validation, just an accessor
         | 
| 19 | 
            -
              p members #=> [firstname, lank, registered, :foo]
         | 
| 20 | 
            -
            end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
            user = MyUser.new
         | 
    
        data/example/see_trace.rb
    DELETED
    
    | @@ -1,32 +0,0 @@ | |
| 1 | 
            -
            #/usr/bin/ruby -w
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            require_relative '../lib/striuct'
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            class User < Striuct.new
         | 
| 6 | 
            -
              member :id,   Integer
         | 
| 7 | 
            -
              member :age,  (20..140)
         | 
| 8 | 
            -
            end
         | 
| 9 | 
            -
             | 
| 10 | 
            -
            user = User.new
         | 
| 11 | 
            -
             | 
| 12 | 
            -
            begin
         | 
| 13 | 
            -
              user[:id] = 10.0
         | 
| 14 | 
            -
            rescue
         | 
| 15 | 
            -
              puts $!.backtrace
         | 
| 16 | 
            -
            end
         | 
| 17 | 
            -
             | 
| 18 | 
            -
            puts '-' * 80
         | 
| 19 | 
            -
             | 
| 20 | 
            -
            $stdout.flush
         | 
| 21 | 
            -
             | 
| 22 | 
            -
            begin
         | 
| 23 | 
            -
              user.age = 19
         | 
| 24 | 
            -
            rescue
         | 
| 25 | 
            -
              puts $!.backtrace
         | 
| 26 | 
            -
            end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
            puts '-' * 80
         | 
| 29 | 
            -
             | 
| 30 | 
            -
            $stdout.flush
         | 
| 31 | 
            -
             | 
| 32 | 
            -
            user.age = 19
         | 
    
        data/striuct.gemspec
    DELETED
    
    | @@ -1,36 +0,0 @@ | |
| 1 | 
            -
            Gem::Specification.new do |gem|
         | 
| 2 | 
            -
              # specific
         | 
| 3 | 
            -
             | 
| 4 | 
            -
              gem.description   = %q{Struct++ library.
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            ---
         | 
| 7 | 
            -
             | 
| 8 | 
            -
              Validatable, Inheritable, Member Aliasing,
         | 
| 9 | 
            -
              Conflict Management, Default Value, Divide nil with unassign,
         | 
| 10 | 
            -
              Lock setter of each member, Hash flendly API, ... And more Struct++ features :)}
         | 
| 11 | 
            -
             | 
| 12 | 
            -
              gem.summary       = gem.description.dup
         | 
| 13 | 
            -
              gem.homepage      = 'http://kachick.github.com/striuct/'
         | 
| 14 | 
            -
              gem.license       = 'MIT'
         | 
| 15 | 
            -
              gem.name          = 'striuct'
         | 
| 16 | 
            -
              gem.version       = '0.4.4'
         | 
| 17 | 
            -
             | 
| 18 | 
            -
              gem.required_ruby_version = '>= 1.9.2'
         | 
| 19 | 
            -
             | 
| 20 | 
            -
              gem.add_runtime_dependency 'validation', '~> 0.0.5'
         | 
| 21 | 
            -
              gem.add_runtime_dependency 'optionalargument', '~> 0.0.3'
         | 
| 22 | 
            -
              gem.add_runtime_dependency 'keyvalidatable', '~> 0.0.5'
         | 
| 23 | 
            -
             | 
| 24 | 
            -
              gem.add_development_dependency 'yard', '>= 0.8.6.1', '< 2'
         | 
| 25 | 
            -
              gem.add_development_dependency 'rake', '>= 10', '< 20'
         | 
| 26 | 
            -
              gem.add_development_dependency 'bundler', '>= 1.3.5', '< 2'
         | 
| 27 | 
            -
             | 
| 28 | 
            -
              # common
         | 
| 29 | 
            -
             | 
| 30 | 
            -
              gem.authors       = ['Kenichi Kamiya']
         | 
| 31 | 
            -
              gem.email         = ['kachick1+ruby@gmail.com']
         | 
| 32 | 
            -
              gem.files         = `git ls-files`.split($\)
         | 
| 33 | 
            -
              gem.executables   = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
         | 
| 34 | 
            -
              gem.test_files    = gem.files.grep(%r{^(test|spec|features)/})
         | 
| 35 | 
            -
              gem.require_paths = ['lib']
         | 
| 36 | 
            -
            end
         |