ruby_ext 0.4.11 → 0.4.12
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.
- data/Rakefile +6 -6
 - data/lib/rake_ext.rb +10 -5
 - data/lib/rake_ext/project.rb +31 -16
 - data/lib/rspec_ext.rb +82 -19
 - data/lib/ruby_ext.rb +1 -52
 - data/lib/ruby_ext/core.rb +24 -0
 - data/lib/ruby_ext/{array.rb → core/array.rb} +4 -2
 - data/lib/ruby_ext/core/basic_object.rb +8 -0
 - data/lib/ruby_ext/core/class.rb +0 -0
 - data/lib/ruby_ext/{deep_clone.rb → core/deep_clone.rb} +3 -4
 - data/lib/ruby_ext/core/enumerable.rb +17 -0
 - data/lib/ruby_ext/{file.rb → core/file.rb} +5 -2
 - data/lib/ruby_ext/core/hash.rb +23 -0
 - data/lib/ruby_ext/{kernel.rb → core/kernel.rb} +0 -0
 - data/lib/ruby_ext/{micelaneous.rb → core/micelaneous.rb} +0 -0
 - data/lib/ruby_ext/{module.rb → core/module.rb} +13 -2
 - data/lib/ruby_ext/{multiple_inheritance.rb → core/multiple_inheritance.rb} +30 -14
 - data/lib/ruby_ext/{must.rb → core/must.rb} +30 -27
 - data/lib/ruby_ext/{not_defined.rb → core/not_defined.rb} +0 -0
 - data/lib/ruby_ext/{object.rb → core/object.rb} +0 -0
 - data/lib/ruby_ext/{open_object.rb → core/open_object.rb} +21 -16
 - data/lib/ruby_ext/{string.rb → core/string.rb} +27 -0
 - data/lib/ruby_ext/{symbol.rb → core/symbol.rb} +0 -0
 - data/lib/ruby_ext/fixes.rb +6 -0
 - data/lib/ruby_ext/gems.rb +0 -1
 - data/lib/ruby_ext/more.rb +11 -0
 - data/lib/ruby_ext/more/declarative_cache.rb +96 -0
 - data/lib/ruby_ext/more/micelaneous.rb +7 -0
 - data/lib/ruby_ext/{observable2.rb → more/observable2.rb} +0 -0
 - data/lib/ruby_ext/{open_constructor.rb → more/open_constructor.rb} +2 -2
 - data/lib/ruby_ext/more/safe_hash.rb +214 -0
 - data/lib/ruby_ext/{synchronize.rb → more/synchronize.rb} +5 -5
 - data/lib/ruby_ext/{tuple.rb → more/tuple.rb} +0 -0
 - data/lib/yaml_fix.rb +9 -0
 - data/readme.md +46 -42
 - data/spec/core/array_spec.rb +7 -0
 - data/spec/{deep_clone_spec.rb → core/deep_clone_spec.rb} +2 -3
 - data/spec/core/enumerable.rb +9 -0
 - data/spec/{kernel_spec.rb → core/kernel_spec.rb} +4 -6
 - data/spec/{kernel_spec → core/kernel_spec}/TheNamespace/ClassA.rb +0 -0
 - data/spec/{kernel_spec → core/kernel_spec}/another_class.rb +0 -0
 - data/spec/{kernel_spec → core/kernel_spec}/the_namespace/class_b.rb +0 -0
 - data/spec/{module_spec.rb → core/module_spec.rb} +2 -4
 - data/spec/{multiple_inheritance_spec.rb → core/multiple_inheritance_spec.rb} +28 -12
 - data/spec/core/must_spec.rb +32 -0
 - data/spec/{open_object_spec.rb → core/open_object_spec.rb} +6 -7
 - data/spec/core/spec_helper.rb +2 -0
 - data/spec/{declarative_cache_spec.rb → more/declarative_cache_spec.rb} +35 -8
 - data/spec/{observable2_spec.rb → more/observable2_spec.rb} +3 -4
 - data/spec/{open_constructor_spec.rb → more/open_constructor_spec.rb} +6 -7
 - data/spec/more/safe_hash_spec.rb +133 -0
 - data/spec/more/spec_helper.rb +2 -0
 - data/spec/{synchronize_spec.rb → more/synchronize_spec.rb} +2 -3
 - metadata +67 -100
 - data/lib/ruby_ext/basic_object.rb +0 -22
 - data/lib/ruby_ext/class.rb +0 -11
 - data/lib/ruby_ext/declarative_cache.rb +0 -85
 - data/lib/ruby_ext/extra_blank_slate.rb +0 -17
 - data/lib/ruby_ext/hash.rb +0 -15
 - data/lib/ruby_ext/prepare_arguments.rb +0 -105
 - data/lib/ruby_ext/prototype_inheritance.rb +0 -110
 - data/lib/ruby_ext/should.rb +0 -166
 - data/lib/rubyopt.rb +0 -7
 - data/spec/_prototype_inheritance_spec.rb +0 -190
 - data/spec/array_spec.rb +0 -8
 - data/spec/must_spec.rb +0 -29
 - data/spec/prepare_arguments_spec.rb +0 -46
 - data/spec/should_spec.rb +0 -24
 - data/spec/spec_helper.rb +0 -19
 
