lanekit 0.1.7 → 0.2.0
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 +8 -8
- data/README.md +11 -1
- data/lib/lanekit/version.rb +1 -1
- data/lib/lanekit.rb +46 -4
- data/lib/template/model.h.erb +9 -6
- data/lib/template/model.m.erb +33 -4
- data/lib/template/model_fixture.json.erb +5 -0
- data/lib/template/model_fixture.m.erb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
M2ZkNjM1Yjk4OGNhNGQ2OWNhNTM1ZDY4Y2FhZGY1ZDE4ZThjMDA2YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDNhY2RiNDIwMzk5ZWY5NzBlMDM4ODgxNjlhMDAxM2MyYzg0NWZhZQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NGVhOWRlMjg2YTNiMTQ3NDZiYzU5NGE3MDUzNmIwNzRlMTMxYTViM2E3YjM1
|
10
|
+
ZGUxOTA5YjRhNWMxMmY3ZjBlZWFiMDkyYmI0NjQ3YTk5ZmEzZGJhODAwMDcx
|
11
|
+
ZDI0OWVlMmIwOGQzMzJkM2U2ZWYyMTAxODRiYTE2NWY0YmVhMmQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2FkYmExMzRhZmQ4OTJhMjY4NmE0YTFkYzYxNmE2NGUwNmMyZGY2YWFkZGJh
|
14
|
+
NjVhODE3YTc4Y2E3M2M1MmRlNmRkNTFhMmI1Y2RiMTZmZjM0OTkzMTliYWE4
|
15
|
+
ZDk4YzJiOWY5NWQ0ZjUwZWQ3YmQ0MTMwOGM1OTdmNjRhMGVlNTE=
|
data/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
## LaneKit
|
2
2
|
|
3
|
-
|
4
3
|
LaneKit is a code generator for iOS Objective-C models for integration with RestKit. It includes support
|
5
4
|
for unit testing with SenTestingKit including fixtures and tests. LaneKit is a command line app written
|
6
5
|
in Ruby and packaged as a Ruby Gem.
|
@@ -8,6 +7,17 @@ in Ruby and packaged as a Ruby Gem.
|
|
8
7
|
- [Source code for LaneKit](https://github.com/LarryAasen/LaneKit/zipball/master) from [GitHub](http://github.com).
|
9
8
|
- Questions? [Stack Overflow](http://stackoverflow.com/questions/tagged/lanekit) is the best place to find answers.
|
10
9
|
|
10
|
+
## Benefits
|
11
|
+
* properly implemented models
|
12
|
+
* consistent Objective-C code
|
13
|
+
* unit tests
|
14
|
+
* test fixtures in JSON and Objective-C
|
15
|
+
* tested code
|
16
|
+
* rapid development
|
17
|
+
* easy integration with RestKit
|
18
|
+
* enhanced productivity of junior developers
|
19
|
+
* reduces dependency on senior developers
|
20
|
+
|
11
21
|
## How To Get Started
|
12
22
|
|
13
23
|
1. Install the LaneKit Ruby Gem from RubyGems.org
|
data/lib/lanekit/version.rb
CHANGED
data/lib/lanekit.rb
CHANGED
@@ -50,6 +50,23 @@ module LaneKit
|
|
50
50
|
type
|
51
51
|
end
|
52
52
|
|
53
|
+
def self.objective_c_type_fixture_json(type_name)
|
54
|
+
if type_name == "array"
|
55
|
+
value = "[]"
|
56
|
+
elsif type_name == "date"
|
57
|
+
value = "03/01/2012"
|
58
|
+
elsif type_name == "integer"
|
59
|
+
value = "1"
|
60
|
+
elsif type_name == "string"
|
61
|
+
value = "MyString"
|
62
|
+
elsif type_name
|
63
|
+
value = ""
|
64
|
+
else
|
65
|
+
value = ""
|
66
|
+
end
|
67
|
+
value
|
68
|
+
end
|
69
|
+
|
53
70
|
def self.objective_c_type_fixture_value(type_name)
|
54
71
|
if type_name == "array"
|
55
72
|
value = "@[]"
|
@@ -89,8 +106,19 @@ module LaneKit
|
|
89
106
|
class Generate < Thor
|
90
107
|
include Thor::Actions
|
91
108
|
|
92
|
-
desc "model
|
109
|
+
desc "model NAME [attributes]", "Generates an Objective-C model for RestKit including unit tests"
|
110
|
+
long_desc <<-LONGDESC
|
111
|
+
Generates the Objective-C code for a model that is compatible with RestKit. It also generates test fixtures and unit tests.\n
|
112
|
+
NAME: the name of the model\n
|
113
|
+
[attributes] name:type:relationship, name:type:relationship, ...\n
|
114
|
+
where type is [date|integer|string|<class_name>] and relationship (optional) is the name of another class.
|
115
|
+
LONGDESC
|
116
|
+
|
117
|
+
option :use_core_data, :type => :boolean, :default => false, :banner => "generate code compatible with Core Data", :aliases => :c # option --use_core_data=true
|
93
118
|
def model(model_name, *attributes)
|
119
|
+
@using_core_data = options[:use_core_data]
|
120
|
+
puts " using Core Data: #{@using_core_data}"
|
121
|
+
|
94
122
|
@model_name = LaneKit.derive_model_name(model_name)
|
95
123
|
|
96
124
|
@model_file_name = LaneKit.derive_file_name(@model_name)
|
@@ -112,6 +140,7 @@ module LaneKit
|
|
112
140
|
:objective_c_type => objective_c_type,
|
113
141
|
:relationship => relationship,
|
114
142
|
:relationship_fixtures_file_name => "#{relationship}Fixtures",
|
143
|
+
:fixture_json => LaneKit.objective_c_type_fixture_json(type),
|
115
144
|
:fixture_value => LaneKit.objective_c_type_fixture_value(type),
|
116
145
|
:unit_test_assert => LaneKit.objective_c_type_unit_test_assert(@model_name, name, type)
|
117
146
|
}
|
@@ -142,7 +171,6 @@ module LaneKit
|
|
142
171
|
@tests_models_folder = "Classes/Tests/Models"
|
143
172
|
|
144
173
|
@template_folder = File.expand_path('../template', __FILE__)
|
145
|
-
@using_core_data = false
|
146
174
|
end
|
147
175
|
|
148
176
|
def source_paths
|
@@ -181,6 +209,11 @@ module LaneKit
|
|
181
209
|
target = File.join(@tests_fixtures_folder, "#{@model_fixtures_file_name}.m")
|
182
210
|
template(source,target)
|
183
211
|
|
212
|
+
# Create the json file
|
213
|
+
source = "model_fixture.json.erb"
|
214
|
+
target = File.join(@tests_fixtures_folder, "#{@model_fixtures_file_name}.json")
|
215
|
+
template(source,target)
|
216
|
+
|
184
217
|
# 3) Create the Model Tests
|
185
218
|
# Create the .h file
|
186
219
|
source = "model_test.h.erb"
|
@@ -204,9 +237,18 @@ end
|
|
204
237
|
|
205
238
|
module LaneKit
|
206
239
|
class CLI < Thor
|
207
|
-
|
240
|
+
|
241
|
+
desc "generate", "Invoke a code generator"
|
242
|
+
long_desc "Invoke a code generator. There is only one generator so far: 'model' that generates Objective-C code compatible with RestKit that includes unit tests"
|
243
|
+
subcommand "generate", LaneKit::Generators::Generate
|
208
244
|
|
209
245
|
# register(class_name, subcommand_alias, usage_list_string, description_string)
|
210
|
-
register(LaneKit::Generators::Generate, "generate", "generate", "Runs a generator")
|
246
|
+
#register(LaneKit::Generators::Generate, "generate", "generate", "Runs a code generator")
|
247
|
+
|
248
|
+
desc "version", "Display the LaneKit version"
|
249
|
+
|
250
|
+
def version
|
251
|
+
puts "LaneKit #{VERSION}"
|
252
|
+
end
|
211
253
|
end
|
212
254
|
end
|
data/lib/template/model.h.erb
CHANGED
@@ -7,16 +7,19 @@
|
|
7
7
|
// <%=@command%>
|
8
8
|
//
|
9
9
|
|
10
|
-
|
11
|
-
#import <CoreData/CoreData.h><% end %>
|
10
|
+
<% if @using_core_data %>#import <CoreData/CoreData.h><% else %>#import <Foundation/Foundation.h><% end %>
|
12
11
|
|
13
12
|
@class RKObjectMapping;
|
14
13
|
|
15
|
-
@interface <%=@class_name%> : NSObject
|
14
|
+
@interface <%=@class_name%> : <% if @using_core_data %>NSManagedObject<% else %>NSObject<% end %>
|
16
15
|
<% @attributes.each do |attribute| %>
|
17
16
|
@property (nonatomic,strong) <%=attribute[:objective_c_type]%><%=attribute[:name]%>;<% if attribute[:relationship] %> // relates to: <%=attribute[:relationship]%><% end %><% end %>
|
18
|
-
|
19
|
-
+ (
|
20
|
-
+ (
|
17
|
+
<% if @using_core_data %>
|
18
|
+
+ (NSString *)entityName;
|
19
|
+
+ (<%=@class_name%> *)create:(NSManagedObjectContext *)moc;<% end %>
|
20
|
+
+ (NSString *)keyPath; // Used by providers. The subset of the parsed response for which the mapping is to be used.
|
21
|
+
+ (NSString *)pathPattern; // Used by providers. The pattern that matches against URLs for which the mapping should be used.
|
22
|
+
+ (RKObjectMapping *)requestMapping; // Used by providers. Returns the request RKObjectMapping
|
23
|
+
+ (RKObjectMapping *)responseMapping; // Used by providers. Returns the response RKObjectMapping
|
21
24
|
|
22
25
|
@end
|
data/lib/template/model.m.erb
CHANGED
@@ -8,15 +8,36 @@
|
|
8
8
|
#import "RestKit.h"<% @attributes.each do |attribute| %><% if attribute[:relationship] %>
|
9
9
|
#import "<%=attribute[:relationship]%>.h"<%end%><%end%>
|
10
10
|
|
11
|
-
@implementation <%=@class_name%>
|
11
|
+
@implementation <%=@class_name%><% if @using_core_data %>
|
12
|
+
|
13
|
+
// All properties in this NSManagedObject need to be defined with @dynamic<% @attributes.each do |attribute| %>
|
14
|
+
@dynamic <%=attribute[:name]%>;<% end %><% end %>
|
12
15
|
|
13
16
|
+ (void)initialize
|
14
17
|
{
|
15
18
|
if (self == [<%=@class_name%> class])
|
16
19
|
{
|
17
20
|
}
|
21
|
+
}<% if @using_core_data %>
|
22
|
+
|
23
|
+
+ (NSString *)entityName
|
24
|
+
{
|
25
|
+
return NSStringFromClass([self class]);
|
18
26
|
}
|
19
27
|
|
28
|
+
+ (<%=@class_name%> *)create:(NSManagedObjectContext *)moc
|
29
|
+
{
|
30
|
+
<%=@class_name%> *entity = nil;
|
31
|
+
@try {
|
32
|
+
entity = [NSEntityDescription insertNewObjectForEntityForName:self.entityName inManagedObjectContext:moc];
|
33
|
+
}
|
34
|
+
@catch (NSException *exception) {
|
35
|
+
NSLog(@"[%@ %@] %@", [self description], NSStringFromSelector(_cmd), exception);
|
36
|
+
@throw exception;
|
37
|
+
}
|
38
|
+
return entity;
|
39
|
+
}<% end %>
|
40
|
+
|
20
41
|
+ (NSDictionary *)dictionaryForMappings
|
21
42
|
{
|
22
43
|
return @{
|
@@ -24,7 +45,16 @@
|
|
24
45
|
<% end %><% end %> };
|
25
46
|
}
|
26
47
|
|
27
|
-
|
48
|
+
+ (NSString *)keyPath
|
49
|
+
{
|
50
|
+
return @"<%=@model_name%>";
|
51
|
+
}
|
52
|
+
|
53
|
+
+ (NSString *)pathPattern
|
54
|
+
{
|
55
|
+
return nil;
|
56
|
+
}
|
57
|
+
|
28
58
|
+ (RKObjectMapping *)requestMapping
|
29
59
|
{
|
30
60
|
RKObjectMapping *requestMapping = [RKObjectMapping requestMapping];
|
@@ -32,13 +62,12 @@
|
|
32
62
|
return requestMapping;
|
33
63
|
}
|
34
64
|
|
35
|
-
// Returns the response RKObjectMapping
|
36
65
|
+ (RKObjectMapping *)responseMapping
|
37
66
|
{
|
38
67
|
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[<%=@class_name%> class]];
|
39
68
|
[mapping addAttributeMappingsFromDictionary:[self dictionaryForMappings]];
|
40
69
|
<% @attributes.each_with_index do |attribute, index| %><% if attribute[:relationship] %>
|
41
|
-
[mapping addRelationshipMappingWithSourceKeyPath:@"<%=attribute[:name]%>" mapping:[<%=attribute[:relationship]%>
|
70
|
+
[mapping addRelationshipMappingWithSourceKeyPath:@"<%=attribute[:name]%>" mapping:[<%=attribute[:relationship]%> responseMapping]];
|
42
71
|
<% end %><% end %> return mapping;
|
43
72
|
}
|
44
73
|
|
@@ -0,0 +1,5 @@
|
|
1
|
+
{
|
2
|
+
"<%=@model_name%>": {
|
3
|
+
<% @attributes.each_with_index do |attribute, index| %><% if attribute[:relationship] %> "<%=attribute[:relationship]%>": []<% else %> "<%=attribute[:name]%>": "<%=attribute[:fixture_json]%>"<% if index != @attributes.size-1 %>,<% end %><% end %>
|
4
|
+
<% end %> }
|
5
|
+
}
|
@@ -13,7 +13,7 @@
|
|
13
13
|
{
|
14
14
|
<%=@class_name%> *<%=@model_name%> = <%=@class_name%>.new;
|
15
15
|
|
16
|
-
<% @attributes.each_with_index do |attribute, index| %><% if attribute[:relationship] %> <%=@model_name%>.<%=attribute[:name]%> = @[<%=attribute[:relationship]%>Fixtures.one];<% else
|
16
|
+
<% @attributes.each_with_index do |attribute, index| %><% if attribute[:relationship] %> <%=@model_name%>.<%=attribute[:name]%> = @[<%=attribute[:relationship]%>Fixtures.one];<% else %> <%=@model_name%>.<%=attribute[:name]%> = <%=attribute[:fixture_value]%>;<% end %>
|
17
17
|
<% end %>
|
18
18
|
return <%=@model_name%>;
|
19
19
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lanekit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Larry Aasen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/template/model.h.erb
|
52
52
|
- lib/template/model.m.erb
|
53
53
|
- lib/template/model_fixture.h.erb
|
54
|
+
- lib/template/model_fixture.json.erb
|
54
55
|
- lib/template/model_fixture.m.erb
|
55
56
|
- lib/template/model_test.h.erb
|
56
57
|
- lib/template/model_test.m.erb
|