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 +4 -4
- data/exe/rabl_to_jbuilder +1 -0
- data/lib/rabl_to_jbuilder/cli.rb +44 -1
- data/lib/rabl_to_jbuilder/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2369a1aebb6c39d44f7e12f5feb6b06ca02a9dc8ba66142ba37bf5f8e3bddf01
|
4
|
+
data.tar.gz: f9701978ae2c50e353cbb885f70efe39e107fc9cc7ae5714f6804f06fb8bff98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 750f9b435d9a8762ad25f8fa8436da15c00439e007b9024c9679c120c185f0904e213dbdb31804be3558e89f9565327accc3c6b088216e580cf42ec3f5ef4777
|
7
|
+
data.tar.gz: 64eb74fffe21094dbef3e20798ce4991de6f07ca350d10e10e1869e23b63053891f0636a0df158341e2f6bf4bc09ebc1f513d5f5a797110d3b5a3f4d70b67771
|
data/exe/rabl_to_jbuilder
CHANGED
data/lib/rabl_to_jbuilder/cli.rb
CHANGED
@@ -1,4 +1,47 @@
|
|
1
1
|
require 'rabl_to_jbuilder'
|
2
2
|
|
3
|
-
|
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
|