| 
         @@ -1,8 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'fileutils'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            File.class_eval do
         
     | 
| 
      
 4 
     | 
    
         
            +
              def file_name
         
     | 
| 
      
 5 
     | 
    
         
            +
                File.basename path
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
              
         
     | 
| 
       4 
8 
     | 
    
         
             
              class << self
         
     | 
| 
       5 
     | 
    
         
            -
                
         
     | 
| 
       6 
9 
     | 
    
         
             
                def write(path, data)
         
     | 
| 
       7 
10 
     | 
    
         
             
                  File.open(path, "wb") do |file|
         
     | 
| 
       8 
11 
     | 
    
         
             
                    return file.write(data)
         
     | 
| 
         @@ -14,7 +17,7 @@ File.class_eval do 
     | 
|
| 
       14 
17 
     | 
    
         
             
                end
         
     | 
| 
       15 
18 
     | 
    
         | 
| 
       16 
19 
     | 
    
         
             
                def delete_directory dir
         
     | 
| 
       17 
     | 
    
         
            -
                  FileUtils.rm_r dir, : 
     | 
| 
      
 20 
     | 
    
         
            +
                  FileUtils.rm_r dir, force: true if File.exist? dir
         
     | 
| 
       18 
21 
     | 
    
         
             
                end
         
     | 
| 
       19 
22 
     | 
    
         
             
              end
         
     | 
| 
       20 
23 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Hash
         
     | 
| 
      
 2 
     | 
    
         
            +
              def subset *keys, &block
         
     | 
| 
      
 3 
     | 
    
         
            +
                keys = keys.first if keys.first.is_a? Array
         
     | 
| 
      
 4 
     | 
    
         
            +
                h = {}    
         
     | 
| 
      
 5 
     | 
    
         
            +
                if keys
         
     | 
| 
      
 6 
     | 
    
         
            +
                  self.each do |k, v|
         
     | 
| 
      
 7 
     | 
    
         
            +
                    h[k] = v if keys.include? k
         
     | 
| 
      
 8 
     | 
    
         
            +
                  end
         
     | 
| 
      
 9 
     | 
    
         
            +
                else
         
     | 
| 
      
 10 
     | 
    
         
            +
                  self.each do |k, v|
         
     | 
| 
      
 11 
     | 
    
         
            +
                    h[k] = v if block.call k
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
                h
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
                
         
     | 
| 
      
 17 
     | 
    
         
            +
              def validate_options! *valid_options
         
     | 
| 
      
 18 
     | 
    
         
            +
                unknown_options = keys - valid_options
         
     | 
| 
      
 19 
     | 
    
         
            +
                raise "unknown options :#{unknown_options.join(': ')}!" unless unknown_options.empty?
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
              
         
     | 
| 
      
 22 
     | 
    
         
            +
              alias_method :to_h, :to_hash
         
     | 
| 
      
 23 
     | 
    
         
            +
            end
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         @@ -1,6 +1,16 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'set'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            Module.class_eval do
         
     | 
| 
      
 4 
     | 
    
         
            +
              def alias name = nil
         
     | 
| 
      
 5 
     | 
    
         
            +
                if name
         
     | 
| 
      
 6 
     | 
    
         
            +
                  name.must_be.a String
         
     | 
| 
      
 7 
     | 
    
         
            +
                  name.must_not_be.blank
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @alias = name.to_s
         
     | 
| 
      
 9 
     | 
    
         
            +
                else
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @alias ||= self.name.split('::').last
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
              
         
     | 
| 
       4 
14 
     | 
    
         
             
              def is?(base)
         
     | 
| 
       5 
15 
     | 
    
         
             
                ancestors.include?(base)
         
     | 
| 
       6 
16 
     | 
    
         
             
              end
         
     | 
| 
         @@ -47,6 +57,7 @@ Module.class_eval do 
     | 
|
| 
       47 
57 
     | 
    
         
             
                each_namespace &b
         
     | 
| 
       48 
58 
     | 
    
         
             
              end
         
     | 
| 
       49 
59 
     | 
    
         | 
| 
      
 60 
     | 
    
         
            +
              # TODO cache it?
         
     | 
| 
       50 
61 
     | 
    
         
             
              def self.namespace_for class_name
         
     | 
| 
       51 
62 
     | 
    
         
             
                list = class_name.split("::")
         
     | 
