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
435
436
437
438
439
440
441
442
443
444
445
446
|
# File 'lib/deplate/common.rb', line 435
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
412
413
414
415
|
# File 'lib/deplate/common.rb', line 412
def class_attributes
class_attributes_ensure
@class_attributes
end
|
.class_attributes=(value) ⇒ Object
423
424
425
426
|
# File 'lib/deplate/common.rb', line 423
def class_attributes=(value)
class_attributes_ensure
@class_attributes = value
end
|
.class_attributes_ensure ⇒ Object
429
430
431
432
|
# File 'lib/deplate/common.rb', line 429
def class_attributes_ensure
@class_attributes ||= {}
@class_meta_attributes ||= {}
end
|
protected :class_attributes
418
419
420
421
|
# File 'lib/deplate/common.rb', line 418
def class_meta_attributes
class_attributes_ensure
@class_meta_attributes
end
|
.inherited(subclass) ⇒ Object
448
449
450
451
452
453
|
# File 'lib/deplate/common.rb', line 448
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
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
485
486
487
488
489
|
# File 'lib/deplate/common.rb', line 455
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
491
492
493
494
|
# File 'lib/deplate/common.rb', line 491
def respond_to?(symbol, *args)
class_attributes_ensure
super or @class_attributes.keys.include?(symbol)
end
|