Class: Mkwebook::Config
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Mkwebook::Config
- Defined in:
- lib/mkwebook/config.rb
Instance Attribute Summary collapse
-
#cli_options ⇒ Object
Returns the value of attribute cli_options.
-
#config ⇒ Object
Returns the value of attribute config.
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
- #authentication? ⇒ Boolean
- #concurrent? ⇒ Boolean
- #find_mkwebook_yaml ⇒ Object
- #force_single_threaded? ⇒ Boolean
-
#initialize(cli_options = {}) ⇒ Config
constructor
A new instance of Config.
- #load(config_file) ⇒ Object
Constructor Details
#initialize(cli_options = {}) ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mkwebook/config.rb', line 8 def initialize( = {}) super(nil) @cli_options = @file = find_mkwebook_yaml if @file && File.exist?(@file) @config = load(@file) __setobj__(@config) else __setobj__({}) end end |
Instance Attribute Details
#cli_options ⇒ Object
Returns the value of attribute cli_options.
6 7 8 |
# File 'lib/mkwebook/config.rb', line 6 def @cli_options end |
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/mkwebook/config.rb', line 6 def config @config end |
#file ⇒ Object
Returns the value of attribute file.
6 7 8 |
# File 'lib/mkwebook/config.rb', line 6 def file @file end |
Instance Method Details
#authentication? ⇒ Boolean
39 40 41 |
# File 'lib/mkwebook/config.rb', line 39 def authentication? config.dig(:authentication, :cookies).present? || config.dig(:authentication, :local_storage).present? end |
#concurrent? ⇒ Boolean
35 36 37 |
# File 'lib/mkwebook/config.rb', line 35 def concurrent? config[:concurrency].present? end |
#find_mkwebook_yaml ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mkwebook/config.rb', line 43 def find_mkwebook_yaml dir = Dir.pwd while dir != '/' file = File.join(dir, 'mkwebook.yaml') return file if File.exist?(file) file = File.join(dir, 'mkwebook.yml') return file if File.exist?(file) dir = File.dirname(dir) end end |
#force_single_threaded? ⇒ Boolean
56 57 58 |
# File 'lib/mkwebook/config.rb', line 56 def force_single_threaded? @cli_options[:pause] || @cli_options[:pause_on_error] || @cli_options[:single_thread] end |
#load(config_file) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mkwebook/config.rb', line 20 def load(config_file) default_config = { 'browser' => { 'headless' => true, }, 'concurrency': 1, 'max-recursion': 1 } config = YAML.load_file(config_file) config = default_config.deep_merge(config).deep_transform_keys! { |k| k.to_s.underscore.to_sym } config[:concurrency] = 1 if force_single_threaded? config[:browser][:headless] = false if @cli_options[:headmode] config end |