Class: SportDB::Loader
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(logger = nil) ⇒ Loader
constructor
A new instance of Loader.
-
#load_fixtures_builtin(name) ⇒ Object
load from gem (built-in).
-
#load_fixtures_with_include_path(name, include_path) ⇒ Object
load from file system.
- #run(opts, args) ⇒ Object
Constructor Details
#initialize(logger = nil) ⇒ Loader
Returns a new instance of Loader.
10 11 12 13 14 15 16 17 |
# File 'lib/sportdb/loader.rb', line 10 def initialize( logger=nil ) if logger.nil? @logger = Logger.new(STDOUT) @logger.level = Logger::INFO else @logger = logger end end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
19 20 21 |
# File 'lib/sportdb/loader.rb', line 19 def logger @logger end |
Instance Method Details
#load_fixtures_builtin(name) ⇒ Object
load from gem (built-in)
47 48 49 50 51 52 53 54 55 |
# File 'lib/sportdb/loader.rb', line 47 def load_fixtures_builtin( name ) # load from gem (built-in) path = "#{SportDB.root}/db/#{name}.rb" puts "*** loading data '#{name}' (#{path})..." code = File.read( path ) load_fixtures_worker( code ) end |
#load_fixtures_with_include_path(name, include_path) ⇒ Object
load from file system
37 38 39 40 41 42 43 44 45 |
# File 'lib/sportdb/loader.rb', line 37 def load_fixtures_with_include_path( name, include_path ) # load from file system path = "#{include_path}/#{name}.rb" puts "*** loading data '#{name}' (#{path})..." code = File.read( path ) load_fixtures_worker( code ) end |
#run(opts, args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sportdb/loader.rb', line 22 def run( opts, args ) args.each do |arg| name = arg # File.basename( arg, '.*' ) if opts.load? load_fixtures_builtin( name ) else load_fixtures_with_include_path( name, opts.data_path ) end end end |