rabl_to_jbuilder 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 617f4327fba2952a1198f7a5f6da7563e840859d7094241638a014b13aac798f
4
- data.tar.gz: 76945dadc2159875f5e71339cf07de5dc6ca1e73a164f2c73fef453235571eb5
3
+ metadata.gz: 2369a1aebb6c39d44f7e12f5feb6b06ca02a9dc8ba66142ba37bf5f8e3bddf01
4
+ data.tar.gz: f9701978ae2c50e353cbb885f70efe39e107fc9cc7ae5714f6804f06fb8bff98
5
5
  SHA512:
6
- metadata.gz: a89b92c28f02f72b508eaa7f7047c997373353cc7ccad3f5bc0351ee2387cdcec312ee558fe68b19053b487e8ea1da64fb171feda96a7ae2c7ad7494332efe6f
7
- data.tar.gz: 05bf8926825b61535302f042f9435d5902923f0a76c2250d16fee47824eaf6517b410294cbb87ad1fc3f2060adc00bfb9754b91b0e5ef2213f7dedc375fcb7dd
6
+ metadata.gz: 750f9b435d9a8762ad25f8fa8436da15c00439e007b9024c9679c120c185f0904e213dbdb31804be3558e89f9565327accc3c6b088216e580cf42ec3f5ef4777
7
+ data.tar.gz: 64eb74fffe21094dbef3e20798ce4991de6f07ca350d10e10e1869e23b63053891f0636a0df158341e2f6bf4bc09ebc1f513d5f5a797110d3b5a3f4d70b67771
@@ -3,3 +3,4 @@
3
3
  $:.unshift(File.expand_path("../lib", __dir__))
4
4
 
5
5
  require 'rabl_to_jbuilder/cli'
6
+ RablToJbuilder::Cli.new(ARGV).run
@@ -1,4 +1,47 @@
1
1
  require 'rabl_to_jbuilder'
2
2
 
3
- puts RablToJbuilder.convert(ARGF.read)
3
+ module RablToJbuilder
4
+ class Cli
5
+ def initialize(argv)
6
+ @files = []
7
+ argv.each do |filename|
8
+ if File.file?(filename)
9
+ @files << filename
10
+ elsif File.directory?(filename)
11
+ @files.concat Dir[File.join(filename, "**/*.rabl")]
12
+ else
13
+ puts "Invalid filename #{filename}"
14
+ end
15
+ end
16
+ end
4
17
 
18
+ def run
19
+ @files.each do |filename|
20
+ begin
21
+ convert_file(filename)
22
+ rescue StandardError => e
23
+ puts e
24
+ puts e.backtrace
25
+ end
26
+ end
27
+ end
28
+
29
+ def convert_file(filename)
30
+ raise "Filenames must end in .rabl" unless filename.end_with?(".rabl")
31
+
32
+ # Guess at an object name
33
+ action_name = File.basename(filename)[/\A([^.]+)/, 1]
34
+ object_name_plural = File.basename(File.dirname(filename))
35
+ object_name_singular = object_name_plural.singularize
36
+
37
+ target = filename.gsub(/\.rabl$/, '.jbuilder')
38
+ puts "#{filename} => #{target}"
39
+
40
+ rabl = File.read(filename)
41
+ jbuilder = RablToJbuilder.convert(rabl, object: Sexp.s(:lvar, object_name_singular.to_sym))
42
+ #jbuilder = RablToJbuilder.convert(rabl)
43
+
44
+ File.write(target, jbuilder)
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module RablToJbuilder
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabl_to_jbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn