Class: LaPack::LaEnv
- Inherits:
-
Object
- Object
- LaPack::LaEnv
- Defined in:
- lib/laenv.rb
Overview
Enviroment class for lapack. Defines runtime options
Instance Attribute Summary collapse
-
#ladb ⇒ Object
readonly
Returns the value of attribute ladb.
-
#lapkg ⇒ Object
readonly
Returns the value of attribute lapkg.
-
#lastore ⇒ Object
readonly
Returns the value of attribute lastore.
Instance Method Summary collapse
- #add(db, params = {}) ⇒ Object
- #db(name) ⇒ Object
- #dbs ⇒ Object
- #dbs_init ⇒ Object
-
#dbs_store ⇒ Object
Returns dbs path.
-
#initialize(args = {}) ⇒ LaEnv
constructor
A new instance of LaEnv.
- #quiet? ⇒ Boolean
- #supports?(dbtype) ⇒ Boolean
Constructor Details
#initialize(args = {}) ⇒ LaEnv
Returns a new instance of LaEnv.
10 11 12 13 14 15 16 17 18 |
# File 'lib/laenv.rb', line 10 def initialize(args={}) @quiet = args.delete(:quiet) || false @lastore = File.(args.delete(:lastore)|| "~/.config/lapack") @ladb = "db" @lapkg = "pkg" FileUtils.mkdir_p(dbs_store) raise "Unknown args #{args.keys.join(', ')}" unless args.keys.empty? end |
Instance Attribute Details
#ladb ⇒ Object (readonly)
Returns the value of attribute ladb.
8 9 10 |
# File 'lib/laenv.rb', line 8 def ladb @ladb end |
#lapkg ⇒ Object (readonly)
Returns the value of attribute lapkg.
8 9 10 |
# File 'lib/laenv.rb', line 8 def lapkg @lapkg end |
#lastore ⇒ Object (readonly)
Returns the value of attribute lastore.
8 9 10 |
# File 'lib/laenv.rb', line 8 def lastore @lastore end |
Instance Method Details
#add(db, params = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/laenv.rb', line 39 def add(db, params = {}) if(db.to_sym.eql?(:ctan)) File.open(File.join(dbs_store, "#{db}.db"), "w") {|f| f << {name: 'ctan', clazz: 'CtanProvider', params: {}}.to_json} elsif (db.to_sym.eql?(:github)) File.open(File.join(dbs_store, "#{db}.db"), "w") {|f| f << {name: 'github', clazz: 'GithubProvider', params: {}}.to_json} else raise "Unsupported" end end |
#db(name) ⇒ Object
31 32 33 |
# File 'lib/laenv.rb', line 31 def db(name) @dbs_hash[name.to_sym] end |
#dbs ⇒ Object
35 36 37 |
# File 'lib/laenv.rb', line 35 def dbs @dbs_hash.keys end |
#dbs_init ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/laenv.rb', line 53 def dbs_init @dbs_hash = Dir["#{dbs_store}/*.db"] .map do |dbfile| File.open(dbfile){|f| JSON.parse(f.read, symbolize_names: true)} end .inject({}) do |h, db| h.update({ db[:name].to_sym => LaPack::const_get(db[:clazz]).new(self, db[:params]) }) end end |
#dbs_store ⇒ Object
Returns dbs path
27 28 29 |
# File 'lib/laenv.rb', line 27 def dbs_store File.join(@lastore, ladb) end |
#quiet? ⇒ Boolean
20 21 22 |
# File 'lib/laenv.rb', line 20 def quiet? @quiet end |
#supports?(dbtype) ⇒ Boolean
49 50 51 |
# File 'lib/laenv.rb', line 49 def supports?(dbtype) (:ctan.eql? dbtype.to_sym) || (:github.eql? dbtype.to_sym) end |