class RareMap::Options
RareMap::Options
defines all available options of RareMap
. @author Wei-Ming Wu @!attribute [r] opts
@return [Hash] the details of options
Constants
- DEFAULT_GROUP
A default group name
Attributes
opts[R]
Public Class Methods
new(raw_opts = {})
click to toggle source
Creates a Options
.
@param raw_opts [Hash] the details of options @return [Options] a Options
object
# File lib/rare_map/options.rb, line 17 def initialize(raw_opts = {}) raw_opts ||= {} raw_opts = raw_opts.with_indifferent_access @opts = { group: DEFAULT_GROUP, primary_key: {}, foreign_key: { suffix: nil, alias: {} } }.with_indifferent_access if 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].kind_of? Hash and raw_opts[:foreign_key][:suffix].kind_of? String @opts[:foreign_key][:suffix] = raw_opts[:foreign_key][:suffix] end if raw_opts[:foreign_key].kind_of? Hash 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 if raw_opts[:group].kind_of? String @opts[:group] = raw_opts[:group] end end end
Public Instance Methods
find_primary_key_by_table(table_name)
click to toggle source
find_table_by_foreign_key(column_name)
click to toggle source
fk_suffix()
click to toggle source
Returns the suffix of a foreign key should have
@return [String, nil] the suffix of a foreign key should have
# File lib/rare_map/options.rb, line 74 def fk_suffix @opts[:foreign_key][:suffix] end
group()
click to toggle source
Returns the name of this Options’ group
@return [String] the name of this Options’ group
# File lib/rare_map/options.rb, line 53 def group @opts[:group] || DEFAULT_GROUP end