Class: Coffer::Registry
- Inherits:
-
Object
- Object
- Coffer::Registry
- Includes:
- Singleton
- Defined in:
- lib/coffer/registry.rb
Constant Summary collapse
- BASE_DIR =
'/opt/coffer'
- BIN_DIR =
File.join(BASE_DIR, 'bin')
- DATA_FILE =
File.join(BASE_DIR, 'coins.dat')
Instance Attribute Summary collapse
-
#coins ⇒ Object
readonly
Returns the value of attribute coins.
Class Method Summary collapse
Instance Method Summary collapse
- #find(coin) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #load(coin) ⇒ Object
- #load_coins(directory) ⇒ Object
- #make_directories ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
15 16 17 18 19 |
# File 'lib/coffer/registry.rb', line 15 def initialize make_directories @coins = [] load_coins File.join(File.dirname(__FILE__), '../../coins') end |
Instance Attribute Details
#coins ⇒ Object (readonly)
Returns the value of attribute coins.
13 14 15 |
# File 'lib/coffer/registry.rb', line 13 def coins @coins end |
Class Method Details
.load(coin) ⇒ Object
33 34 35 |
# File 'lib/coffer/registry.rb', line 33 def self.load(coin) instance.load coin end |
Instance Method Details
#find(coin) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/coffer/registry.rb', line 52 def find( coin ) coin = coin.downcase @coins.find do |c| c.name.downcase == coin || c.symbol.to_s.downcase == coin end end |
#load(coin) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/coffer/registry.rb', line 37 def load( coin ) if coin.is_a?(Symbol) || coin.is_a?(String) coin = ActiveSupport::Inflector.camelize( coin, true ) coin = Coffer::Coin.const_get( coin ) elsif coin.is_a?(Coffer::Definition) # pass else raise "Wrong type! (#{ coin.class.to_s })" end @coins << coin # warn "Loaded coin: #{ coin.inspect } #{ coin.symbol }" end |
#load_coins(directory) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/coffer/registry.rb', line 25 def load_coins(directory) Dir["#{ directory }/*.rb"].each do |d| require d self.load File.basename(d, '.rb') end end |
#make_directories ⇒ Object
21 22 23 |
# File 'lib/coffer/registry.rb', line 21 def make_directories FileUtils.mkdir_p BIN_DIR end |