Module: ItegrationAttr

Included in:
ItegrationVerb
Defined in:
lib/tdl/exlib/itegration_verb.rb

Instance Method Summary collapse

Instance Method Details



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/tdl/exlib/itegration_verb.rb', line 180

def compact_link_itgt(*names)
    link_itgt(*names)
    # container_hash = get_itgt_var('itegration_compact_link_hash',{})
    # ## 为每个link生成一个保存attr的list
    # names.each do |name|
    #     unless container_hash[name.to_s]
    #         container_hash[name.to_s] = []
    #     end
    # end
    # set_itgt_var('itegration_compact_link_hash',container_hash)
    ## 存入 list
    container = get_itgt_var('itegration_compact_link_collect',[])
    container = container | names.map { |e| e.to_s }
    set_itgt_var('itegration_compact_link_collect',container)
    #
    # ## 生成2级类方法
    # names.each do |name|
    #
    #     define_singleton_method("#{name}_has_attr") do |*argvs|
    #         # puts argvs
    #         # return 90
    #         # ItegrationVerb[name]
    #         ## 把 attr 保存到 list
    #         container_hash = get_itgt_var('itegration_compact_link_hash',{})
    #         container_hash[name.to_s] = container_hash[name.to_s] | argvs.map { |e| e.to_s }
    #         set_itgt_var('itegration_compact_link_hash',container_hash)
    #     end
    #
    #     define_singleton_method("#{name}_has_flag") do |*argvs|
    #         "itgt 标识"
    #         container_hash = get_itgt_var('itegration_compact_flag_hash',{})
    #         container_hash[name.to_s] ||= []
    #         container_hash[name.to_s] = container_hash[name.to_s] | argvs.map { |e| e.to_s }
    #         set_itgt_var('itegration_compact_flag_hash',container_hash)
    #     end
    #
    # end
end

#get_itgt_var(name, default = []) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/tdl/exlib/itegration_verb.rb', line 3

def get_itgt_var(name,default=[])
    unless instance_variable_get("@_#{name}_")
        instance_variable_set("@_#{name}_",default)
        container = instance_variable_get("@_#{name}_")
    else
        container = instance_variable_get("@_#{name}_")
    end

    return container
end

#has_attr(*names) ⇒ Object



123
124
125
# File 'lib/tdl/exlib/itegration_verb.rb', line 123

def has_attr(*names)
    link_explort(*names)
end

#has_flag(*names) ⇒ Object



127
128
129
130
131
132
# File 'lib/tdl/exlib/itegration_verb.rb', line 127

def has_flag(*names)
    ## 标识控制
    container = get_itgt_var('itegration_flag_collect',[])
    container = container | names.map{ |e| e.to_s }
    set_itgt_var("itegration_flag_collect",container)
end

#itegration_explortObject



28
29
30
# File 'lib/tdl/exlib/itegration_verb.rb', line 28

def itegration_explort
    instance_variable_get("@_itegration_explort_collect_")
end

#itegration_hashObject



20
21
22
# File 'lib/tdl/exlib/itegration_verb.rb', line 20

def itegration_hash
    instance_variable_get("@_itegration_link_hash_")
end


24
25
26
# File 'lib/tdl/exlib/itegration_verb.rb', line 24

def itegration_link
    instance_variable_get("@_itegration_link_collect_")
end


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
# File 'lib/tdl/exlib/itegration_verb.rb', line 32

