Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/carat/1st.rb,
lib/carat/snapshot.rb,
lib/carat-dev/vars/vars.rb,
lib/carat-dev/detach/detach.rb,
lib/carat-dev/interface_work/must.rb,
lib/carat-dev/interface_work/type.rb,
lib/carat-dev/blankslate/blankslate.rb,
lib/carat-dev/conditional/conditionals.rb,
lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb
Overview
Class Method Summary collapse
- .blank_slate_method_added ⇒ Object
- .conversion(to_type) ⇒ Object
- .define_conversion(to_type, &block) ⇒ Object
- .method_added(name) ⇒ Object
Instance Method Summary collapse
- #adopt(mod) ⇒ Object
- #apply_snapshot(snap) ⇒ Object
-
#detach(cfg = {}) ⇒ Object
waiting for the real method operation to finish.
- #false? ⇒ Boolean
- #import(mod) ⇒ Object
- #method(s) ⇒ Object
- #method_pre1st ⇒ Object
- #must(*args) ⇒ Object
- #must_be(obj) ⇒ Object
- #must_exist ⇒ Object
- #must_have(*args) ⇒ Object (also: #needed)
- #take_snapshot ⇒ Object
- #to(to_type, *args) ⇒ Object
- #true? ⇒ Boolean
Class Method Details
.blank_slate_method_added ⇒ Object
44 |
# File 'lib/carat-dev/blankslate/blankslate.rb', line 44 alias_method :blank_slate_method_added, :method_added |
.conversion(to_type) ⇒ Object
223 224 225 |
# File 'lib/carat-dev/interface_work/type.rb', line 223 def self.conversion(to_type) @conversion_registry[to_type] end |
.define_conversion(to_type, &block) ⇒ Object
226 227 228 |
# File 'lib/carat-dev/interface_work/type.rb', line 226 def self.define_conversion(to_type, &block) @conversion_registry[to_type] end |
Instance Method Details
#adopt(mod) ⇒ Object
411 412 413 414 |
# File 'lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb', line 411 def adopt(mod) (class << self; self; end).adopt_module(mod) self end |
#apply_snapshot(snap) ⇒ Object
55 56 57 58 59 |
# File 'lib/carat/snapshot.rb', line 55 def apply_snapshot(snap) instance_variables.each do |iv| instance_variable_set(iv, snap[iv]) end end |
#detach(cfg = {}) ⇒ Object
waiting for the real method operation to finish.
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/carat-dev/detach/detach.rb', line 273 def detach(cfg={}) cfg = { :ps => :append, :die => :parent, :name => :parent, :id => :object, :path => '/tmp/drb_detach.#{pid}', :allref => true, :background => true }.merge(cfg) if cfg[:name] == :parent name = $0 else name = cfg[:name].to_s end if cfg[:id] == :object id = "#<#{self.class}:0x#{self.object_id.to_s(16)}>" else id = cfg[:id] end pid = fork { # A nice little trick case cfg[:ps] when :append $0 = name + " - #{id}" when :replace $0 = id when :none break end if cfg[:ps].kind_of? String $0 = cfg[:ps] end trap("INT") { exit } pid = Process.pid obj = nil if cfg[:background] == true obj = Dispatch::BackgroundDispatch.new(self,true) else obj = self end DRb.start_service("drbunix://"+eval(%!"#{cfg[:path]}"!),obj) DRb.thread.join exit } # Mom always said I should clean up after myself if cfg[:die] == :parent at_exit { Process.kill("INT", pid) } end sleep 0.3 DRb.start_service remote = DRbObject.new(nil,"drbunix://"+eval(%!"#{cfg[:path]}"!)) if cfg[:allref] == true remote.instance_eval "alias :real_method_missing :method_missing" def remote.method_missing(msg_id, *a, &b) a.each do |i| allow = true [Symbol, String, Fixnum, Bignum, Array, Regexp].each do |t| if i.kind_of? t allow = false break end end next if not allow def i._dump(d) raise TypeError, 'can\'t dump' end end return real_method_missing(msg_id, *a) end end return remote end |
#false? ⇒ Boolean
3 |
# File 'lib/carat-dev/conditional/conditionals.rb', line 3 def false? ; nil ; end |
#import(mod) ⇒ Object
405 406 407 408 409 |
# File 'lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb', line 405 def import(mod) (class << self; self; end).import_module(mod) do yield self end end |
#method(s) ⇒ Object
48 49 50 |
# File 'lib/carat/1st.rb', line 48 def method(s) ( @__methods__ ||= {} )[s] ||= method_pre1st(s) end |
#method_pre1st ⇒ Object
47 |
# File 'lib/carat/1st.rb', line 47 alias_method :method_pre1st, :method |
#must(*args) ⇒ Object
14 15 16 17 |
# File 'lib/carat-dev/interface_work/must.rb', line 14 def must( *args ) args.each {|c| return self if c === self } raise TypeError, "wrong arg type '#{self.class}' for required #{args.join('/')}" end |
#must_be(obj) ⇒ Object
28 29 30 31 |
# File 'lib/carat-dev/interface_work/must.rb', line 28 def must_be( obj ) self == obj or raise ArgumentError, "expected #{eq.inspect} but is #{inspect}" self end |
#must_exist ⇒ Object
33 34 35 |
# File 'lib/carat-dev/interface_work/must.rb', line 33 def must_exist nil? and raise ArgumentError, 'receiver is wrongly nil' end |
#must_have(*args) ⇒ Object Also known as: needed
19 20 21 22 23 24 25 |
# File 'lib/carat-dev/interface_work/must.rb', line 19 def must_have( *args ) args.each do |m| self.respond_to? m or raise ArgumentError, "receiver #{inspect} does not have '#{m}'" end self end |
#take_snapshot ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/carat/snapshot.rb', line 47 def take_snapshot snap = Hash.new instance_variables.each do |iv| snap[iv] = instance_variable_get(iv) end snap end |
#to(to_type, *args) ⇒ Object
229 230 231 |
# File 'lib/carat-dev/interface_work/type.rb', line 229 def to(to_type, *args) @conversion_registry[to_type].call(*args) end |
#true? ⇒ Boolean
4 |
# File 'lib/carat-dev/conditional/conditionals.rb', line 4 def true? ; yield ; end |