Class: Lambchop::Utils
- Inherits:
-
Object
- Object
- Lambchop::Utils
- Defined in:
- lib/lambchop/utils.rb
Class Method Summary collapse
- .camelize(obj) ⇒ Object
- .debug? ⇒ Boolean
- .open_source(location) ⇒ Object
- .parse_magic_comment(src) ⇒ Object
- .remove_shebang(src) ⇒ Object
- .with_error_logging ⇒ Object
Class Method Details
.camelize(obj) ⇒ Object
46 47 48 |
# File 'lib/lambchop/utils.rb', line 46 def camelize(obj) obj.to_s.gsub(/(?:\A|_)([a-z])/) { $1.upcase } end |
.debug? ⇒ Boolean
50 51 52 |
# File 'lib/lambchop/utils.rb', line 50 def debug? ENV['DEBUG'] == '1' end |
.open_source(location) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lambchop/utils.rb', line 23 def open_source(location) open(location) do |f| Zip::InputStream.open(f) do |zis| while entry = zis.get_next_entry next if entry.name =~ %r|\Anode_modules/| yield(entry.name, entry.get_input_stream.read) end end end end |
.parse_magic_comment(src) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lambchop/utils.rb', line 7 def parse_magic_comment(src) ss = StringScanner.new(src) unless ss.scan(%r|\A\s*/\*|) raise 'Cannot find magic comment' end unless comment = ss.scan_until(%r|\*/|) raise 'Cannot find magic comment' end comment.sub!(%r|\*/\z|, '') [YAML.load(comment), ss.rest.sub(/\A\n/, '')] end |
.remove_shebang(src) ⇒ Object
3 4 5 |
# File 'lib/lambchop/utils.rb', line 3 def remove_shebang(src) src.sub(/\A#![^\n]*\n/, '') end |
.with_error_logging ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lambchop/utils.rb', line 34 def with_error_logging begin yield rescue => e if debug? raise e else $stdout.puts("[ERROR] #{e.}") end end end |