Class: Hash

Inherits:
Object show all
Includes:
Tracing::RuleMatch
Defined in:
lib/extensions/hash_extensions.rb,
lib/extensions/hash_rule_extensions.rb

Instance Method Summary collapse

Methods included from Tracing::RuleMatch

#matches_any?

Instance Method Details

#action_handlersObject

return action_handler



80
81
82
83
84
85
86
87
# File 'lib/extensions/hash_extensions.rb', line 80

def action_handlers
  action_handler_list = self[:action_handlers]
  if action_handler_list
    action_handler_list.action_handlers        
  else
    Tracing::ActionHandler.new(self)
  end
end

#appenderObject

Rework?



101
102
103
104
# File 'lib/extensions/hash_extensions.rb', line 101

def appender        
  puts self[:template].inspect
  # appenders
end

#appendersObject



89
90
91
92
93
94
95
96
97
98
# File 'lib/extensions/hash_extensions.rb', line 89

def appenders        
  appender_list = self[:appenders]
  return appender_list.appenders if appender_list
  template = self.template
  if template
    puts template.inspect
  else
    puts "no template"
  end
end

#configurationObject



57
58
59
# File 'lib/extensions/hash_extensions.rb', line 57

def configuration
  Tracing::Configuration.new(self)
end

#contextObject



3
4
5
6
7
8
9
10
11
# File 'lib/extensions/hash_extensions.rb', line 3

def context
  modules = self[:modules]
  cls_name = self[:class_name]
  method_name = self[:method_name]
  self[:modules] = cls_name.modules if cls_name && !modules
  self[:class_name] = cls_name.class_name if cls_name
  calculate_full_names
  self
end

#create_filterObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/extensions/hash_extensions.rb', line 116

def create_filter
  return self.filters if self[:filters]
  hash = self.create_filter_hash || self    
  if hash    
    filter_class = hash.filter_class
    if filter_class
      filter_class.new(hash) 
    else
      nil
    end
  else
    nil
  end
end

#create_filter_hashObject



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/extensions/hash_extensions.rb', line 131

def create_filter_hash
# puts "TRY create_filter: " + name_hash.inspect
  [:module_filter, :class_filter, :method_filter, :vars_filter, :args_filter].each do |symbol|
    # puts "symbol:" + symbol.to_s
    res = self.try_create_filter_hash(symbol) 
    # puts "Filter created:" + res.inspect     
    return res if res
  end
  # puts "no filter could be created :("
  nil
end

#filter_classObject



163
164
165
166
167
168
169
170
171
# File 'lib/extensions/hash_extensions.rb', line 163

def filter_class
  FilterMappings.convenience_map.select do |key, _filter|
    return _filter.filter_class if self.has_key?(key) || self.has_key?(_filter)
  end
  FilterMappings.rules_map.select do |key, _filter|
    return _filter.filter_class if self.has_key? key
  end
  nil
end

#filtersObject

return filter



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/extensions/hash_extensions.rb', line 66

def filters
  filter_list = self[:filters]  
  # puts "filter_list: #{filter_list.inspect}"  
  if filter_list
    filter_list.filters              
  else
    # puts "create filter from: #{self.inspect}"
    x = self.create_filter
    # puts "created filter: #{x.inspect}"
    x
  end        
end

#final_yield_actionObject



61
62
63
# File 'lib/extensions/hash_extensions.rb', line 61

def final_yield_action
  self[:final_yield_action] || :include
end

#full_class_nameObject



44
45
46
47
48
# File 'lib/extensions/hash_extensions.rb', line 44

def full_class_name
  mod_name = self.full_modules_name
  name = self[:class_name]
  name = "#{mod_name}::#{name}" if !mod_name.blank?
end

#full_method_nameObject



50
51
52
53
54
# File 'lib/extensions/hash_extensions.rb', line 50

