Class: Bookbinder::Config::Checkers::ProductsChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/bookbinder/config/checkers/products_checker.rb

Constant Summary collapse

MissingRequiredKeyError =
Class.new(RuntimeError)
MissingProductsKeyError =
Class.new(RuntimeError)
MissingProductIdError =
Class.new(RuntimeError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



23
24
25
# File 'lib/bookbinder/config/checkers/products_checker.rb', line 23

def config
  @config
end

Instance Method Details

#check(config) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bookbinder/config/checkers/products_checker.rb', line 9

def check(config)
  @config = config

  if section_product_ids.count > 0
    if config.products.empty?
       MissingProductsKeyError.new('You must specify at least one product under the products key in config.yml')
    elsif missing_products.count != 0
      MissingProductIdError.new("Your config.yml is missing required product id under the products key. Required product ids are #{missing_products.join(", ")}.")
    elsif invalid_products.any?
      MissingRequiredKeyError.new("Your config.yml is missing required key(s) for products #{invalid_product_ids}. Required keys are #{required_product_keys.join(", ")}.")
    end
  end
end