Class: SdlImplModule

Inherits:
Object
  • Object
show all
Defined in:
lib/tdl/sdlimplement/sdl_impl_module.rb

Constant Summary collapse

@@_impl_ms_ =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_name, hash) ⇒ SdlImplModule

Returns a new instance of SdlImplModule.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 5

def initialize(key_name,hash)
    # @class_name = class_name
    @key_name = key_name
    parse_name(key_name)
    @info   = hash['info']
    @path   = hash['path']
    @pins_map = hash['pins_map'].to_sym if hash['pins_map']
    @req_modules = hash['require'] || {}
    @mutual_moduls = hash['matual'] || {}

    %w{ info path pins_map require matual}.each {|e| hash.delete(e) }
    gen_other_attr(hash)

    @@_impl_ms_[key_name] = self
    @real_require = {}
end

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



4
5
6
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 4

def class_name
  @class_name
end

#infoObject (readonly)

Returns the value of attribute info.



4
5
6
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 4

def info
  @info
end

#key_nameObject (readonly)

Returns the value of attribute key_name.



4
5
6
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 4

def key_name
  @key_name
end

#nicknameObject (readonly)

Returns the value of attribute nickname.



4
5
6
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 4

def nickname
  @nickname
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 4

def path
  @path
end

#pins_mapObject (readonly)

Returns the value of attribute pins_map.



4
5
6
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 4

def pins_map
  @pins_map
end

#real_requireObject (readonly)

Returns the value of attribute real_require.



4
5
6
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 4

def real_require
  @real_require
end

Class Method Details

.implement(modules, tbs) ⇒ Object

——— implement top ——————



171
172
173
174
175
176
177
178
179
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 171

def self.implement(modules,tbs)
    ma  = []
    modules.each do |m|
        ma << self.modules_hash(m)
        ma << m.dependent.flatten
    end
    ma = ma.uniq

end

.inspect_dependent(level_len, dep_array) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 153

def self.inspect_dependent(level_len,dep_array)
    str = ""
    dep_array.each do |e_array|
        str += " "*level_len + (e_array[0].key_name).to_s + ":\n"

        str += " "*level_len + (e_array[0].key_name).to_s + ":\n"
        if e_array[1].any?
            str += self.inspect_dependent(level_len+4,e_array[1])
        else
            str.chop!
            str += " ~\n"
        end
    end
    str
end

.inspect_dependent_verb(level_len, dep_array) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 139

def self.inspect_dependent_verb(level_len,dep_array)
    str = ""
    dep_array.each do |e_array|
        str += " "*level_len + (e_array[0].key_name).to_s + " -> \n"
        if e_array[1].any?
            str += self.inspect_dependent_verb(level_len+((e_array[0].key_name).to_s.length)+4,e_array[1])
        else
            str.chop!
            str += "[]\n"
        end
    end
    str
end

.modules_hash(module_origin_str) ⇒ Object



128
129
130
131
132
133
134
135
136
137
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 128

def self.modules_hash(module_origin_str)
    if @@_impl_ms_.keys.include? module_origin_str
        @@_impl_ms_[module_origin_str]
    elsif @@_impl_ms_.keys.map { |e| e.sub(/\(\w*\)/,"" ) }.include?(module_origin_str) || @@_impl_ms_.keys.map { |e| e.sub(/\(\w*\)/,"" ) }.include?(module_origin_str.sub(/\(\s*\)/,""))
        @@_impl_ms_[ @@_impl_ms_.keys.select { |e|  e.include? module_origin_str }[0] ]
    else
        # puts module_origin_str
        return nil
    end
end

Instance Method Details

#common_argvsObject



22
23
24
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 22

def common_argvs
    [:nickname,:pins_map]
end

#dependent(sure: false, pool: []) ⇒ Object

def self.impl_ms_keys_cont(key)

if @@_impl_ms_.keys.include? key
    return key
elsif @@_impl_ms_.keys.map { |e| e.sub(/\(\w*\)/,"" ) }.include? key
    return @@_impl_ms_.keys.select { |e|  e.include? key }[0]
else
    return false
end

end



78
79
80
81
82
83
84
85
86
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
126
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 78

def dependent(sure:false,pool:[])
    dep_array = []

    @req_modules.each do |k,v|
        unless v.is_a? Array
            ov = SdlImplModule.modules_hash(v)
            if ov
                # dep_array << ov
                dep_array << [ov,ov.dependent(sure:sure,pool:pool)]
            else
                raise TdlError.new("Module[#{@class_name}] depend on [#{v}] but [#{v}] dont exist !!!!")
            end
            @real_require[k]    = ov unless @real_require.include? ov
        else
            # dep_array << v
            next if sure

            if pool.empty?
                mutual_hash = {}
                v.each_index do |index|
                    mutual_hash["k##{index}"] = v[index]
                end
                ov = SdlImplModule.new("#mutual#",{'require' => mutual_hash })
                dep_array << [ov,ov.dependent(sure:sure,pool:pool)]

            else
                in_pool = false
                v.each do |vv|
                    ov = SdlImplModule.modules_hash(vv)
                    if pool.include? ov
                        dep_array << [ov,ov.dependent(sure:sure,pool:pool)]
                        in_pool = true
                        break
                    end
                end

                unless in_pool
                    ov = SdlImplModule.modules_hash(v[0])
                    dep_array << [ov,ov.dependent(sure:sure,pool:pool)]
                end

                @real_require[k]    = ov    unless @real_require.include? ov
            end
        end
    end
    # raise TdlError.new("SdlImplModule[#{key_name}] cant dependent itself !!!") if dep_array.flatten.include? self

    return dep_array
end

#gen_other_attr(hash) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 26

def gen_other_attr(hash)
    obj = Object.new
    define_singleton_method("other") do
        obj
    end

    keys = hash.keys

    obj.define_singleton_method("keys") do
        keys
    end

    hash.each do |k,v|
        obj.define_singleton_method(k) do
            v
        end
    end
end

#parse_name(key_name) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 45

def parse_name(key_name)
    rep0 = /(?<class>\w+)/
    rep1 = /(?<class>\w+)\(\s*\)/
    rep2 = /(?<class>\w+)\((?<nickname>\w+)\)/

    if rep2.match key_name
        @class_name = $~[:class]
        @nickname   = $~[:nickname]
    elsif rep1.match key_name
        @class_name = $~[:class]
        @nickname   = nil
    elsif rep0.match key_name
        @class_name = $~[:class]
        @nickname   = nil
    else
        raise TdlError.new("SdlImplModule KEY_NAME PARSE ERROR [#{key_name.to_s}]")
    end
end