Class: RareMap::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/rare_map/config_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_opts = nil, group = nil) ⇒ Options

Returns a new instance of Options.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rare_map/config_loader.rb', line 63

def initialize(raw_opts = nil, group = nil)
  @opts = { 'group'       => 'default',
            'primary_key' => {},
            'foreign_key' => { 'suffix' => nil, 'alias' => {} } }
            
  if raw_opts and raw_opts.kind_of? Hash
    if raw_opts['group']
      @opts['group'] = raw_opts['group']
    end
    if raw_opts['primary_key'].kind_of? Hash
      @opts['primary_key'] = raw_opts['primary_key'].select { |k, v| k.kind_of? String and v.kind_of? String }
    end
    if raw_opts['foreign_key'] and raw_opts['foreign_key']['suffix'].kind_of? String
       @opts['foreign_key']['suffix'] = raw_opts['foreign_key']['suffix']
    end
    if raw_opts['foreign_key'] and raw_opts['foreign_key']['alias'].kind_of? Hash
       @opts['foreign_key']['alias'] = raw_opts['foreign_key']['alias'].select { |k, v| k.kind_of? String and v.kind_of? String }
    end
  end
  @opts['group'] = group if group.kind_of? String
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



61
62
63
# File 'lib/rare_map/config_loader.rb', line 61

def opts
  @opts
end

Instance Method Details

#find_primary_key_by_table(table_name) ⇒ Object



93
94
95
96
# File 'lib/rare_map/config_loader.rb', line 93

def find_primary_key_by_table(table_name)
  @opts['primary_key'].each { |k, v| return v if k == table_name }
  nil
end

#find_table_by_foreign_key(column_name) ⇒ Object



98
99
100
101
# File 'lib/rare_map/config_loader.rb', line 98

def find_table_by_foreign_key(column_name)
  @opts['foreign_key']['alias'].each { |k, v| return v if k == column_name }
  nil
end

#fk_suffixObject



103
104
105
# File 'lib/rare_map/config_loader.rb', line 103

def fk_suffix
  @opts['foreign_key']['suffix']
end

#groupObject



89
90
91
# File 'lib/rare_map/config_loader.rb', line 89

def group
  @opts['group'] || 'default'
end

#group?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/rare_map/config_loader.rb', line 85

def group?
  @opts['group'] != 'default'
end

#to_sObject



107
108
109
# File 'lib/rare_map/config_loader.rb', line 107

def to_s
  @opts.to_s
end