Class: Deplate::CommonObject
- Inherits:
-
Object
- Object
- Deplate::CommonObject
show all
- Defined in:
- lib/deplate/common.rb
Class Method Summary
collapse
Class Method Details
.class_attribute(name, default = nil, args = nil) ⇒ Object
430
431
432
433
434
435
436
437
438
439
440
441
|
# File 'lib/deplate/common.rb', line 430
def class_attribute(name, default=nil, args=nil)
class_attributes_ensure
@class_attributes[name] = default
if args
@class_meta_attributes ||= {}
if @class_meta_attributes[name]
@class_meta_attributes[name].merge!(args)
else
@class_meta_attributes[name] = args
end
end
end
|
.class_attributes ⇒ Object
407
408
409
410
|
# File 'lib/deplate/common.rb', line 407
def class_attributes
class_attributes_ensure
@class_attributes
end
|
.class_attributes=(value) ⇒ Object
418
419
420
421
|
# File 'lib/deplate/common.rb', line 418
def class_attributes=(value)
class_attributes_ensure
@class_attributes = value
end
|
.class_attributes_ensure ⇒ Object
424
425
426
427
|
# File 'lib/deplate/common.rb', line 424
def class_attributes_ensure
@class_attributes ||= {}
@class_meta_attributes ||= {}
end
|
protected :class_attributes
413
414
415
416
|
# File 'lib/deplate/common.rb', line 413
def class_meta_attributes
class_attributes_ensure
@class_meta_attributes
end
|
.inherited(subclass) ⇒ Object
443
444
445
446
447
448
|
# File 'lib/deplate/common.rb', line 443
def inherited(subclass)
subclass.class_attributes.merge!(@class_attributes.dup) do |key, ov, nv|
end
subclass.class_meta_attributes.merge!(@class_meta_attributes.dup) do |key, ov, nv|
end
end
|
.method_missing(method, *args) ⇒ Object
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
# File 'lib/deplate/common.rb', line 450
def method_missing(method, *args)
class_attributes_ensure
method_s = method.to_s
if method_s =~ /=$/
method_s = method_s[0..-2]
method_y = method_s.intern
setter = true
else
method_y = method
setter = false
end
if @class_attributes.keys.include?(method_y)
pre = "hook_pre_#{method}"
if respond_to?(pre)
send(pre, *args)
end
if setter
if args.size > 1
raise "Wrong number of arguments: #{method} #{args}"
end
rv = @class_attributes[method_y] = args[0]
else
rv = @class_attributes[method_y]
end
post = "hook_post_#{method}"
if respond_to?(post)
send(post, *args)
end
return rv
else
super
end
end
|
.respond_to?(symbol, *args) ⇒ Boolean
486
487
488
489
|
# File 'lib/deplate/common.rb', line 486
def respond_to?(symbol, *args)
class_attributes_ensure
super or @class_attributes.keys.include?(symbol)
end
|