def link_explort(*names)
    ## explort_active_hash
    explort_active_hash = get_itgt_var('explort_active_hash',{})
    ## explort_silence_hash
    explort_silence_hash = get_itgt_var('explort_silence_hash',{})
    ## 存入 list
    # unless instance_variable_get("@_itegration_explort_collect_")
    #     instance_variable_set("@_itegration_explort_collect_",[])
    #     container = instance_variable_get("@_itegration_explort_collect_")
    # else
    #     container = instance_variable_get("@_itegration_explort_collect_")
    # end
    container = get_itgt_var('itegration_explort_collect',[])

    container = container | names.map{ |e| e.to_s }
    instance_variable_set("@_itegration_explort_collect_",container)

    ## 定义引用输出是发生的情况
    names.each do |name|
        define_singleton_method("active_#{name}") do |names_pool_signal=nil,&block|
            unless names_pool_signal
                explort_active_hash[name.to_s] = block
            else
                explort_active_hash[name.to_s] = names_pool_signal.to_s
            end
        end

        define_singleton_method("silence_#{name}") do |&block|
            explort_silence_hash[name.to_s] = block
        end
    end

    ## 生成实例方法
    self.class_exec do
        names.each do |name|
            define_method("active_#{name}_proc_run") do
                itgt_inst = self
                inst_explort_active_hash = get_itgt_var('explort_active_hash'){ explort_active_hash.clone }
                inst_explort_run_hash    = get_itgt_var('explort_active_run_record',{})
                inst_explort_silence_hash = get_itgt_var('explort_silence_hash'){ explort_silence_hash.clone }

                inst_explort_silence_hash.delete(name.to_s)
                ## 如果运行过则,从记录中加载
                if inst_explort_run_hash[name.to_s]
                    return inst_explort_run_hash[name.to_s]
                end

                ## 没有要激活的proc 则直接调用
                unless inst_explort_active_hash[name.to_s]
                    return itgt_inst.send(name.to_s)
                end

                itgt_inst.set_itgt_var('explort_silence_hash',inst_explort_silence_hash)

                if inst_explort_active_hash[name.to_s].is_a? String
                    brel = inst_explort_active_hash[name.to_s].snoop(itgt_inst,itgt_inst.top_module)
                elsif inst_explort_active_hash[name.to_s]
                    # $_implicit_curr_itgt_ = itgt_inst
                    ItegrationVerb.curr_itgt_push itgt_inst
                    brel = itgt_inst.top_module.instance_exec(itgt_inst,&inst_explort_active_hash[name.to_s])
                    ItegrationVerb.curr_itgt_pop
                end

                ## 运行一次后删掉
                inst_explort_active_hash.delete(name.to_s)
                # 记录
                inst_explort_run_hash[name.to_s] = brel

                itgt_inst.set_itgt_var('explort_active_run_record',inst_explort_run_hash)

                itgt_inst.set_itgt_var('explort_active_hash',inst_explort_active_hash)

                brel

            end

        end


        define_method('silence_procs_run') do
            inst_explort_silence_hash = get_itgt_var('explort_silence_hash',explort_silence_hash.clone)
            # $_implicit_curr_itgt_ = self
            ItegrationVerb.curr_itgt_push self
            inst_explort_silence_hash.each_value do |v|
                self.top_module.instance_exec(self,&v) if v
            end
            ItegrationVerb.curr_itgt_pop
        end
    end
end


134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/tdl/exlib/itegration_verb.rb', line 134

def link_itgt(*names)
    container_hash = get_itgt_var('itegration_link_hash',{})
    ## 为每个link生成一个保存attr的list
    names.each do |name|
        unless container_hash[name.to_s]
            container_hash[name.to_s] = []
        end
    end
    set_itgt_var('itegration_link_hash',container_hash)
    ## 存入 list
    container = get_itgt_var('itegration_link_collect',[])
    container = container | names.map { |e| e.to_s }
    set_itgt_var('itegration_link_collect',container)
    ## 生成实例方法
    # self.class_exec do
    #     names.each do |name|
    #         define_method(name) do
    #             ItegrationVerb[name]
    #         end
    #     end
    # end

    ## 生成2级类方法
    names.each do |name|

        define_singleton_method("#{name}_has_attr") do |*argvs|
            # puts argvs
            # return 90
            # ItegrationVerb[name]
            ## 把 attr 保存到 list
            container_hash = get_itgt_var('itegration_link_hash',{})
            container_hash[name.to_s] = container_hash[name.to_s] | argvs.map { |e| e.to_s }
            set_itgt_var('itegration_link_hash',container_hash)
        end

        define_singleton_method("#{name}_has_flag") do |*argvs|
            "itgt 标识"
            container_hash = get_itgt_var('itegration_flag_hash',{})
            container_hash[name.to_s] ||= []
            container_hash[name.to_s] = container_hash[name.to_s] | argvs.map { |e| e.to_s }
            set_itgt_var('itegration_flag_hash',container_hash)
        end

    end
end

#param(name, default) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/tdl/exlib/itegration_verb.rb', line 219

def param(name,default)
    ## param_hash
    # itgt_param_hash = get_itgt_var('itgt_param_hash',{})
    # itgt_param_hash[name.to_s] = default
    # set_itgt_var('itgt_param_hash',itgt_param_hash)
    ## 生成实例方法
    self.class_exec do
        define_method(name) do
            # ItegrationVerb[name]
            itgt_param_hash = get_itgt_var('itgt_param_hash',{})
            if itgt_param_hash[name.to_s]
                return itgt_param_hash[name.to_s]
            else
                itgt_param_hash[name.to_s] = default
                set_itgt_var('itgt_param_hash',itgt_param_hash)
                return default
            end
        end

        define_method("#{name}=") do |value|
            # ItegrationVerb[name]
            itgt_param_hash = get_itgt_var('itgt_param_hash',{})
            itgt_param_hash[name.to_s] = value
            set_itgt_var('itgt_param_hash',itgt_param_hash)
            value
        end
    end
end

#set_itgt_var(name, value) ⇒ Object



14
15
16
17
18
# File 'lib/tdl/exlib/itegration_verb.rb', line 14

def set_itgt_var(name,value)
    # rel = get_itgt_var(name)
    instance_variable_set("@_#{name}_",value)
    container = instance_variable_get("@_#{name}_")
end