lambchop 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dea62c77a6ac1568c61714754f3f6b1f43b875d4
4
- data.tar.gz: 7a2be55dbe9adbbe746c3cc53dbe9418cd8a1609
3
+ metadata.gz: d80c6e0852ad9d7a44e2743493bf9e8e53b30019
4
+ data.tar.gz: ce1a1e09d9368b679fa06cceae088ccd31735cac
5
5
  SHA512:
6
- metadata.gz: 464363eb0712671e815688fb67853102cdee49a4615c2c9a52607b4636463f8267b47a88316ad8e341bffb3ce49eddd66cdfcc0427c03dbd5c47f8199a33b505
7
- data.tar.gz: 6d912182b4202f0bc7fa1720f36403eb84b7170f16e33a94d5e01e6db6dd09e1b6b33eb0df1baae728a7d1f07f3aa5b832871cec301bb0af2272686f10e131c6
6
+ metadata.gz: eefc0526e495af489968d9056c12b4c833b443bc2abd61b1ac8d10644610d29d954ce135d5850fdd71aad3f7b939110dc500635a0182f3468d22249a4c9f66b0
7
+ data.tar.gz: 0b72a2732f81fb0162ecb87b360fc4cffbedbbdf00398c8ab85a8ecd8bacb5a23e5da3675f0f250dcec6185deff0e3f4ea15bf5bd1dad5ae563aef835da92b32
data/README.md CHANGED
@@ -35,6 +35,8 @@ timeout: 3 # default: 3
35
35
  memory_size: 128 # default: 128
36
36
  role: arn:aws:iam::NNNNNNNNNNNN:role/lambda_exec_role
37
37
  handler: test.handler
38
+ # Handler module name is filename.
39
+ # `handler:` is `index.handler` when filename is `index.js`
38
40
  */
39
41
  console.log('Loading event');
40
42
 
@@ -122,6 +124,29 @@ START RequestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
122
124
  └── node_modules/
