Module: Outil::Inferace

Includes:
RubyDecorators
Defined in:
lib/outil.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.decorateObject



63
64
65
66
# File 'lib/outil.rb', line 63

def self.decorate
    RubyDecorators::Stack.all << self
    Workspace.sync
end

.registered_decoratorsObject



104
105
106
# File 'lib/outil.rb', line 104

def self.registered_decorators
    @registered_decorators ||= {}
end

Instance Method Details

#decoratorsObject



83
84
85
# File 'lib/outil.rb', line 83

def decorators
    @decorators ||= {}
end

#nameObject



79
80
81
# File 'lib/outil.rb', line 79

def name
    @name ||= self.class.name.to_s
end

#named(name) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/outil.rb', line 68

def named(name)
    @name = name.to_s
    class_eval <<-RUBY_EVAL
    def self.#{@name}(dcr)
        if decorators[dcr]
            self.decorate(decorators[dcr])
        end
    end
    RUBY_EVAL
end

#registered_methodsObject



100
101
102
# File 'lib/outil.rb', line 100

def registered_methods
    @registered_methods ||= {}
end

#use(*decs) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/outil.rb', line 87

def use *decs
    append = Proc.new do |dec|
        fmt = dec.name.split('::').last.
        gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
        gsub(/([a-z\d])([A-Z])/,'\1_\2').
        tr("-", "_").
        downcase.
        to_sym
        self.decorators[fmt] = dec
    end
    decs.each &append
end