| 
       52 
63 
     | 
    
         
             
                if list.size > 1
         
     | 
| 
         @@ -112,8 +123,8 @@ Module.class_eval do 
     | 
|
| 
       112 
123 
     | 
    
         
             
                m = method.to_s.clone
         
     | 
| 
       113 
124 
     | 
    
         
             
                ESCAPE_METHOD_SYMBOLS.each{|from, to| m.gsub! from, to}
         
     | 
| 
       114 
125 
     | 
    
         
             
                raise "Invalid method name '#{method}'!" unless m =~ /^[_a-zA-Z0-9]+$/
         
     | 
| 
       115 
     | 
    
         
            -
                m
         
     | 
| 
      
 126 
     | 
    
         
            +
                m.to_sym
         
     | 
| 
       116 
127 
     | 
    
         
             
              end
         
     | 
| 
       117 
128 
     | 
    
         | 
| 
       118 
     | 
    
         
            -
              public :include
         
     | 
| 
      
 129 
     | 
    
         
            +
              public :include, :define_method
         
     | 
| 
       119 
130 
     | 
    
         
             
            end
         
     | 
| 
         @@ -19,14 +19,14 @@ class Module 
     | 
|
| 
       19 
19 
     | 
    
         
             
                @directly_included_by ||= Set.new
         
     | 
| 
       20 
20 
     | 
    
         
             
              end
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
              def  
     | 
| 
       23 
     | 
    
         
            -
                unless mod.directly_included_by.include? self
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
              def include2 mod
         
     | 
| 
      
 23 
     | 
    
         
            +
                # unless mod.directly_included_by.include? self
         
     | 
| 
      
 24 
     | 
    
         
            +
                mod.directly_included_by.add self
         
     | 
| 
      
 25 
     | 
    
         
            +
                # end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
                include mod
         
     | 
| 
       28 
28 
     | 
    
         
             
                directly_included_by.each do |child|
         
     | 
| 
       29 
     | 
    
         
            -
                  child. 
     | 
| 
      
 29 
     | 
    
         
            +
                  child.include2 self
         
     | 
| 
       30 
30 
     | 
    
         
             
                end
         
     | 
| 
       31 
31 
     | 
    
         
             
              end
         
     | 
| 
       32 
32 
     | 
    
         
             
            end
         
     | 
| 
         @@ -38,12 +38,19 @@ end 
     | 
|
| 
       38 
38 
     | 
    
         
             
            class Module
         
     | 
| 
       39 
39 
     | 
    
         
             
              def class_prototype
         
     | 
| 
       40 
40 
     | 
    
         
             
                unless @class_prototype
         
     | 
| 
       41 
     | 
    
         
            -
                   
     | 
| 
      
 41 
     | 
    
         
            +
                  ancestor = ancestors[1]
         
     | 
| 
      
 42 
     | 
    
         
            +
                  if(
         
     | 
| 
      
 43 
     | 
    
         
            +
                    !const_defined?(:ClassMethods) or 
         
     | 
| 
      
 44 
     | 
    
         
            +
                    (
         
     | 
| 
      
 45 
     | 
    
         
            +
                      const_defined?(:ClassMethods) and ancestor and ancestor.const_defined?(:ClassMethods) and 
         
     | 
| 
      
 46 
     | 
    
         
            +
                      const_get(:ClassMethods) == ancestor.const_get(:ClassMethods)
         
     | 
| 
      
 47 
     | 
    
         
            +
                    )
         
     | 
| 
      
 48 
     | 
    
         
            +
                  )
         
     | 
| 
       42 
49 
     | 
    
         
             
                    class_eval "module ClassMethods; end", __FILE__, __LINE__        
         
     | 
| 
       43 
50 
     | 
    
         
             
                  end      
         
     | 
| 
       44 
51 
     | 
    
         
             
                  @class_prototype = const_get :ClassMethods
         
     | 
| 
       45 
52 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
                  (class << self; self end). 
     | 
| 
      
 53 
     | 
    
         
            +
                  (class << self; self end).include2 @class_prototype
         
     | 
| 
       47 
54 
     | 
    
         
             
                end
         
     | 
| 
       48 
55 
     | 
    
         
             
                @class_prototype
         
     | 
| 
       49 
56 
     | 
    
         
             
              end
         
     | 
| 
         @@ -57,20 +64,29 @@ class Module 
     | 
|
| 
       57 
64 
     | 
    
         
             
                end
         
     | 
| 
       58 
65 
     | 
    
         
             
              end
         
     | 
| 
       59 
66 
     | 
    
         | 
| 
      
 67 
     | 
    
         
            +
              def inherited &b
         
     | 
| 
      
 68 
     | 
    
         
            +
                @inherited = b if b
         
     | 
