Class: HashBrowns::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/hashbrowns/configuration.rb

Constant Summary collapse

VALID_STATUSES =
%w(success info warning error)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hashbrowns/configuration.rb', line 7

def initialize
  @link_hash = Hash.new
  @link_for_id = Hash.new
  @links = Set.new
  @link_parents = Hash.new
  @pretty_names = Hash.new
  @important = Hash.new
  @ignore_important_case = false

  @status_hash = {
    "green" => "success",
    "blue" => "info",
    "red" => "error",
    "yellow" => "warning"
  }

  @table_styles = Set.new
  @key_fields = Hash.new
  @parent_overrides = Set.new

end

Instance Attribute Details

#ignore_important_caseObject

Returns the value of attribute ignore_important_case.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def ignore_important_case
  @ignore_important_case
end

#importantObject

Returns the value of attribute important.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def important
  @important
end

#key_fieldsObject

Returns the value of attribute key_fields.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def key_fields
  @key_fields
end

Returns the value of attribute link_for_id.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def link_for_id
  @link_for_id
end

Returns the value of attribute link_hash.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def link_hash
  @link_hash
end

Returns the value of attribute link_parents.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def link_parents
  @link_parents
end

Returns the value of attribute links.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def links
  @links
end

#parent_overridesObject

Returns the value of attribute parent_overrides.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def parent_overrides
  @parent_overrides
end

#pretty_namesObject

Returns the value of attribute pretty_names.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def pretty_names
  @pretty_names
end

#status_hashObject

Returns the value of attribute status_hash.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def status_hash
  @status_hash
end

#table_stylesObject

Returns the value of attribute table_styles.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def table_styles
  @table_styles
end

Instance Method Details



80
81
82
# File 'lib/hashbrowns/configuration.rb', line 80

def add_external_link(name)
  @links.add name.to_s
end


76
77
78
# File 'lib/hashbrowns/configuration.rb', line 76

def add_external_links(*names)
  @links.merge names.map{|x| x.to_s}
end

#add_formatted_name(real, formatted, source) ⇒ Object



70
71
72
73
74
# File 'lib/hashbrowns/configuration.rb', line 70

def add_formatted_name(real, formatted, source)
  real, formatted, source = real.to_s, formatted.to_s, source.to_s
  @pretty_names[real] = Hash.new unless @pretty_names.has_key?(real)
  @pretty_names[real][source] = formatted
end

#add_important_name(name, value, status = false) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/hashbrowns/configuration.rb', line 55

def add_important_name(name, value, status=false)
  name = name.to_s
  if value.kind_of?(Proc)
    @important[name] = value 
    return
  end
  value, status = value.to_s, status.to_s
  value = value.downcase if @ignore_important_case && value.kind_of?(String)
  return false unless status
  status = @status_hash[status] if @status_hash.has_key?(status)

  @important[name] = Hash.new unless @important.has_key?(name)
  @important[name][value] = status
end


96
97
98
# File 'lib/hashbrowns/configuration.rb', line 96

def add_link_by_key(key, path)
  @link_hash[key.to_s] = path.to_s
end


100
101
102
103
104
105
106
# File 'lib/hashbrowns/configuration.rb', line 100

def add_link_by_parent(parent, key, path)
  if @link_parents.has_key?(parent.to_s)
    @link_parents[parent.to_s][key.to_s] = path.to_s
  else
    @link_parents[parent.to_s] = { key.to_s => path.to_s }
  end
end


108
109
110
111
112
113
114
115
116
# File 'lib/hashbrowns/configuration.rb', line 108

def add_link_by_parents(parents, key, path)
  parents.each do |parent|
    if @link_parents.has_key?(parent.to_s)
      @link_parents[parent.to_s][key.to_s] = path.to_s
    else
      @link_parents[parent.to_s] = { key.to_s => path.to_s }
    end
  end
end


84
85
86
87
88
# File 'lib/hashbrowns/configuration.rb', line 84

def add_link_for_id(key, parent)
  key = key.to_s
  @link_for_id[key] = Set.new if @link_for_id[key].nil?
  @link_for_id[key].add(parent.to_s)
end


90
91
92
93
94
# File 'lib/hashbrowns/configuration.rb', line 90

def add_links_for_id(key, parents)
  key = key.to_s
  @link_for_id[key] = Set.new if @link_for_id[key].nil?
  @link_for_id[key].merge(parents.map(&:to_s))
end

#add_overview_field(type, value, *path) ⇒ Object



49
50
51
52
53
# File 'lib/hashbrowns/configuration.rb', line 49

def add_overview_field(type, value, *path)
  type, value, path = type.to_s, value.to_s, path.map{|p| p.to_s}
  @key_fields[type] = Hash.new unless @key_fields.has_key?(type)
  insert_value(@key_fields[type], value, path)
end

#add_parent_override(parent) ⇒ Object



45
46
47
# File 'lib/hashbrowns/configuration.rb', line 45

def add_parent_override(parent)
  @parent_overrides.add(parent)
end

#add_parent_overrides(*parents) ⇒ Object



41
42
43
# File 'lib/hashbrowns/configuration.rb', line 41

def add_parent_overrides(*parents)
  @parent_overrides.merge(parents)
end

#add_status_mapping(name, status) ⇒ Object



29
30
31
32
# File 'lib/hashbrowns/configuration.rb', line 29

def add_status_mapping(name, status)
  raise "Unknown Status" unless VALID_STATUSES.include?(status)
  @status_hash[name] = status
end

#add_table_style(style) ⇒ Object



34
35
36
# File 'lib/hashbrowns/configuration.rb', line 34

def add_table_style(style)
  @table_styles.add(style)
end

#add_table_styles(*styles) ⇒ Object



37
38
39
# File 'lib/hashbrowns/configuration.rb', line 37

def add_table_styles(*styles)
  @table_styles.merge(styles)
end