Module: SportDb

Defined in:
lib/sportdb.rb,
lib/sportdb/lang.rb,
lib/sportdb/stats.rb,
lib/sportdb/reader.rb,
lib/sportdb/schema.rb,
lib/sportdb/deleter.rb,
lib/sportdb/updater.rb,
lib/sportdb/version.rb,
lib/sportdb/cli/opts.rb,
lib/sportdb/data/fixtures.rb,
lib/sportdb/service/version.rb

Defined Under Namespace

Modules: FixtureHelpers, Fixtures, Keys, Matcher, Models, Service Classes: CreateDb, Deleter, Lang, Opts, Reader, Stats, Updater

Constant Summary collapse

VERSION =
'1.7.4'

Class Method Summary collapse

Class Method Details



81
82
83
# File 'lib/sportdb.rb', line 81

def self.banner
  "sportdb #{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
end

.config_pathObject



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

def self.config_path
  "#{root}/config"
end

.createObject



111
112
113
114
# File 'lib/sportdb.rb', line 111

def self.create
  CreateDb.new.up
  WorldDb::Models::Prop.create!( key: 'db.schema.sport.version', value: VERSION )
end

.data_pathObject



93
94
95
# File 'lib/sportdb.rb', line 93

def self.data_path
  "#{root}/data"
end

.delete!Object

delete ALL records (use with care!)



145
146
147
148
# File 'lib/sportdb.rb', line 145

def self.delete!
  puts '*** deleting sport table records/data...'
  Deleter.new.run
end

.langObject



97
98
99
100
101
102
103
# File 'lib/sportdb.rb', line 97

def self.lang
  # todo/fix: find a better way for single instance ??
   if @lang.nil?
     @lang = Lang.new
   end
   @lang
end

.load_pluginsObject



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/sportdb.rb', line 172

def self.load_plugins

  @found  ||= []
  @loaded ||= {}
  @files  ||= Gem.find_files( 'sportdb_plugin.rb' )

  puts "#{@files.size} plugin files found:"
  @files.each do |file|
    puts "  >#{file}<"
  end
  
  ## todo: extract version and name of gem?
  puts "normalized/match pattern:"
  @files.each do |file|
    if file =~ /sportdb-([a-z]+)-(\d\.\d.\d)/
      puts "  >#{$1}< | >#{$2}<"
      @found << file
    else
      puts "*** error: ignoring plugin script >#{file}< not matching gem naming pattern"
    end
  end
  
  @found.each do |file|
    begin
      puts  "loading plugin script #{file}"
      require file
    rescue LoadError => e
      puts "*** error loading plugin script #{file.inspect}: #{e.message}. skipping..."
    end
  end

end

.mainObject



106
107
108
109
# File 'lib/sportdb.rb', line 106

def self.main
  ## Runner.new.run(ARGV) - old code
  require 'sportdb/cli/main'
end

.propsObject



166
167
168
# File 'lib/sportdb.rb', line 166

def self.props
  Stats.new.props
end

.read(ary, include_path) ⇒ Object

load built-in (that is, bundled within the gem) named plain text seeds

  • pass in an array of pairs of event/seed names e.g. [[‘at.2012/13’, ‘at/2012_13/bl’],

    ['cl.2012/13', 'cl/2012_13/cl']] etc.
    


135
136
137
138
139
140
141
# File 'lib/sportdb.rb', line 135

def self.read( ary, include_path )
  reader = Reader.new( include_path )
  ## todo: check kind_of?( Array ) or kind_of?(String) to support array or string
  ary.each do |name|
    reader.load( name )
  end
end

.read_all(include_path) ⇒ Object

convenience helper



121
122
123
# File 'lib/sportdb.rb', line 121

def self.read_all( include_path )   # convenience helper
  read_setup( 'setups/all', include_path )
end

.read_builtinObject



125
126
127
# File 'lib/sportdb.rb', line 125

def self.read_builtin
  read_setup( 'setups/all', data_path )
end

.read_setup(setup, include_path) ⇒ Object



116
117
118
119
# File 'lib/sportdb.rb', line 116

def self.read_setup( setup, include_path )
  reader = Reader.new( include_path )
  reader.load_setup( setup )
end

.rootObject



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

def self.root
  "#{File.expand_path( File.dirname(File.dirname(__FILE__)) )}"
end

.statsObject



156
157
158
159
160
# File 'lib/sportdb.rb', line 156

def self.stats
  stats = Stats.new
  stats.tables
  stats.props
end

.tablesObject



162
163
164
# File 'lib/sportdb.rb', line 162

def self.tables
  Stats.new.tables
end

.update!Object

method delete!



150
151
152
153
# File 'lib/sportdb.rb', line 150

def self.update!
  puts '*** update event fixtures...'
  Updater.new.run
end