| 
      
 69 
     | 
    
         
            +
                @inherited
         
     | 
| 
      
 70 
     | 
    
         
            +
              end
         
     | 
| 
      
 71 
     | 
    
         
            +
              
         
     | 
| 
       60 
72 
     | 
    
         
             
              def inherit *modules
         
     | 
| 
       61 
73 
     | 
    
         
             
                modules.each do |mod|
         
     | 
| 
       62 
74 
     | 
    
         
             
                  # Instance Methods
         
     | 
| 
       63 
     | 
    
         
            -
                   
     | 
| 
      
 75 
     | 
    
         
            +
                  include2 mod
         
     | 
| 
       64 
76 
     | 
    
         | 
| 
       65 
77 
     | 
    
         
             
                  # Class Methods
         
     | 
| 
       66 
     | 
    
         
            -
                   
     | 
| 
       67 
     | 
    
         
            -
                     
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
      
 78 
     | 
    
         
            +
                  unless self.class_prototype == mod.class_prototype
         
     | 
| 
      
 79 
     | 
    
         
            +
                    if self.class == Module   
         
     | 
| 
      
 80 
     | 
    
         
            +
            # p self => self.class_prototype, mod => mod.class_prototype             
         
     | 
| 
      
 81 
     | 
    
         
            +
                      class_prototype.include2 mod.class_prototype
         
     | 
| 
      
 82 
     | 
    
         
            +
                    else        
         
     | 
| 
      
 83 
     | 
    
         
            +
                      (class << self; self end).include2 mod.class_prototype
         
     | 
| 
      
 84 
     | 
    
         
            +
                    end          
         
     | 
| 
      
 85 
     | 
    
         
            +
                  end
         
     | 
| 
       71 
86 
     | 
    
         | 
| 
       72 
87 
     | 
    
         
             
                  # callback
         
     | 
| 
       73 
     | 
    
         
            -
                  mod.inherited self if mod.respond_to? :inherited
         
     | 
| 
      
 88 
     | 
    
         
            +
                  # mod.inherited self if mod.respond_to? :inherited
         
     | 
| 
      
 89 
     | 
    
         
            +
                  self.instance_eval &mod.inherited if mod.inherited
         
     | 
| 
       74 
90 
     | 
    
         
             
                end
         
     | 
| 
       75 
91 
     | 
    
         
             
              end
         
     | 
| 
       76 
92 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,9 +1,9 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            class AssertionError <  
     | 
| 
      
 1 
     | 
    
         
            +
            class AssertionError < RuntimeError; end
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            class MustAssertions <  
     | 
| 
      
 3 
     | 
    
         
            +
            class MustAssertions < BasicObject
         
     | 
| 
       4 
4 
     | 
    
         
             
              attr_reader :obj
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
              def initialize obj
         
     | 
| 
      
 6 
     | 
    
         
            +
              def initialize obj    
         
     | 
| 
       7 
7 
     | 
    
         
             
                @obj = obj
         
     | 
| 
       8 
8 
     | 
    
         
             
              end
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
         @@ -24,18 +24,18 @@ class MustAssertions < ExtraBlankSlate 
     | 
|
| 
       24 
24 
     | 
    
         
             
              end
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
26 
     | 
    
         
             
              def defined
         
     | 
| 
       27 
     | 
    
         
            -
                 
     | 
| 
      
 27 
     | 
    
         
            +
                @obj != nil
         
     | 
| 
       28 
28 
     | 
    
         
             
              end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
30 
     | 
    
         
             
              def respond_to method
         
     | 
| 
       31 
31 
     | 
    
         
             
                @obj.respond_to? method
         
     | 
| 
       32 
32 
     | 
    
         
             
              end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
              def a  
     | 
| 
       35 
     | 
    
         
            -
                if  
     | 
| 
       36 
     | 
    
         
            -
                   
     | 
| 
      
 34 
     | 
    
         
            +
              def a *args    
         
     | 
| 
      
 35 
     | 
    
         
            +
                if args.class == ::Array
         
     | 
| 
      
 36 
     | 
    
         
            +
                  args.any?{|k| @obj.is_a? k}
         
     | 
| 
       37 
37 
     | 
    
         
             
                else
         
     | 
| 
       38 
     | 
    
         
            -
                  @obj.is_a?  
     | 
| 
      
 38 
     | 
    
         
            +
                  @obj.is_a? args
         
     | 
| 
       39 
39 
     | 
    
         
             
                end
         
     | 
| 
       40 
40 
     | 
    
         
             
              end
         
     | 
| 
       41 
41 
     | 
    
         
             
              alias_method :an, :a
         
     | 
| 
         @@ -55,7 +55,7 @@ class MustAssertions < ExtraBlankSlate 
     | 
|
| 
       55 
55 
     | 
    
         
             
              def in *args
         
     | 