def full_method_name
  cls_name = self.full_class_name
  name = self[:method_name]
  name = "#{cls_name}.#{name}" if !cls_name.blank?
end

#full_modules_nameObject



40
41
42
# File 'lib/extensions/hash_extensions.rb', line 40

def full_modules_name
  self[:modules].join("::") if self[:modules]
end

#map(key) ⇒ Object



157
158
159
160
161
# File 'lib/extensions/hash_extensions.rb', line 157

def map(key)
  clazz = self[key]
  return clazz if clazz
  self[:default]
end

#method_name=(name) ⇒ Object



13
14
15
16
# File 'lib/extensions/hash_extensions.rb', line 13

def method_name=(name)
  self[:method_name] = name
  calculate_full_method_name
end

#result=(res) ⇒ Object



18
19
20
# File 'lib/extensions/hash_extensions.rb', line 18

def result=(res)
  self[:result] = res
end

#rule_allow_action(name) ⇒ Object

return a symbol, either - :include, :exclude or :exclude_and_yield, :include_and_yield or :yield (let next filter decide)



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/extensions/hash_rule_extensions.rb', line 14

def rule_allow_action(name)
  include_rules = self[:include].rule_list
  
  puts "include_rules: #{include_rules.inspect}, name: #{name}"
  
  if !include_rules.blank?
    # puts "Rule include"            
    res = include_rules.matches_any?(name)
    return :include if res
  end
  exclude_rules = self[:exclude].rule_list
  if !exclude_rules.blank?
    # puts "Rule exclude"      
    return :exclude if exclude_rules.matches_any?(name)
  end

  rules = self[:exclude_and_yield].rule_list
  if !rules.blank?
    # puts "Rule exclude"      
    return :exclude_and_yield if rules.matches_any?(name)
  end

  rules = self[:include_and_yield].rule_list
  if !rules.blank?
    # puts "Rule exclude"      
    return :include_and_yield if rules.matches_any?(name)
  end


  # puts "Not included or excluded"          
  if !self[:default].nil?
    # puts "Return default: #{self[:default]}"
    return self[:default]      
  end
  # puts "Rule yields"
  return :yield
rescue RuleTypeError
  # puts "error"
  return :exclude    
end

#rule_listObject



9
10
11
# File 'lib/extensions/hash_rule_extensions.rb', line 9

def rule_list
  rules
end

#rules_allow_action(name) ⇒ Object



4
5
6
7
# File 'lib/extensions/hash_rule_extensions.rb', line 4

def rules_allow_action(name)
  puts "Hash: rules_allow_action"
  rule_allow_action(name)
end

#set_context(hash) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/extensions/hash_extensions.rb', line 23

def set_context(hash)
  modules = hash[:modules]
  cls_name = hash[:class_name]
  method_name = hash[:method_name]
  args = hash[:args]
  vars = hash[:vars]
  self[:modules] = cls_name.modules if cls_name
  self[:modules] = modules if modules

  self[:class_name] = cls_name.class_name if cls_name
  self[:method_name] = method_name if method_name
  self[:args] = args if args
  self[:vars] = vars if vars

  calculate_full_names  
end

#templateObject

return template



108
109
110
111
112
113
114
# File 'lib/extensions/hash_extensions.rb', line 108

def template     
  puts "Template from : #{self.inspect}"
  template_key = self[:template] || self[:type]
  template_class = TemplateMappings.defaults[template_key]
  puts template_class.inspect
  template_class.new self if template_class
end

#try_create_filter_hash(symbol) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/extensions/hash_extensions.rb', line 143

def try_create_filter_hash(symbol)
  _symbol = has_any_prefix(symbol)
  # puts _symbol.inspect
  return if !_symbol
  
  prefix = _symbol[:prefix]
  filter_sym = _symbol[:filter_symbol]

  filter_names = self[filter_sym]

  rule_symbol = prefix.to_sym.rule
  {symbol => {rule_symbol => filter_names}}    
end