Module: CDK::Bindings

Included in:
CDKOBJS
Defined in:
lib/cdk/mixins/bindings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#binding_listObject (readonly)

Returns the value of attribute binding_list.



3
4
5
# File 'lib/cdk/mixins/bindings.rb', line 3

def binding_list
  @binding_list
end

Instance Method Details

#bind(type, key, function, data) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/cdk/mixins/bindings.rb', line 20

def bind(type, key, function, data)
  obj = self.bindableObject(type)
  if key.ord < Ncurses::KEY_MAX && !(obj.nil?)
    if key.ord != 0
      obj.binding_list[key.ord] = [function, data]
    end
  end
end

#bindableObject(cdktype) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/cdk/mixins/bindings.rb', line 10

def bindableObject(cdktype)
  if cdktype != self.object_type
    return nil
  elsif [:FSELECT, :ALPHALIST].include?(self.object_type)
    return @entry_field
  else
    return self
  end
end

#checkBind(type, key) ⇒ Object

This checks to see if the binding for the key exists: If it does then it runs the command and returns its value, normally true If it doesn’t it returns a false. This way we can ‘overwrite’ coded bindings.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cdk/mixins/bindings.rb', line 47

def checkBind(type, key)
  obj = self.bindableObject(type)
  if !(obj.nil?) && obj.binding_list.include?(key)
    function = obj.binding_list[key][0]
    data = obj.binding_list[key][1]

    if function == :getc
      return data
    else
      return function.call(type, obj, data, key)
    end
  end
  return false
end

#cleanBindings(type) ⇒ Object



36
37
38
39
40
41
# File 'lib/cdk/mixins/bindings.rb', line 36

def cleanBindings(type)
  obj = self.bindableObject(type)
  if !(obj.nil?) && !(obj.binding_list.nil?)
    obj.binding_list.clear
  end
end

#init_bindingsObject



5
6
7
8
# File 'lib/cdk/mixins/bindings.rb', line 5

def init_bindings
  # Bound functions
  @binding_list = {}
end

#isBind(type, key) ⇒ Object

This checks to see if the binding for the key exists.



63
64
65
66
67
68
69
70
71
# File 'lib/cdk/mixins/bindings.rb', line 63

def isBind(type, key)
  result = false
  obj = self.bindableObject(type)
  unless obj.nil?
    result = obj.binding_list.include?(key)
  end

  return result
end

#unbind(type, key) ⇒ Object



29
30
31
32
33
34
# File 'lib/cdk/mixins/bindings.rb', line 29

def unbind(type, key)
  obj = self.bindableObject(type)
  unless obj.nil?
    obj.binding_list.delete(key)
  end
end