| 
       56 
56 
     | 
    
         
             
                if args.size == 1 
         
     | 
| 
       57 
57 
     | 
    
         
             
                  obj = args.first
         
     | 
| 
       58 
     | 
    
         
            -
                  if obj.is_a?(Array) or obj.is_a?(Range)
         
     | 
| 
      
 58 
     | 
    
         
            +
                  if obj.is_a?(::Array) or obj.is_a?(::Range)
         
     | 
| 
       59 
59 
     | 
    
         
             
                    obj.include? @obj
         
     | 
| 
       60 
60 
     | 
    
         
             
                  else
         
     | 
| 
       61 
61 
     | 
    
         
             
                    args.include? @obj
         
     | 
| 
         @@ -73,7 +73,7 @@ class MustAssertions < ExtraBlankSlate 
     | 
|
| 
       73 
73 
     | 
    
         
             
                !@obj
         
     | 
| 
       74 
74 
     | 
    
         
             
              end
         
     | 
| 
       75 
75 
     | 
    
         | 
| 
       76 
     | 
    
         
            -
              def empty
         
     | 
| 
      
 76 
     | 
    
         
            +
              def empty    
         
     | 
| 
       77 
77 
     | 
    
         
             
                @obj.empty?
         
     | 
| 
       78 
78 
     | 
    
         
             
              end
         
     | 
| 
       79 
79 
     | 
    
         | 
| 
         @@ -101,11 +101,11 @@ class MustAssertions < ExtraBlankSlate 
     | 
|
| 
       101 
101 
     | 
    
         
             
                @obj <= o
         
     | 
| 
       102 
102 
     | 
    
         
             
              end
         
     | 
| 
       103 
103 
     | 
    
         | 
| 
       104 
     | 
    
         
            -
              def exist  
     | 
| 
       105 
     | 
    
         
            -
                @obj.exist?  
     | 
| 
      
 104 
     | 
    
         
            +
              def exist *args
         
     | 
| 
      
 105 
     | 
    
         
            +
                @obj.exist? *args
         
     | 
| 
       106 
106 
     | 
    
         
             
              end
         
     | 
| 
       107 
107 
     | 
    
         | 
| 
       108 
     | 
    
         
            -
              def be
         
     | 
| 
      
 108 
     | 
    
         
            +
              def be    
         
     | 
| 
       109 
109 
     | 
    
         
             
                @prefix = 'be'
         
     | 
| 
       110 
110 
     | 
    
         
             
                self
         
     | 
| 
       111 
111 
     | 
    
         
             
              end
         
     | 
| 
         @@ -116,25 +116,25 @@ class MustAssertions < ExtraBlankSlate 
     | 
|
| 
       116 
116 
     | 
    
         
             
              end
         
     | 
| 
       117 
117 
     | 
    
         | 
| 
       118 
118 
     | 
    
         
             
              def self.assertions
         
     | 
| 
       119 
     | 
    
         
            -
                special =  
     | 
| 
       120 
     | 
    
         
            -
                 
     | 
| 
      
 119 
     | 
    
         
            +
                special = [:be, :have]
         
     | 
| 
      
 120 
     | 
    
         
            +
                public_instance_methods.select{|m| m !~ /^__/ and !special.include?(m)}    
         
     | 
| 
       121 
121 
     | 
    
         
             
              end
         
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
      
 122 
     | 
    
         
            +
              
         
     | 
| 
       123 
123 
     | 
    
         
             
              protected
         
     | 
| 
       124 
     | 
    
         
            -
                def method_missing m, *args, &b
         
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
                end
         
     | 
| 
      
 124 
     | 
    
         
            +
                # def method_missing m, *args, &b
         
     | 
| 
      
 125 
     | 
    
         
            +
                #   raise ::RuntimeError, "Assertion '#{m}' is unknown!", caller[1..-1]
         
     | 
| 
      
 126 
     | 
    
         
            +
                # end
         
     | 
| 
       127 
127 
     | 
    
         | 
| 
       128 
128 
     | 
    
         
             
                def failed method, negative, *args
         
     | 
| 
       129 
     | 
    
         
            -
                  stack = caller.sfilter('must.rb')
         
     | 
| 
      
 129 
     | 
    
         
            +
                  stack = ::Object.send(:caller).sfilter('must.rb')
         
     | 
| 
       130 
130 
     | 
    
         | 
| 
       131 
131 
     | 
    
         
             
                  unless args.empty?
         
     | 
| 
       132 
     | 
    
         
            -
                     
     | 
| 
      
 132 
     | 
    
         
            +
                    ::Object.send :raise, ::AssertionError, "
         
     | 
| 
       133 
