Module: Betterdocs::Global
- Extended by:
- ComplexConfig::Provider::Shortcuts, Tins::DSLAccessor
- Defined in:
- lib/betterdocs/global.rb
Class Method Summary collapse
- .actions ⇒ Object
- .all_docs ⇒ Object
- .api_base_url ⇒ Object
- .api_url(url = nil) ⇒ Object
- .api_url_options ⇒ Object
-
.asset(path, to: :root) ⇒ Object
Defines an asset for the file at
path
. - .asset_url(url = nil) ⇒ Object
- .assets(hash = nil) ⇒ Object
- .assets=(hash) ⇒ Object
- .config ⇒ Object
- .configuration_file ⇒ Object
- .configure(config = configuration_file, &block) ⇒ Object
- .configure_via_yaml(config) ⇒ Object
- .default_sanitize(code = nil) ⇒ Object
-
.each_asset ⇒ Object
Maps the assets original source path to its destination path in the output by yielding to every asset’s source/destination pair.
- .each_swagger_asset ⇒ Object
- .platform_url(url = nil) ⇒ Object
- .section(name) ⇒ Object
- .sections ⇒ Object
- .sections_clear ⇒ Object
- .swagger_asset(path, to: :root) ⇒ Object
- .swagger_assets(hash = nil) ⇒ Object
- .swagger_assets=(hash) ⇒ Object
- .url_for(options = {}) ⇒ Object
- .url_helpers ⇒ Object
Class Method Details
.actions ⇒ Object
200 201 202 |
# File 'lib/betterdocs/global.rb', line 200 def actions all_docs.reduce([]) { |a, d| a.concat(d.actions) } end |
.all_docs ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/betterdocs/global.rb', line 180 def all_docs Dir.chdir controllers_dir do Dir["#{api_prefix}/**/*_controller.rb"].each_with_object([]) do |cf, all| controller_name = cf.sub(/\.rb$/, '').camelcase controller = begin controller_name.constantize rescue NameError => e STDERR.puts "Skipping #{cf.inspect}, #{e.class}: #{e}" next end if docs = controller.ask_and_send(:docs) all << docs else STDERR.puts "Skipping #{cf.inspect}, #{controller_name.inspect} doesn't respond to :docs method" end end end end |
.api_base_url ⇒ Object
60 61 62 |
# File 'lib/betterdocs/global.rb', line 60 def api_base_url "#{api_protocol}://#{api_host}/#{api_prefix}" end |
.api_url(url = nil) ⇒ Object
46 47 48 |
# File 'lib/betterdocs/global.rb', line 46 def api_url(url = nil) handle_url(:api, url) end |
.api_url_options ⇒ Object
64 65 66 |
# File 'lib/betterdocs/global.rb', line 64 def { protocol: api_protocol, host: api_host, format: api_default_format } end |
.asset(path, to: :root) ⇒ Object
Defines an asset for the file at path
. If to
was given it will be copied to this path (it includes the basename) below templates_directory
in the output, otherwise it will be copied directly to templates_directory
.
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/betterdocs/global.rb', line 109 def asset(path, to: :root) @assets ||= {} if destination = to.ask_and_send(:to_str) @assets[path.to_s] = destination elsif to == :root @assets[path.to_s] = to else raise ArgumentError, 'keyword argument to needs to be a string or :root' end end |
.asset_url(url = nil) ⇒ Object
54 55 56 |
# File 'lib/betterdocs/global.rb', line 54 def asset_url(url = nil) handle_url(:asset, url) end |
.assets(hash = nil) ⇒ Object
88 89 90 91 92 |
# File 'lib/betterdocs/global.rb', line 88 def assets(hash = nil) @assets ||= {} hash&.each { |path, to| asset path, to: to } @assets end |
.assets=(hash) ⇒ Object
83 84 85 86 |
# File 'lib/betterdocs/global.rb', line 83 def assets=(hash) @assets&.clear assets(hash) end |
.config ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/betterdocs/global.rb', line 172 def config if block_given? yield self else self end end |
.configuration_file ⇒ Object
155 156 157 158 |
# File 'lib/betterdocs/global.rb', line 155 def configuration_file cc.betterdocs rescue ComplexConfig::ConfigurationFileMissing end |
.configure(config = configuration_file, &block) ⇒ Object
166 167 168 169 170 |
# File 'lib/betterdocs/global.rb', line 166 def configure(config = configuration_file, &block) config and configure_via_yaml(config) block and instance_eval(&block) self end |
.configure_via_yaml(config) ⇒ Object
160 161 162 163 164 |
# File 'lib/betterdocs/global.rb', line 160 def configure_via_yaml(config) config.each do |name, value| __send__(name, value.dup) end end |
.default_sanitize(code = nil) ⇒ Object
78 79 80 81 |
# File 'lib/betterdocs/global.rb', line 78 def default_sanitize(code = nil) code and @default_sanitize = eval(code) @default_sanitize end |
.each_asset ⇒ Object
Maps the assets original source path to its destination path in the output by yielding to every asset’s source/destination pair.
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/betterdocs/global.rb', line 133 def each_asset assets.each do |(path, destination)| path = path.to_s if destination == :root yield path, File.join(output_directory.to_s, File.basename(path)) else yield path, File.join(output_directory.to_s, destination.to_str) end end end |
.each_swagger_asset ⇒ Object
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/betterdocs/global.rb', line 144 def each_swagger_asset swagger_assets.each do |(path, destination)| path = path.to_s if destination == :root yield path, File.join(swagger_output_directory.to_s, File.basename(path)) else yield path, File.join(swagger_output_directory.to_s, destination.to_str) end end end |
.platform_url(url = nil) ⇒ Object
34 35 36 |
# File 'lib/betterdocs/global.rb', line 34 def platform_url(url = nil) handle_url(:platform, url) end |
.section(name) ⇒ Object
220 221 222 |
# File 'lib/betterdocs/global.rb', line 220 def section(name) sections[name] if sections.key?(name) end |
.sections ⇒ Object
204 205 206 207 208 209 210 211 212 213 |
# File 'lib/betterdocs/global.rb', line 204 def sections @sections and return @sections Dir.chdir controllers_dir do actions.each_with_object(@sections = {}) do |action, sections| sections[action.section] ||= Section.new(action.section) sections[action.section] << action end end @sections.freeze end |
.sections_clear ⇒ Object
215 216 217 218 |
# File 'lib/betterdocs/global.rb', line 215 def sections_clear @sections = nil self end |
.swagger_asset(path, to: :root) ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/betterdocs/global.rb', line 120 def swagger_asset(path, to: :root) @swagger_assets ||= {} if destination = to.ask_and_send(:to_str) @swagger_assets[path.to_s] = destination elsif to == :root @swagger_assets[path.to_s] = to else raise ArgumentError, 'keyword argument to needs to be a string or :root' end end |
.swagger_assets(hash = nil) ⇒ Object
99 100 101 102 103 |
# File 'lib/betterdocs/global.rb', line 99 def swagger_assets(hash = nil) @swagger_assets ||= {} hash&.each { |path, to| swagger_asset path, to: to } @swagger_assets end |
.swagger_assets=(hash) ⇒ Object
94 95 96 97 |
# File 'lib/betterdocs/global.rb', line 94 def swagger_assets=(hash) @swagger_assets&.clear swagger_assets(hash) end |
.url_for(options = {}) ⇒ Object
228 229 230 231 232 |
# File 'lib/betterdocs/global.rb', line 228 def url_for( = {}) Betterdocs.rails.application.routes.url_for( | Betterdocs::Global.config. ) end |
.url_helpers ⇒ Object
224 225 226 |
# File 'lib/betterdocs/global.rb', line 224 def url_helpers Betterdocs.rails.application.routes.url_helpers end |