restkit-generate 0.1.1 → 0.1.2
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.
- data/bin/restkit-generate +14 -3
- data/lib/generator/common.rb +14 -14
- data/lib/generator/header.rb +1 -4
- data/lib/generator/mk.rb +4 -7
- metadata +3 -3
data/bin/restkit-generate
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
THIS_FILE = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
|
|
4
|
+
lib = File.expand_path(File.dirname(THIS_FILE) + '/../lib')
|
|
4
5
|
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
|
5
6
|
|
|
6
7
|
require 'optparse'
|
|
@@ -10,14 +11,19 @@ options = {}
|
|
|
10
11
|
|
|
11
12
|
optparse = OptionParser.new do |opts|
|
|
12
13
|
opts.banner = "Usage: restkit-generate model NAME [field:type field:type] [options]"
|
|
13
|
-
|
|
14
|
+
|
|
14
15
|
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
|
15
16
|
options[:verbose] = v
|
|
16
17
|
end
|
|
17
|
-
|
|
18
|
+
|
|
18
19
|
opts.on("-p prefix", "--[no-]prefix", "Prefix, default: Base") do |p|
|
|
19
20
|
options[:prefix] = p
|
|
20
21
|
end
|
|
22
|
+
|
|
23
|
+
opts.on( '-h', '--help', 'Display this screen' ) do
|
|
24
|
+
puts opts
|
|
25
|
+
exit
|
|
26
|
+
end
|
|
21
27
|
end
|
|
22
28
|
|
|
23
29
|
begin
|
|
@@ -27,6 +33,11 @@ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
|
|
27
33
|
exit
|
|
28
34
|
end
|
|
29
35
|
|
|
36
|
+
if ARGV.empty?
|
|
37
|
+
puts optparse
|
|
38
|
+
exit
|
|
39
|
+
end
|
|
40
|
+
|
|
30
41
|
Generator.configure(options)
|
|
31
42
|
|
|
32
43
|
begin
|
data/lib/generator/common.rb
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
1
|
module Generator
|
|
2
2
|
@@config = {}
|
|
3
3
|
@@properties = {}
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
def self.configure(options)
|
|
6
6
|
@@config = options
|
|
7
7
|
if options[:prefix].nil?
|
|
8
|
-
|
|
8
|
+
@@config[:prefix] = "Base"
|
|
9
9
|
else
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
if !options[:prefix]
|
|
11
|
+
@@config[:prefix] = ""
|
|
12
|
+
end
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
def self.config
|
|
17
17
|
@@config
|
|
18
18
|
end
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
def self.properties
|
|
21
21
|
@@properties
|
|
22
22
|
end
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
def self.validate!
|
|
25
25
|
type = ARGV[0]
|
|
26
26
|
if type != "model"
|
|
27
|
-
raise ArgumentError, "Unknown type '#{type}'.", caller
|
|
27
|
+
raise ArgumentError, "Unknown type '#{type}'.\nRun restkit-generate --help for more information.", caller
|
|
28
28
|
end
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
@@config[:model_name] = ARGV[1]
|
|
31
31
|
if @@config[:model_name].nil?
|
|
32
32
|
raise ArgumentError, "Model name can't be empty.", caller
|
|
33
33
|
end
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
ARGV.shift(2)
|
|
36
36
|
if ARGV.nil?
|
|
37
37
|
raise ArgumentError, "No input parameters defined.", caller
|
|
38
38
|
end
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
ARGV.each do |arg|
|
|
41
41
|
original_name = arg.split(":")[0]
|
|
42
42
|
a = arg.gsub(/_([a-z])/) do |word|
|
|
43
43
|
word.gsub(/_/, "").capitalize
|
|
44
44
|
end
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
name = a.split(":")[0]
|
|
47
47
|
name = @@config[:model_name].downcase+"Id" if name == "id"
|
|
48
48
|
type = a.split(":")[1]
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
@@properties[name] = {:type => type, :original_name => original_name}
|
|
51
51
|
end
|
|
52
52
|
end
|
data/lib/generator/header.rb
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
module Generator
|
|
2
|
-
|
|
3
2
|
module Header
|
|
4
|
-
|
|
5
3
|
def self.make
|
|
6
4
|
props = []
|
|
7
5
|
model_name = Generator.config[:model_name]
|
|
@@ -11,6 +9,7 @@ module Generator
|
|
|
11
9
|
header =
|
|
12
10
|
"//\n"+
|
|
13
11
|
"// #{prefix}#{model_name}.h\n"+
|
|
12
|
+
"// Command: #{$0} model #{model_name} #{ARGV.join( ' ' )}\n"+
|
|
14
13
|
"//\n\n"+
|
|
15
14
|
"#import <Foundation/Foundation.h>\n"+
|
|
16
15
|
"#import <RestKit/RestKit.h>\n\n"+
|
|
@@ -25,7 +24,5 @@ module Generator
|
|
|
25
24
|
|
|
26
25
|
File.open("#{prefix}#{model_name}.h", 'w') {|f| f.write(header) }
|
|
27
26
|
end
|
|
28
|
-
|
|
29
27
|
end
|
|
30
|
-
|
|
31
28
|
end
|
data/lib/generator/mk.rb
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
module Generator
|
|
2
|
-
|
|
3
2
|
module MakeFile
|
|
4
|
-
|
|
5
3
|
def self.make
|
|
6
4
|
model_name = Generator.config[:model_name]
|
|
7
5
|
prefix = Generator.config[:prefix]
|
|
@@ -19,7 +17,7 @@ module Generator
|
|
|
19
17
|
"// #{prefix}#{model_name}.m\n"+
|
|
20
18
|
"//\n\n"+
|
|
21
19
|
|
|
22
|
-
"#import \"#{prefix}#{model_name}.h\n\n"+
|
|
20
|
+
"#import \"#{prefix}#{model_name}.h\"\n\n"+
|
|
23
21
|
"@implementation #{prefix}#{model_name}\n\n"+
|
|
24
22
|
"@synthesize "+synthesize.join(", ")+";\n\n"+
|
|
25
23
|
"+ (RKObjectMapping *)objectMapping\n"+
|
|
@@ -27,11 +25,12 @@ module Generator
|
|
|
27
25
|
" RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[self class]];\n"+
|
|
28
26
|
" [mapping mapKeyPathsToAttributes:\n"+
|
|
29
27
|
mapping.join(",\n")+", nil];\n"+
|
|
28
|
+
" return mapping;\n"+
|
|
30
29
|
"}\n\n"+
|
|
31
30
|
|
|
32
31
|
"- (id)initWithCoder:(NSCoder *)coder\n"+
|
|
33
32
|
"{\n"+
|
|
34
|
-
" self = [[
|
|
33
|
+
" self = [[[self class] alloc] init];\n"+
|
|
35
34
|
" if (self) {\n"+
|
|
36
35
|
encoders.join("\n")+"\n"+
|
|
37
36
|
" }\n"+
|
|
@@ -51,7 +50,5 @@ module Generator
|
|
|
51
50
|
|
|
52
51
|
File.open("#{prefix}#{model_name}.m", 'w') {|f| f.write(source) }
|
|
53
52
|
end
|
|
54
|
-
|
|
55
53
|
end
|
|
56
|
-
|
|
57
|
-
end
|
|
54
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: restkit-generate
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-
|
|
12
|
+
date: 2012-07-26 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description: A model generator for iOS RestKit (Rails-like), ARC compliant
|
|
15
15
|
email: romefimov@gmail.com
|
|
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
44
44
|
version: '0'
|
|
45
45
|
requirements: []
|
|
46
46
|
rubyforge_project:
|
|
47
|
-
rubygems_version: 1.8.
|
|
47
|
+
rubygems_version: 1.8.24
|
|
48
48
|
signing_key:
|
|
49
49
|
specification_version: 3
|
|
50
50
|
summary: A model generator for iOS RestKit (Rails-like), ARC compliant
|