133 
     | 
    
         
             
              ASSERTION FAILED (#{stack.first}):
         
     | 
| 
       134 
     | 
    
         
            -
              #{@obj.inspect} must #{'not ' if negative}#{"#{@prefix} " if @prefix}#{method} #{args. 
     | 
| 
      
 134 
     | 
    
         
            +
              #{@obj.inspect} must #{'not ' if negative}#{"#{@prefix} " if @prefix}#{method} #{args.collect{|a| a.inspect}.join(', ')}
         
     | 
| 
       135 
135 
     | 
    
         
             
                    ", stack
         
     | 
| 
       136 
136 
     | 
    
         
             
                  else
         
     | 
| 
       137 
     | 
    
         
            -
                     
     | 
| 
      
 137 
     | 
    
         
            +
                    ::Object.send :raise, ::AssertionError, "
         
     | 
| 
       138 
138 
     | 
    
         
             
              ASSERTION FAILED (#{stack.first}):
         
     | 
| 
       139 
139 
     | 
    
         
             
              #{@obj.inspect} must #{'not ' if negative}#{"#{@prefix} " if @prefix}#{method}
         
     | 
| 
       140 
140 
     | 
    
         
             
                    ", stack
         
     | 
| 
         @@ -151,11 +151,15 @@ class Must < MustAssertions 
     | 
|
| 
       151 
151 
     | 
    
         
             
                  @obj
         
     | 
| 
       152 
152 
     | 
    
         
             
                end
         
     | 
| 
       153 
153 
     | 
    
         
             
              end
         
     | 
| 
      
 154 
     | 
    
         
            +
              
         
     | 
| 
      
 155 
     | 
    
         
            +
              def inspect
         
     | 
| 
      
 156 
     | 
    
         
            +
                "<#Must>"
         
     | 
| 
      
 157 
     | 
    
         
            +
              end
         
     | 
| 
       154 
158 
     | 
    
         
             
            end
         
     | 
| 
       155 
159 
     | 
    
         | 
| 
       156 
160 
     | 
    
         
             
            class MustNot < MustAssertions
         
     | 
| 
       157 
     | 
    
         
            -
              assertions.each do |m|
         
     | 
| 
       158 
     | 
    
         
            -
                desition = "_#{m}"
         
     | 
| 
      
 161 
     | 
    
         
            +
              assertions.each do |m|    
         
     | 
| 
      
 162 
     | 
    
         
            +
                desition = "_#{m}".to_sym
         
     | 
| 
       159 
163 
     | 
    
         
             
                alias_method desition, m
         
     | 
| 
       160 
164 
     | 
    
         
             
                define_method m do |*args|
         
     | 
| 
       161 
165 
     | 
    
         
             
                  failed m, true, *args if __send__(desition, *args)
         
     | 
| 
         @@ -164,8 +168,7 @@ class MustNot < MustAssertions 
     | 
|
| 
       164 
168 
     | 
    
         
             
              end
         
     | 
| 
       165 
169 
     | 
    
         
             
            end
         
     | 
| 
       166 
170 
     | 
    
         | 
| 
       167 
     | 
    
         
            -
            Object.class_eval do
         
     | 
| 
       168 
     | 
    
         
            -
              
         
     | 
| 
      
 171 
     | 
    
         
            +
            Object.class_eval do  
         
     | 
| 
       169 
172 
     | 
    
         
             
              def must
         
     | 
| 
       170 
173 
     | 
    
         
             
                Must.new(self)
         
     | 
| 
       171 
174 
     | 
    
         
             
              end
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         @@ -1,14 +1,18 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            raise "You shouldn't use OpenObject defined in facets, it's incopatible with this version!" if defined?(OpenObject)
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            class OpenObject < Hash
         
     | 
| 
       4 
     | 
    
         
            -
              
         
     | 
| 
       5 
     | 
    
         
            -
               
     | 
| 
       6 
     | 
    
         
            -
               
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            class OpenObject < Hash    
         
     | 
| 
      
 4 
     | 
    
         
            +
              #
         
     | 
| 
      
 5 
     | 
    
         
            +
              # delete methods
         
     | 
| 
      
 6 
     | 
    
         
            +
              #
         
     | 
| 
      
 7 
     | 
    
         
            +
              PUBLIC_METHODS = %w(
         
     | 
| 
      
 8 
     | 
    
         
            +
                as send each each_pair size is_a? clone dup empty? blank? present? merge merge! stringify_keys stringify_keys! symbolize_keys symbolize_keys! to_query
         
     | 
| 
      
 9 
     | 
    
         
            +
              ).collect{|m| m.to_sym}
         
     | 
| 
      
 10 
     | 
    
         
            +
              PUBLIC_METHODS_RE = /(^__|^object_|^must|^stub)/  
         
     | 
| 
      
 11 
     | 
    
         
            +
              protected(*public_instance_methods.select{|m| !PUBLIC_METHODS.include?(m) and m !~ PUBLIC_METHODS_RE})
         
     | 
| 
      
 12 
     | 
    
         
            +
                
         
     | 
| 
       10 
13 
     | 
    
         
             
              def inspect
         
     | 
| 
       11 
     | 
    
         
            -
                "#<#{self.class}:#{self.object_id} #{super}>"
         
     | 
| 
      
 14 
     | 
    
         
            +
                # "#<#{self.class}:#{self.object_id} #{super}>"
         
     | 
| 
      
 15 
     | 
    
         
            +
                "<#{super}>"
         
     | 
| 
       12 
16 
     | 
    
         
             
              end
         
     | 
| 
       13 
17 
     | 
    
         | 
| 
       14 
18 
     | 
    
         
             
              def to_a; super end
         
     | 
| 
         @@ -30,6 +34,7 @@ class OpenObject < Hash 
     | 
|
| 
       30 
34 
     | 
    
         
             
                  r
         
     | 
| 
       31 
35 
     | 
    
         
             
                end 
         
     | 
| 
       32 
36 
     | 
    
         
             
              end
         
     | 
| 
      
 37 
     | 
    
         
            +
              alias_method :to_oo, :to_openobject
         
     | 
| 
       33 
38 
     | 
    
         | 
| 
       34 
39 
     | 
    
         
             
              def each █ super(&block) end
         
     | 
| 
       35 
40 
     | 
    
         | 
| 
         @@ -47,12 +52,12 @@ class OpenObject < Hash 
     | 
|
| 
       47 
52 
     | 
    
         
             
              end
         
     | 
| 
       48 
53 
     | 
    
         | 
| 
       49 
54 
     | 
    
         
             
              def update other
         
     | 
| 
       50 
     | 
    
         
            -
                other.to_hash.each{|k,v| self[k. 
     | 
| 
      
 55 
     | 
    
         
            +
                other.to_hash.each{|k,v| self[k.to_sym] = v}
         
     | 
| 
       51 
56 
     | 
    
         
             
                self
         
     | 
| 
       52 
57 
     | 
    
         
             
              end
         
     | 
| 
       53 
58 
     | 
    
         | 
| 
       54 
59 
     | 
    
         
             
              def delete key
         
     | 
| 
       55 
     | 
    
         
            -
                super key. 
     | 
| 
      
 60 
     | 
    
         
            +
                super key.to_sym
         
     | 
| 
       56 
61 
     | 
    
         
             
              end
         
     | 
| 
       57 
62 
     | 
    
         | 
| 
       58 
63 
     | 
    
         
             
              def == other
         
     | 
| 
         @@ -64,15 +69,15 @@ class OpenObject < Hash 
     | 
|
| 
       64 
69 
     | 
    
         
             
              end
         
     | 
| 
       65 
70 
     | 
    
         | 
| 
       66 
71 
     | 
    
         
             
              def []= k, v
         
     | 
| 
       67 
     | 
    
         
            -
                super k. 
     | 
| 
      
 72 
     | 
    
         
            +
                super k.to_sym, v
         
     | 
| 
       68 
73 
     | 
    
         
             
              end
         
     | 
| 
       69 
74 
     | 
    
         | 
| 
       70 
75 
     | 
    
         
             
              def [] k
         
     | 
| 
       71 
     | 
    
         
            -
                super k. 
     | 
| 
      
 76 
     | 
    
         
            +
                super k.to_sym
         
     | 
| 
       72 
77 
     | 
    
         
             
              end
         
     | 
| 
       73 
78 
     | 
    
         | 
| 
       74 
79 
     | 
    
         
             
              def include? k
         
     | 
| 
       75 
     | 
    
         
            -
                super k. 
     | 
| 
      
 80 
     | 
    
         
            +
                super k.to_sym
         
     | 
| 
       76 
81 
     | 
    
         
             
              end
         
     | 
| 
       77 
82 
     | 
    
         | 
| 
       78 
83 
     | 
    
         
             
              def to_hash deep = false
         
     | 
| 
         @@ -105,10 +110,8 @@ class OpenObject < Hash 
     | 
|
| 
       105 
110 
     | 
    
         
             
              end
         
     | 
| 
       106 
111 
     | 
    
         | 
| 
       107 
112 
     | 
    
         
             
              protected
         
     | 
| 
       108 
     | 
    
         
            -
                def method_missing m, arg = nil, &block
         
     | 
| 
       109 
     | 
    
         
            -
                  m = m.to_s
         
     | 
| 
      
 113 
     | 
    
         
            +
                def method_missing m, arg = nil, &block      
         
     | 
| 
       110 
114 
     | 
    
         
             
                  type = m[-1,1]
         
     | 
| 
       111 
     | 
    
         
            -
                  # key = m.to_s.sub(/[=?!]$/,'').to_s
         
     | 
| 
       112 
115 
     | 
    
         
             
                  if type == '='
         
     | 
| 
       113 
116 
     | 
    
         
             
                    self[m[0..-2]] = arg
         
     | 
| 
       114 
117 
     | 
    
         
             
                  elsif type == '!'        
         
     | 
| 
         @@ -129,6 +132,7 @@ class NilClass 
     | 
|
| 
       129 
132 
     | 
    
         
             
              def to_openobject deep = false
         
     | 
| 
       130 
133 
     | 
    
         
             
                OpenObject.new
         
     | 
| 
       131 
134 
     | 
    
         
             
              end
         
     | 
| 
      
 135 
     | 
    
         
            +
              alias_method :to_oo, :to_openobject
         
     | 
| 
       132 
136 
     | 
    
         
             
            end
         
     | 
| 
       133 
137 
     | 
    
         | 
| 
       134 
138 
     | 
    
         
             
            class Hash
         
     | 
| 
         @@ -147,6 +151,7 @@ class Hash 
     | 
|
| 
       147 
151 
     | 
    
         
             
                  r
         
     | 
| 
       148 
152 
     | 
    
         
             
                end
         
     | 
| 
       149 
153 
     | 
    
         
             
              end
         
     | 
| 
      
 154 
     | 
    
         
            +
              alias_method :to_oo, :to_openobject
         
     | 
| 
       150 
155 
     | 
    
         | 
| 
       151 
156 
     | 
    
         
             
              alias_method :oo_eql, :==
         
     | 
| 
       152 
157 
     | 
    
         
             
              def == other
         
     | 
| 
         @@ -7,6 +7,10 @@ String.class_eval do 
     | 
|
| 
       7 
7 
     | 
    
         
             
                File.expand_path(File.dirname(self) + "/..")
         
     | 
| 
       8 
8 
     | 
    
         
             
              end
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
      
 10 
     | 
    
         
            +
              def expand_path
         
     | 
| 
      
 11 
     | 
    
         
            +
                File.expand_path(self)
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
              
         
     | 
| 
       10 
14 
     | 
    
         
             
              def to_reader
         
     | 
| 
       11 
15 
     | 
    
         
             
                self.to_sym
         
     | 
| 
       12 
16 
     | 
    
         
             
              end
         
     | 
| 
         @@ -19,6 +23,10 @@ String.class_eval do 
     | 
|
| 
       19 
23 
     | 
    
         
             
                "@#{self}"
         
     | 
| 
       20 
24 
     | 
    
         
             
              end
         
     | 
| 
       21 
25 
     | 
    
         | 
| 
      
 26 
     | 
    
         
            +
              def to_a
         
     | 
| 
      
 27 
     | 
    
         
            +
                [self]
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
              
         
     | 
| 
       22 
30 
     | 
    
         
             
              def interpolate binding
         
     | 
| 
       23 
31 
     | 
    
         
             
                binding.must_be.a Binding
         
     | 
| 
       24 
32 
     | 
    
         
             
                return gsub(/\#\{.+?\}/) do |term|
         
     | 
| 
         @@ -41,4 +49,23 @@ String.class_eval do 
     | 
|
| 
       41 
49 
     | 
    
         
             
                word.downcase!
         
     | 
| 
       42 
50 
     | 
    
         
             
                word
         
     | 
| 
       43 
51 
     | 
    
         
             
              end
         
     | 
| 
      
 52 
     | 
    
         
            +
              
         
     | 
| 
      
 53 
     | 
    
         
            +
              def camelize first_letter_in_uppercase = true
         
     | 
| 
      
 54 
     | 
    
         
            +
                if first_letter_in_uppercase
         
     | 
| 
      
 55 
     | 
    
         
            +
                  gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
         
     | 
| 
      
 56 
     | 
    
         
            +
                else
         
     | 
| 
      
 57 
     | 
    
         
            +
                  self[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..-1]
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
              
         
     | 
| 
      
 61 
     | 
    
         
            +
              def constantize
         
     | 
| 
      
 62 
     | 
    
         
            +
                names = self.split('::')
         
     | 
| 
      
 63 
     | 
    
         
            +
                names.shift if names.empty? || names.first.empty?
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                constant = Object
         
     | 
| 
      
 66 
     | 
    
         
            +
                names.each do |name|
         
     | 
| 
      
 67 
     | 
    
         
            +
                  constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
         
     | 
| 
      
 68 
     | 
    
         
            +
                end
         
     | 
| 
      
 69 
     | 
    
         
            +
                constant
         
     | 
| 
      
 70 
     | 
    
         
            +
              end
         
     | 
| 
       44 
71 
     | 
    
         
             
            end
         
     | 
| 
         
            File without changes
         
     |