Module: Simple::Httpd::Helpers
Instance Method Summary collapse
-
#instance_eval_paths(obj, *paths) ⇒ Object
instance_eval zero or more paths in the context of obj.
- #shorten_path(path) ⇒ Object
-
#subclass(klass, description: nil) ⇒ Object
subclass a klass with an optional description.
- #underscore(str) ⇒ Object
Instance Method Details
#instance_eval_paths(obj, *paths) ⇒ Object
instance_eval zero or more paths in the context of obj
40 41 42 43 44 45 46 |
# File 'lib/simple/httpd/helpers.rb', line 40 def instance_eval_paths(obj, *paths) paths.each do |path| # STDERR.puts "Loading #{path}" obj.instance_eval File.read(path), path, 1 end obj end |
#shorten_path(path) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/simple/httpd/helpers.rb', line 16 def shorten_path(path) path = File.absolute_path(path) if path.start_with?(pwd) path = path[pwd.length..-1] path = File.join("./", path) if path =~ /\// end if path.start_with?(home) path = File.join("~/", path[home.length..-1]) end path end |
#subclass(klass, description: nil) ⇒ Object
subclass a klass with an optional description
49 50 51 52 53 |
# File 'lib/simple/httpd/helpers.rb', line 49 def subclass(klass, description: nil) subclass = Class.new(klass) subclass.define_method(:inspect) { description } if description subclass end |
#underscore(str) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/simple/httpd/helpers.rb', line 31 def underscore(str) parts = str.split("::") parts = parts.map do |part| part.gsub(/[A-Z]+/) { |ch| "_#{ch.downcase}" }.gsub(/^_/, "") end parts.join("/") end |