Class: ConfigBase

Inherits:
Entity show all
Defined in:
lib/qooxview/helpers/config_base.rb

Instance Attribute Summary

Attributes inherited from Entity

#changed, #id, #show_error_missing

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#data, #data_get, #data_set_hash, #delete, #get_unique, #init_instance, #initialize, #inspect, #method_missing, #old_respond_to?, #respond_to?, #to_a, #to_frontend, #true

Constructor Details

This class inherits a constructor from Entity

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Entity

Class Method Details

.add_function(func) ⇒ Object



265
266
267
# File 'lib/qooxview/helpers/config_base.rb', line 265

def self.add_function(func)
  self.store({:functions => self.get_functions.push(func.to_sym)})
end

.del_function(func) ⇒ Object



269
270
271
# File 'lib/qooxview/helpers/config_base.rb', line 269

def self.del_function(func)
  self.store({:functions => self.get_functions.reject { |f| f == func.to_sym }})
end

.get_functionsObject



194
195
196
# File 'lib/qooxview/helpers/config_base.rb', line 194

def self.get_functions
  ConfigBases.singleton.get_functions
end

.get_functions_numericObject



198
199
200
# File 'lib/qooxview/helpers/config_base.rb', line 198

def self.get_functions_numeric
  ConfigBases.singleton.get_functions_numeric
end

.has_function?(func) ⇒ Boolean

Returns:

  • (Boolean)


257
258
259
# File 'lib/qooxview/helpers/config_base.rb', line 257

def self.has_function?(func)
  ConfigBase.get_functions.index(func.to_sym) != nil
end

.method_missing(m, *args) ⇒ Object



244
245
246
247
248
249
250
251
# File 'lib/qooxview/helpers/config_base.rb', line 244

def self.method_missing(m, *args)
  dputs(4) { "#{m} - #{args.inspect} - #{ConfigBases.singleton.inspect}" }
  if args.length > 0
    ConfigBases.singleton.send(m, *args)
  else
    ConfigBases.singleton.send(m)
  end
end

.respond_to?(cmd) ⇒ Boolean

Returns:

  • (Boolean)


253
254
255
# File 'lib/qooxview/helpers/config_base.rb', line 253

def self.respond_to?(cmd)
  ConfigBases.singleton.respond_to?(cmd)
end

.set_functions(func) ⇒ Object



261
262
263
# File 'lib/qooxview/helpers/config_base.rb', line 261

def self.set_functions(func)
  self.store({:functions => func.collect{|f| f.to_sym}})
end

.store(c = {}) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/qooxview/helpers/config_base.rb', line 202

def self.store(c = {})
  #dputs_func
  if c.has_key? :functions
    funcs = c._functions
    dputs(4) { "Storing functions: #{funcs.inspect}" }
    if funcs.index { |i| i.to_s.to_i.to_s == i.to_s }
      dputs(3) { 'Converting numeric to names' }
      funcs = funcs.collect { |d|
        ConfigBases.functions[d-1].to_sym
      }
    else
      funcs.to_sym!
    end
    funcs.each { |f|
      ConfigBases.functions_base.each { |k, v|
        if v.index(f)
          dputs(2) { "Adding #{k.inspect} to #{f}" }
          funcs.push k.to_sym
        end
      }
    }
    funcs.flatten!
    ConfigBases.functions_conflict.each { |f|
      dputs(4) { "Testing conflict of #{f}" }
      list = f.collect { |g|
        funcs.index(g)
      }.select { |l| l }.sort
      dputs(4) { "List is #{list.inspect}" }
      if list.length > 1
        list.pop
        dputs(4) { "Deleting #{list.inspect}" }
        list.each { |l| funcs.delete_at(l) }
      end
    }
    c[:functions] = funcs
  end
  dputs(4) { "Storing #{c.inspect}" }
  ConfigBases.singleton.data_set_hash(c)
  ConfigBase.setup_defaults
  View.update_configured_all
end

Instance Method Details

#data_set(field, value) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/qooxview/helpers/config_base.rb', line 127

