Class: Olympic::Settings
- Inherits:
-
Object
show all
- Extended by:
- Forwardable, ClassMethods
- Defined in:
- lib/olympic/settings.rb,
lib/olympic/settings/class_methods.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary
collapse
- DEFAULT_SETTINGS =
{
match_class: "Match",
match_primary_key: :id,
match_tournament_key: :tournament_id,
match_foreign_key: :match_id,
match_winner_key: :winner_id,
match_join_key: :match_id,
team_class: "Team",
team_primary_key: :id,
team_tournament_join: :teams_tournaments,
team_join_key: :team_id,
tournament_class: "Tournament",
tournament_primary_key: :id,
tournament_root_key: :root_id,
tournament_join_key: :tournament_id,
source_class: "Source",
source_primary_key: :id,
source_match_key: :match_id,
source_source_key: :source_id,
source_source_type: :source_type,
rating: :glicko
}
Instance Method Summary
collapse
settings
Constructor Details
#initialize(settings = {}) ⇒ Settings
Returns a new instance of Settings.
35
36
37
38
|
# File 'lib/olympic/settings.rb', line 35
def initialize(settings = {})
@settings = DEFAULT_SETTINGS.clone.merge(settings)
@klass = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/olympic/settings.rb', line 64
def method_missing(method, *args, &block)
return super if args.length > 1 || block_given?
method = method.to_s
case method
when /\?\z/, /\!\z/
super
when /\A(.*)\=\z/
super unless args.length == 1
self[$+] = args[0]
else
super unless args.length == 0
self[method]
end
end
|
Instance Method Details
#[](key) ⇒ Object
50
51
52
|
# File 'lib/olympic/settings.rb', line 50
def [](key)
@settings.fetch(key.to_s.to_sym)
end
|
#[]=(key, value) ⇒ Object
45
46
47
48
|
# File 'lib/olympic/settings.rb', line 45
def []=(key, value)
@klass = {}
@settings[key.to_s.to_sym] = value
end
|
#build {|_self| ... } ⇒ Object
40
41
42
43
|
# File 'lib/olympic/settings.rb', line 40
def build
yield self
self
end
|
#class_for(name) ⇒ Object
54
55
56
57
58
|
# File 'lib/olympic/settings.rb', line 54
def class_for(name)
@klass.fetch(name) do
@klass[name] = fetch(:"#{name}_class").constantize
end
end
|
#rating_system ⇒ Object
60
61
62
|
# File 'lib/olympic/settings.rb', line 60
def rating_system
Rating.for(rating)
end
|