123
125
  ```
124
126
 
127
+ # Diff
128
+ ```sh
129
+ $ lambchop-diff
130
+ usage: lambchop-cat <function-name> <file>
131
+
132
+ $ lambchop-diff test ./test.js
133
+ --- test:test.js
134
+ +++ ./test.js
135
+ @@ -1,11 +1,11 @@
136
+ var http = require('http');
137
+
138
+ exports.handler = function(event, context) {
139
+ - http.get('http://example.com/', function(res) {
140
+ + http.get('http://www.yahoo.com/', function(res) {
141
+ res.setEncoding('utf8');
142
+ res.on('data', function(str) {
143
+ console.log(str);
144
+ context.done();
145
+ });
146
+ });
147
+ };
148
+ ```
149
+
125
150
  ## Demo
126
151
 
127
152
  * https://asciinema.org/a/14158
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path("#{File.dirname __FILE__}/../lib")
3
+ require 'rubygems'
4
+ require 'lambchop'
5
+
6
+ if ARGV.length != 2
7
+ puts 'usage: lambchop-cat <function-name> <file>'
8
+ exit 1
9
+ end
10
+
11
+ open(ARGV[1]) do |f|
12
+ Lambchop::Diff.diff(ARGV[0], f)
13
+ end
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency 'aws-sdk-core', '~> 2.0.9'
23
23
  spec.add_dependency 'rubyzip', '>= 1.0.0'
24
+ spec.add_dependency 'diffy'
24
25
  spec.add_development_dependency 'bundler'
25
26
  spec.add_development_dependency 'rake'
26
27
  end
@@ -3,13 +3,16 @@ require 'open-uri'
3
3
  require 'yaml'
4
4
 
5
5
  require 'aws-sdk-core'
6
+ require 'diffy'
6
7
  require 'zip'
7
8
 
8
9
  module Lambchop; end
9
10
 
10
11
  require 'lambchop/cat'
11
12
  require 'lambchop/client'
13
+ require 'lambchop/diff'
12
14
  require 'lambchop/dump'
13
15
  require 'lambchop/tail'
16
+ require 'lambchop/utils'
14
17
  require 'lambchop/watch_dog'
15
18
  require 'lambchop/version'
@@ -11,8 +11,8 @@ class Lambchop::Client
11
11
  end
12
12
 
13
13
  def start
14
- src = remove_shebang(@source)
15
- config, src = parse_magic_comment(src)
14
+ src = Lambchop::Utils.remove_shebang(@source)
15
+ config, src = Lambchop::Utils.parse_magic_comment(src)
16
16
 
17
17
  config['function_name'] ||= File.basename(@path, '.js')
18
18
  function_name = config['function_name']
@@ -60,24 +60,4 @@ class Lambchop::Client
60
60
  end
61
61
  end
62
62
  end
63
-
64
- def remove_shebang(src)
65
- src.sub(/\A#![^\n]*\n/, '')
66
- end
67
-
68
- def parse_magic_comment(src)
69
- ss = StringScanner.new(src)
70
-
71
- unless ss.scan(%r|\A\s*/\*|)
72
- raise 'Cannot find magic comment'
73
- end
74
-
75
- unless comment = ss.scan_until(%r|\*/|)
76
- raise 'Cannot find magic comment'
77
- end
78
-
79
- comment.sub!(%r|\*/\z|, '')
80
-
81
- [YAML.load(comment), ss.rest.sub(/\A\n/, '')]
82
- end
83
63
  end
@@ -0,0 +1,33 @@
1
+ class Lambchop::Diff
2
+ def self.diff(function_name, file, options = {})
3
+ self.new(function_name, file, options).diff
4
+ end
5
+
6
+ def initialize(function_name, file, options = {})
7
+ @function_name = function_name
8
+ @file = file
9
+ @client = options[:client] || Aws::Lambda::Client.new
10
+ @out = options[:out] || $stdout
11
+ @options = options
12
+ end
13
+
14
+ def diff
15
+ file = @file
16
+
17
+ if file.kind_of?(IO)
18
+ file = file.read
19
+ end
20
+
21
+ file = Lambchop::Utils.remove_shebang(file)
22
+ config, file = Lambchop::Utils.parse_magic_comment(file)
23
+
24
+ page = @client.get_function(:function_name => @function_name).first
25
+
26
+ Lambchop::Utils.open_source(page.code.location) do |name, func|
27
+ @out.puts("--- #{@function_name}:#{name}")
28
+ @out.puts("+++ #{@file.path}")
29
+ diff = Diffy::Diff.new(func, file, :include_diff_info => true).to_s
30
+ @out.puts(diff.each_line.to_a.slice(2..-1).join)
31
+ end
32
+ end
33
+ end
@@ -42,12 +42,9 @@ class Lambchop::Dump
42
42
  end
43
43
 
44
44
  def puts_source(location)
45
- open(location) do |f|
46
- Zip::InputStream.open(f) do |zis|
47
- while entry = zis.get_next_entry
48
- @out.puts(entry.get_input_stream.read)
49
- end
50
- end
45
+ Lambchop::Utils.open_source(location) do |name, src|
46
+ @out.puts("// #{name}")
47
+ @out.puts(src)
51
48
  end
52
49
  end
53
50
  end
@@ -0,0 +1,34 @@
1
+ class Lambchop::Utils
2
+ class << self
3
+ def remove_shebang(src)
4
+ src.sub(/\A#![^\n]*\n/, '')
5
+ end
6
+
7
+ def parse_magic_comment(src)
8
+ ss = StringScanner.new(src)
9
+
10
+ unless ss.scan(%r|\A\s*/\*|)
11
+ raise 'Cannot find magic comment'
12
+ end
13
+
14
+ unless comment = ss.scan_until(%r|\*/|)
15
+ raise 'Cannot find magic comment'
16
+ end
17
+
18
+ comment.sub!(%r|\*/\z|, '')
19
+
20
+ [YAML.load(comment), ss.rest.sub(/\A\n/, '')]
21
+ end
22
+
23
+ def open_source(location)
24
+ open(location) do |f|
25
+ Zip::InputStream.open(f) do |zis|
26
+ while entry = zis.get_next_entry
27
+ next if entry.name =~ %r|\Anode_modules/|
28
+ yield(entry.name, entry.get_input_stream.read)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end # of class methods
34
+ end
@@ -1,3 +1,3 @@
1
1
  module Lambchop
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lambchop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: diffy
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -73,6 +87,7 @@ email:
73
87
  executables:
74
88
  - lambchop
75
89
  - lambchop-cat
90
+ - lambchop-diff
76
91
  - lambchop-dump
77
92
  - lambchop-tail
78
93
  extensions: []
@@ -85,14 +100,17 @@ files:
85
100
  - Rakefile
86
101
  - bin/lambchop
87
102
  - bin/lambchop-cat
103
+ - bin/lambchop-diff
88
104
  - bin/lambchop-dump
89
105
  - bin/lambchop-tail
90
106
  - lambchop.gemspec
91
107
  - lib/lambchop.rb
92
108
  - lib/lambchop/cat.rb
93
109
  - lib/lambchop/client.rb
110
+ - lib/lambchop/diff.rb
94
111
  - lib/lambchop/dump.rb
95
112
  - lib/lambchop/tail.rb
113
+ - lib/lambchop/utils.rb
96
114
  - lib/lambchop/version.rb
97
115
  - lib/lambchop/watch_dog.rb
98
116
  homepage: https://github.com/winebarrel/lambchop