def data_set(field, value)
  old = data_get(field)
  ret = super(field, value)
  if !@loading
    return if old == value
    dputs(3) { "Updating #{field} to #{value.inspect}, #{old.inspect}" }
    if field == :functions
      if (del = old - value).length > 0
        @proxy.call_changed(:function_del, del, nil)
      end
      if (add = value - old).length > 0
        @proxy.call_changed(:function_add, add, nil)
      end
    else
      @proxy.call_changed(field, value, old)
    end
  end
  ret
end

#debug_lvl=(lvl) ⇒ Object



161
162
163
164
165
166
# File 'lib/qooxview/helpers/config_base.rb', line 161

def debug_lvl=(lvl)
  dputs(4) { "Setting debug-lvl to #{lvl}" }
  data_set(:_debug_lvl, lvl.to_i)
  Object.const_defined?(:DEBUG_LVL) and Object.send(:remove_const, :DEBUG_LVL)
  Object.const_set(:DEBUG_LVL, lvl.to_i)
end

#dputs_show_time=(t) ⇒ Object



168
169
170
# File 'lib/qooxview/helpers/config_base.rb', line 168

def dputs_show_time=(t)
  DPuts.show_time = (self._dputs_show_time = t).first
end

#dputs_silent=(s) ⇒ Object



172
173
174
# File 'lib/qooxview/helpers/config_base.rb', line 172

def dputs_silent=(s)
  DPuts.silent = (self._dputs_silent = s) == %w(true)
end

#dputs_terminal_width=(w) ⇒ Object



176
177
178
# File 'lib/qooxview/helpers/config_base.rb', line 176

def dputs_terminal_width=(w)
  DPuts.terminal_width = (self._dputs_terminal_width = w).to_i
end

#get_functionsObject



184
185
186
# File 'lib/qooxview/helpers/config_base.rb', line 184

def get_functions
  functions.to_sym
end

#get_functions_numericObject



188
189
190
191
192
# File 'lib/qooxview/helpers/config_base.rb', line 188

def get_functions_numeric
  functions.collect { |f|
    @proxy.functions.index(f.to_sym) + 1
  }
end

#is_loadingObject



120
121
122
123
124
125
# File 'lib/qooxview/helpers/config_base.rb', line 120

def is_loading
  oldloading = @loading
  @loading = true
  yield
  @loading = oldloading
end

#save_block_to_object(block, obj) ⇒ Object



152
153
154
155
156
157
158
159
# File 'lib/qooxview/helpers/config_base.rb', line 152

def save_block_to_object(block, obj)
  dputs(3) { "Pushing block #{block} to object #{obj}" }
  ConfigBases.get_block_fields(block).each { |f|
    value = data_get(f)
    dputs(3) { "Setting #{f} in #{block} to #{value}" }
    obj.send("#{f}=", value)
  }
end

#send_configObject

This can be used in an overriden ConfigBase-class to send individual configs



117
118
# File 'lib/qooxview/helpers/config_base.rb', line 117

def send_config
end

#setup_defaultsObject



106
107
108
109
110
111
112
113
114
# File 'lib/qooxview/helpers/config_base.rb', line 106

def setup_defaults
  DPuts.logall_file = dputs_logall
  DPuts.log_file = dputs_logfile
  DPuts.silent = dputs_silent == %w(true)
  DPuts.show_time = (dputs_show_time || %w(min)).first
  DPuts.terminal_width = (dputs_terminal_width || 160).to_i

  send_config
end

#setup_instanceObject



98
99
100
101
102
103
104
# File 'lib/qooxview/helpers/config_base.rb', line 98

def setup_instance
  dputs(4) { "Setting up ConfigBase with debug_lvl = #{debug_lvl}" }
  if !Object.const_defined? :DEBUG_LVL
    self.debug_lvl = debug_lvl
  end
  is_loading { setup_defaults }
end

#to_hashObject



180
181
182
# File 'lib/qooxview/helpers/config_base.rb', line 180

def to_hash
  super.merge(:functions => get_functions_numeric)
end

#update(action, value, old = nil) ⇒ Object



147
148
149
150
# File 'lib/qooxview/helpers/config_base.rb', line 147

def update(action, value, old = nil)
  dputs(3) { "No action #{action.inspect} changed to #{value.inspect} from #{old.inspect}" }
  #super(action, value, old)
end