Class: Twin::Config
- Inherits:
-
Object
- Object
- Twin::Config
- Defined in:
- lib/twin/config.rb
Constant Summary collapse
- DEFAULTS =
{ "global_excludes" => [".DS_Store"], "apex_theme" => nil, "apex_width" => nil, "apex_code_highlight" => nil, "apex_code_highlight_theme" => nil, }.freeze
Instance Attribute Summary collapse
-
#apex_code_highlight ⇒ Object
Returns the value of attribute apex_code_highlight.
-
#apex_code_highlight_theme ⇒ Object
Returns the value of attribute apex_code_highlight_theme.
-
#apex_theme ⇒ Object
Returns the value of attribute apex_theme.
-
#apex_width ⇒ Object
Returns the value of attribute apex_width.
-
#global_excludes ⇒ Object
Returns the value of attribute global_excludes.
-
#sync_dir ⇒ Object
Returns the value of attribute sync_dir.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ Config
constructor
A new instance of Config.
- #validate! ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ Config
Returns a new instance of Config.
18 19 20 21 22 23 24 25 26 |
# File 'lib/twin/config.rb', line 18 def initialize(data = {}) merged = DEFAULTS.merge(data || {}) @sync_dir = ENV["TWIN_SYNC_DIR"] || merged["sync_dir"].to_s @global_excludes = merged["global_excludes"] || [] @apex_theme = merged["apex_theme"] @apex_width = merged["apex_width"] @apex_code_highlight = merged["apex_code_highlight"] @apex_code_highlight_theme = merged["apex_code_highlight_theme"] end |
Instance Attribute Details
#apex_code_highlight ⇒ Object
Returns the value of attribute apex_code_highlight.
6 7 8 |
# File 'lib/twin/config.rb', line 6 def apex_code_highlight @apex_code_highlight end |
#apex_code_highlight_theme ⇒ Object
Returns the value of attribute apex_code_highlight_theme.
6 7 8 |
# File 'lib/twin/config.rb', line 6 def apex_code_highlight_theme @apex_code_highlight_theme end |
#apex_theme ⇒ Object
Returns the value of attribute apex_theme.
6 7 8 |
# File 'lib/twin/config.rb', line 6 def apex_theme @apex_theme end |
#apex_width ⇒ Object
Returns the value of attribute apex_width.
6 7 8 |
# File 'lib/twin/config.rb', line 6 def apex_width @apex_width end |
#global_excludes ⇒ Object
Returns the value of attribute global_excludes.
6 7 8 |
# File 'lib/twin/config.rb', line 6 def global_excludes @global_excludes end |
#sync_dir ⇒ Object
Returns the value of attribute sync_dir.
6 7 8 |
# File 'lib/twin/config.rb', line 6 def sync_dir @sync_dir end |
Class Method Details
.load ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/twin/config.rb', line 28 def self.load path = ENV["TWIN_CONFIG"] || File.join(Dir.home, ".config", "twin", "config.yaml") data = {} if File.exist?(path) begin data = YAML.safe_load_file(path) || {} rescue Psych::SyntaxError => e raise "config syntax error in #{path}: #{e.}" end end new(data) end |
Instance Method Details
#validate! ⇒ Object
41 42 43 44 |
# File 'lib/twin/config.rb', line 41 def validate! raise "sync_dir not set (add to ~/.config/twin/config.yaml or set TWIN_SYNC_DIR)" if sync_dir.empty? raise "sync_dir not found: #{sync_dir}" unless Dir.exist?(sync_dir) end |