Class: BrickAndMortar::Config
- Inherits:
-
Object
- Object
- BrickAndMortar::Config
- Defined in:
- lib/brick_and_mortar/config.rb
Instance Attribute Summary collapse
-
#store ⇒ Object
Returns the value of attribute store.
Instance Method Summary collapse
- #bricks_and_store_from_data(data) ⇒ Object
- #create_store! ⇒ Object
- #destroy_store! ⇒ Object
-
#initialize(store_) ⇒ Config
constructor
A new instance of Config.
- #parse!(yaml) ⇒ Object
- #parse_data!(brick_data, store_ = @store) ⇒ Object
- #parse_file!(yaml_file) ⇒ Object
- #store_exists? ⇒ Boolean (also: #store_exist?)
Constructor Details
#initialize(store_) ⇒ Config
Returns a new instance of Config.
10 11 12 |
# File 'lib/brick_and_mortar/config.rb', line 10 def initialize(store_) @store = store_ end |
Instance Attribute Details
#store ⇒ Object
Returns the value of attribute store.
8 9 10 |
# File 'lib/brick_and_mortar/config.rb', line 8 def store @store end |
Instance Method Details
#bricks_and_store_from_data(data) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/brick_and_mortar/config.rb', line 37 def bricks_and_store_from_data(data) store_ = @store begin brick_data = if data['store'] && !data['store'].empty? store_ = data['store'] data['bricks'] elsif data['bricks'] data['bricks'] else [] end rescue TypeError brick_data = data end [brick_data, store_] end |
#create_store! ⇒ Object
18 19 20 21 22 23 |
# File 'lib/brick_and_mortar/config.rb', line 18 def create_store! unless store_exists? FileUtils.mkpath @store fail "Could not create store at \"#{@store}\"" unless store_exists? end end |
#destroy_store! ⇒ Object
25 26 27 |
# File 'lib/brick_and_mortar/config.rb', line 25 def destroy_store! FileUtils.rm_rf @store end |
#parse!(yaml) ⇒ Object
54 55 56 57 |
# File 'lib/brick_and_mortar/config.rb', line 54 def parse!(yaml) brick_data, store_ = bricks_and_store_from_data YAML.load(yaml) parse_data! brick_data, store_ end |
#parse_data!(brick_data, store_ = @store) ⇒ Object
31 32 33 34 35 |
# File 'lib/brick_and_mortar/config.rb', line 31 def parse_data!(brick_data, store_ = @store) brick_data.map do |brick| Brick::Config.new(brick, store_) end end |
#parse_file!(yaml_file) ⇒ Object
59 60 61 62 |
# File 'lib/brick_and_mortar/config.rb', line 59 def parse_file!(yaml_file) brick_data, store_ = bricks_and_store_from_data YAML.load_file(yaml_file) parse_data! brick_data, store_ end |
#store_exists? ⇒ Boolean Also known as: store_exist?
14 15 16 |
# File 'lib/brick_and_mortar/config.rb', line 14 def store_exists? Dir.exist? @store end |