Module: Minidbc::ClassMethods
- Defined in:
- lib/minidbc.rb
Instance Method Summary collapse
- #create_method_call_wrap(method_name, new_method_name, check_pre, check_post, pre_check_invariants, post_check_invariants) ⇒ Object
- #inherited(subclass) ⇒ Object
- #invariant(&blk) ⇒ Object
- #invariants ⇒ Object
- #method_added(method_name) ⇒ Object
- #minidbc_init ⇒ Object
- #post(&blk) ⇒ Object
- #postconds(method_name) ⇒ Object
- #pre(&blk) ⇒ Object
- #preconds(method_name) ⇒ Object
Instance Method Details
#create_method_call_wrap(method_name, new_method_name, check_pre, check_post, pre_check_invariants, post_check_invariants) ⇒ Object
127 128 129 130 131 132 133 134 135 |
# File 'lib/minidbc.rb', line 127 def create_method_call_wrap( method_name, new_method_name, check_pre, check_post, pre_check_invariants, post_check_invariants ) define_method method_name do |*arg| # puts self.class # puts method_name # puts new_method_name # byebug minidbc_call_wrap( method_name, new_method_name, check_pre, check_post, pre_check_invariants, post_check_invariants, *arg ) end end |
#inherited(subclass) ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/minidbc.rb', line 156 def inherited(subclass) subclass.minidbc_init if subclass.superclass == self puts subclass subclass.extend(SubclassMethods) end end |
#invariant(&blk) ⇒ Object
164 165 166 |
# File 'lib/minidbc.rb', line 164 def invariant(&blk) @invariants << Cond.new( blk, caller[0] ) end |
#invariants ⇒ Object
83 84 85 |
# File 'lib/minidbc.rb', line 83 def invariants @invariants end |
#method_added(method_name) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/minidbc.rb', line 87 def method_added(method_name) # byebug if method_name == :initialize if /\w+_without_dbc/ =~ method_name.to_s return elsif /(pre_|post_|check_minidbc_invariant)\w+/ =~ method_name.to_s return else new_method_name = :"#{method_name}_#{self.to_s.gsub(/::/,"_")}_without_dbc" if instance_methods(false).include?(new_method_name) return end if method_name == :initialize && @hook_initialize return end @minidbc_pres[method_name] = @pres @minidbc_posts[method_name] = @posts @pres = [] @posts = [] #TODO need to support client code call alias_method alias_method new_method_name, method_name if method_name == :initialize @hook_initialize = true create_method_call_wrap( method_name, new_method_name, true, true, false, true ) elsif private_methods.include? method_name create_method_call_wrap( method_name, new_method_name, true, true, false, false ) else create_method_call_wrap( method_name, new_method_name, true, true, true, true ) end end end |
#minidbc_init ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/minidbc.rb', line 137 def minidbc_init @pres = [] @posts = [] @minidbc_pres = {} @minidbc_posts = {} @invariants = [] @hook_initialize = false #TODO need to check invariants on initialize # class << self # alias_method :minidbc_new, :new # def new(*arg) # ret = __new__(*arg) # ret.minidbc_check_condition( # end # end end |
#post(&blk) ⇒ Object
172 173 174 |
# File 'lib/minidbc.rb', line 172 def post(&blk) @posts << Cond.new( blk, caller[0] ) end |
#postconds(method_name) ⇒ Object
79 80 81 |
# File 'lib/minidbc.rb', line 79 def postconds(method_name) @minidbc_posts[method_name] end |
#pre(&blk) ⇒ Object
168 169 170 |
# File 'lib/minidbc.rb', line 168 def pre(&blk) @pres << Cond.new( blk, caller[0] ) end |
#preconds(method_name) ⇒ Object
75 76 77 |
# File 'lib/minidbc.rb', line 75 def preconds(method_name) @minidbc_pres[method_name] end |