Class: Mint::Config
- Inherits:
-
Object
- Object
- Mint::Config
- Defined in:
- lib/mint/config.rb
Constant Summary collapse
- DEFAULT_STDIN_MODE =
false
- DEFAULT_VERBOSE =
false
- DEFAULT_LAYOUT_NAME =
"default"
- DEFAULT_STYLE_NAME =
"default"
- DEFAULT_STYLE_MODE =
:inline
- DEFAULT_OUTPUT_FILE_FORMAT =
'%{name}.%{ext}'
- DEFAULT_WORKING_DIRECTORY =
lambda { Pathname.getwd. }
- DEFAULT_DESTINATION_DIRECTORY =
lambda { Pathname.getwd. }
- DEFAULT_PRESERVE_STRUCTURE =
true
- DEFAULT_INSERT_TITLE_HEADING =
false
- DEFAULT_AUTODROP =
true
- DEFAULT_NAVIGATION =
false
- DEFAULT_NAVIGATION_DEPTH =
3
- DEFAULT_NAVIGATION_TITLE =
nil
Instance Attribute Summary collapse
-
#autodrop ⇒ Object
Returns the value of attribute autodrop.
-
#destination_directory ⇒ Object
Returns the value of attribute destination_directory.
-
#files ⇒ Object
Returns the value of attribute files.
-
#help ⇒ Object
Returns the value of attribute help.
-
#insert_title_heading ⇒ Object
Returns the value of attribute insert_title_heading.
-
#layout_name ⇒ Object
Returns the value of attribute layout_name.
-
#navigation ⇒ Object
Returns the value of attribute navigation.
-
#navigation_depth ⇒ Object
Returns the value of attribute navigation_depth.
-
#navigation_title ⇒ Object
Returns the value of attribute navigation_title.
-
#output_file_format ⇒ Object
Returns the value of attribute output_file_format.
-
#preserve_structure ⇒ Object
Returns the value of attribute preserve_structure.
-
#stdin_mode ⇒ Object
Returns the value of attribute stdin_mode.
-
#style_destination_directory ⇒ Object
Returns the value of attribute style_destination_directory.
-
#style_mode ⇒ Object
Returns the value of attribute style_mode.
-
#style_name ⇒ Object
Returns the value of attribute style_name.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
-
#working_directory ⇒ Object
This can’t be set by the user.
Class Method Summary collapse
- .defaults ⇒ Object
- .ensure_config(config) ⇒ Object
- .load_file(file) ⇒ Object
- .with_defaults(overrides = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #merge(config = Config.new) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mint/config.rb', line 38 def initialize( = {}) @stdin_mode = [:stdin_mode] if .key?(:stdin_mode) @help = [:help] @verbose = [:verbose] if .key?(:verbose) @layout_name = [:layout_name] || [:template_name] @style_name = [:style_name] || [:template_name] @style_mode = [:style_mode] @output_file_format = [:output_file_format] @working_directory = [:working_directory]&. @destination_directory = [:destination_directory] @style_destination_directory = [:style_destination_directory] @preserve_structure = [:preserve_structure] if .key?(:preserve_structure) @insert_title_heading = [:insert_title_heading] if .key?(:insert_title_heading) @autodrop = [:autodrop] if .key?(:autodrop) @navigation = [:navigation] if .key?(:navigation) @navigation_depth = [:navigation_depth] if .key?(:navigation_depth) @navigation_title = [:navigation_title] end |
Instance Attribute Details
#autodrop ⇒ Object
Returns the value of attribute autodrop.
18 19 20 |
# File 'lib/mint/config.rb', line 18 def autodrop @autodrop end |
#destination_directory ⇒ Object
Returns the value of attribute destination_directory.
14 15 16 |
# File 'lib/mint/config.rb', line 14 def destination_directory @destination_directory end |
#files ⇒ Object
Returns the value of attribute files.
5 6 7 |
# File 'lib/mint/config.rb', line 5 def files @files end |
#help ⇒ Object
Returns the value of attribute help.
7 8 9 |
# File 'lib/mint/config.rb', line 7 def help @help end |
#insert_title_heading ⇒ Object
Returns the value of attribute insert_title_heading.
17 18 19 |
# File 'lib/mint/config.rb', line 17 def insert_title_heading @insert_title_heading end |
#layout_name ⇒ Object
Returns the value of attribute layout_name.
9 10 11 |
# File 'lib/mint/config.rb', line 9 def layout_name @layout_name end |
#navigation ⇒ Object
Returns the value of attribute navigation.
19 20 21 |
# File 'lib/mint/config.rb', line 19 def @navigation end |
#navigation_depth ⇒ Object
Returns the value of attribute navigation_depth.
20 21 22 |
# File 'lib/mint/config.rb', line 20 def @navigation_depth end |
#navigation_title ⇒ Object
Returns the value of attribute navigation_title.
21 22 23 |
# File 'lib/mint/config.rb', line 21 def @navigation_title end |
#output_file_format ⇒ Object
Returns the value of attribute output_file_format.
12 13 14 |
# File 'lib/mint/config.rb', line 12 def output_file_format @output_file_format end |
#preserve_structure ⇒ Object
Returns the value of attribute preserve_structure.
16 17 18 |
# File 'lib/mint/config.rb', line 16 def preserve_structure @preserve_structure end |
#stdin_mode ⇒ Object
Returns the value of attribute stdin_mode.
6 7 8 |
# File 'lib/mint/config.rb', line 6 def stdin_mode @stdin_mode end |
#style_destination_directory ⇒ Object
Returns the value of attribute style_destination_directory.
15 16 17 |
# File 'lib/mint/config.rb', line 15 def style_destination_directory @style_destination_directory end |
#style_mode ⇒ Object
Returns the value of attribute style_mode.
11 12 13 |
# File 'lib/mint/config.rb', line 11 def style_mode @style_mode end |
#style_name ⇒ Object
Returns the value of attribute style_name.
10 11 12 |
# File 'lib/mint/config.rb', line 10 def style_name @style_name end |
#verbose ⇒ Object
Returns the value of attribute verbose.
8 9 10 |
# File 'lib/mint/config.rb', line 8 def verbose @verbose end |
#working_directory ⇒ Object
This can’t be set by the user
13 14 15 |
# File 'lib/mint/config.rb', line 13 def working_directory @working_directory end |
Class Method Details
.defaults ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/mint/config.rb', line 99 def self.defaults dest_dir = DEFAULT_DESTINATION_DIRECTORY.call Config.new({ stdin_mode: DEFAULT_STDIN_MODE, verbose: DEFAULT_VERBOSE, layout_name: DEFAULT_LAYOUT_NAME, style_name: DEFAULT_STYLE_NAME, style_mode: DEFAULT_STYLE_MODE, output_file_format: DEFAULT_OUTPUT_FILE_FORMAT, working_directory: DEFAULT_WORKING_DIRECTORY.call, destination_directory: dest_dir, style_destination_directory: Pathname.new('.'), preserve_structure: DEFAULT_PRESERVE_STRUCTURE, insert_title_heading: DEFAULT_INSERT_TITLE_HEADING, autodrop: DEFAULT_AUTODROP, navigation: DEFAULT_NAVIGATION, navigation_depth: DEFAULT_NAVIGATION_DEPTH, navigation_title: DEFAULT_NAVIGATION_TITLE }) end |
.ensure_config(config) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/mint/config.rb', line 82 def self.ensure_config(config) case config when Config config when Hash Config.new(config) else raise ArgumentError, "config must be a Config object or Hash" end end |
.load_file(file) ⇒ Object
93 94 95 96 97 |
# File 'lib/mint/config.rb', line 93 def self.load_file(file) toml_config = TOML.load_file(file) mapped_config = map_toml_keys_to_config(toml_config) if toml_config.is_a?(Hash) Config.new(mapped_config || {}) end |
.with_defaults(overrides = {}) ⇒ Object
120 121 122 |
# File 'lib/mint/config.rb', line 120 def self.with_defaults(overrides = {}) defaults.merge(new(overrides)) end |
Instance Method Details
#merge(config = Config.new) ⇒ Object
78 79 80 |
# File 'lib/mint/config.rb', line 78 def merge(config = Config.new) Config.new(to_h.merge(config.to_h.reject {|_, v| v.nil? })) end |
#to_h ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/mint/config.rb', line 57 def to_h { stdin_mode: @stdin_mode, help: @help, verbose: @verbose, layout_name: @layout_name, style_name: @style_name, style_mode: @style_mode, output_file_format: @output_file_format, working_directory: @working_directory, destination_directory: @destination_directory, style_destination_directory: @style_destination_directory, preserve_structure: @preserve_structure, insert_title_heading: @insert_title_heading, autodrop: @autodrop, navigation: @navigation, navigation_depth: @navigation_depth, navigation_title: @navigation_title } end |