lanekit 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE +9 -0
- data/README.md +39 -0
- data/bin/lanekit +8 -0
- data/lib/lanekit/version.rb +3 -0
- data/lib/lanekit.rb +135 -0
- data/lib/template/model.h.erb +19 -0
- data/lib/template/model.m.erb +40 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZjM3ZDc2ZjRkOTQyNzQzMjQ3YjA0ZTQ1MDVmYzQyMDJmNzgxOTcwMw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MWViY2IzZGM4ZjlkOTVlNzRiYTVmYThkMzg4ZGQ3YTc0MzQwMjJlMw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NmJlODc2NjVhNjhkOTdjYzRlNWEyZTQyNzNjYjg1NDQzYzBjMmZiODllNTcz
|
10
|
+
MzA4YmYyYjAwMjE4YTcyZjQyZmIyNzZlNDZiMDUwNjlmOGYzZmEwMjM4OTlk
|
11
|
+
NDdjMGI5ODcwMWUyYmE1NDI5ZjhhMDE0MGMzMGRmODljMzkxNWE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDM1MTE0NDgyMzAxZGIyNDgzNjQ4Y2Q2ZjFiN2RjOGZkMmJiMDY1MTc0ODcy
|
14
|
+
ZGNjNzc1NmM5MzlkMDY3ZWFhOGRjNzEzZTM3NDQ1Y2Q4YTY1Zjg3MjkzNDVm
|
15
|
+
NDFhODY1YmVhMTUwMTE0YzljYmNjMzkzZTE1ODlkNGE0MjlmMTc=
|
data/LICENSE
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2013 Larry Aasen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
## LaneKit
|
2
|
+
|
3
|
+
LaneKit is a Ruby command line app that creates iOS Objective-C models for integration with RestKit.
|
4
|
+
|
5
|
+
## How To Get Started
|
6
|
+
|
7
|
+
1. Install the LaneKit Ruby Gem from RubyGems.org
|
8
|
+
|
9
|
+
```
|
10
|
+
$ gem install lanekit
|
11
|
+
Successfully installed lanekit-0.1.1
|
12
|
+
```
|
13
|
+
|
14
|
+
- [Download LaneKit](https://github.com/LarryAasen/LaneKit/zipball/master) from [GitHub](http://github.com).
|
15
|
+
- Questions? [Stack Overflow](http://stackoverflow.com/questions/tagged/lanekit) is the best place to find answers.
|
16
|
+
|
17
|
+
## Example Usage
|
18
|
+
|
19
|
+
### Create a new model called Video
|
20
|
+
```
|
21
|
+
$ lanekit generate model video duration:string headline:string image:string
|
22
|
+
```
|
23
|
+
|
24
|
+
## Credits
|
25
|
+
|
26
|
+
LaneKit was created by [Larry Aasen](https://github.com/larryaasen).
|
27
|
+
|
28
|
+
## Contact
|
29
|
+
|
30
|
+
Follow Larry Aasen on Twitter [@LarryAasen](https://twitter.com/LarryAasen).
|
31
|
+
|
32
|
+
### Creators
|
33
|
+
|
34
|
+
[Larry Aasen](https://github.com/larryaasen)
|
35
|
+
[@larryaasen](https://twitter.com/larryaasen)
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
LaneKit is available under the MIT license. See the LICENSE file for more info.
|
data/bin/lanekit
ADDED
data/lib/lanekit.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'xcodeproj'
|
3
|
+
require 'lanekit/version'
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_support/inflector'
|
6
|
+
|
7
|
+
module LaneKit
|
8
|
+
@@objc_types = {
|
9
|
+
array: "NSArray *"
|
10
|
+
}
|
11
|
+
|
12
|
+
# Model names are lower case
|
13
|
+
# "Car" => "car", "Bigbird" => "bigbird"
|
14
|
+
def self.derive_model_name(name)
|
15
|
+
model_name = name.to_s.downcase
|
16
|
+
model_name
|
17
|
+
end
|
18
|
+
|
19
|
+
# Objective-C class names are capitalized
|
20
|
+
# "car" => "Car", "bigbird" => "Bigbird"
|
21
|
+
def self.derive_class_name(name)
|
22
|
+
class_name = name.to_s.capitalize
|
23
|
+
class_name
|
24
|
+
end
|
25
|
+
|
26
|
+
# File names are the same as class names
|
27
|
+
def self.derive_file_name(name)
|
28
|
+
file_name = name.to_s.capitalize
|
29
|
+
file_name
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.objective_c_type(type_name)
|
33
|
+
type = @@objc_types[type_name]
|
34
|
+
return type if type
|
35
|
+
|
36
|
+
if type_name == "array"
|
37
|
+
type = "NSArray *"
|
38
|
+
elsif type_name == "date"
|
39
|
+
type = "NSDate *"
|
40
|
+
elsif type_name == "integer"
|
41
|
+
type = "NSNumber *"
|
42
|
+
elsif type_name == "string"
|
43
|
+
type = "NSString *"
|
44
|
+
elsif type_name
|
45
|
+
type = type_name + " *"
|
46
|
+
else
|
47
|
+
type = "id "
|
48
|
+
end
|
49
|
+
type
|
50
|
+
end
|
51
|
+
|
52
|
+
module Generators
|
53
|
+
|
54
|
+
class Generate < Thor
|
55
|
+
include Thor::Actions
|
56
|
+
|
57
|
+
desc "model [name] [name:type, name:type, ...] where type is [date|integer|string|<class_name>]", "Generates an Objective-C model for RestKit"
|
58
|
+
def model(model_name, *attributes)
|
59
|
+
@model_name = LaneKit.derive_model_name(model_name)
|
60
|
+
@file_name = LaneKit.derive_file_name(@model_name)
|
61
|
+
@class_name = LaneKit.derive_class_name(@model_name)
|
62
|
+
|
63
|
+
@attributes = []
|
64
|
+
@any_relationships = false
|
65
|
+
|
66
|
+
attributes.each {|attribute|
|
67
|
+
name, type, relationship = attribute.split(":")
|
68
|
+
objective_c_type = LaneKit.objective_c_type(type)
|
69
|
+
@attributes << {
|
70
|
+
:type => type,
|
71
|
+
:name => name,
|
72
|
+
:objective_c_type => objective_c_type,
|
73
|
+
:relationship => relationship
|
74
|
+
}
|
75
|
+
@any_relationships = relationship ? true : @any_relationships
|
76
|
+
}
|
77
|
+
|
78
|
+
self.initialize_stuff
|
79
|
+
self.create_model_folders
|
80
|
+
self.create_model_files @model_name
|
81
|
+
self.update_xcode_project @model_name
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.source_root
|
85
|
+
File.dirname('./')
|
86
|
+
end
|
87
|
+
|
88
|
+
no_commands {
|
89
|
+
def initialize_stuff
|
90
|
+
@model_date = Date.today.to_s
|
91
|
+
@models_folder = "Classes/model"
|
92
|
+
@template_folder = File.expand_path('../template', __FILE__)
|
93
|
+
@using_core_data = false
|
94
|
+
end
|
95
|
+
|
96
|
+
def source_paths
|
97
|
+
[@template_folder]
|
98
|
+
end
|
99
|
+
|
100
|
+
def create_model_folders
|
101
|
+
empty_directory @models_folder
|
102
|
+
end
|
103
|
+
|
104
|
+
def create_model_files(model_name)
|
105
|
+
# Files are created lowercase
|
106
|
+
# Class names are camel case, videodata => VideoData
|
107
|
+
|
108
|
+
# Create the .h file
|
109
|
+
source = "model.h.erb"
|
110
|
+
target = File.join(@models_folder, "#{@file_name}.h")
|
111
|
+
template(source,target)
|
112
|
+
|
113
|
+
# Create the .m file
|
114
|
+
source = "model.m.erb"
|
115
|
+
target = File.join(@models_folder, "#{@file_name}.m")
|
116
|
+
template(source,target)
|
117
|
+
end
|
118
|
+
|
119
|
+
def update_xcode_project(model_name)
|
120
|
+
xcworkspace_path = ""
|
121
|
+
Xcodeproj::Workspace.new_from_xcworkspace(xcworkspace_path)
|
122
|
+
end
|
123
|
+
}
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
module LaneKit
|
129
|
+
class CLI < Thor
|
130
|
+
desc "generate", "Generate a model compatible with RestKit"
|
131
|
+
|
132
|
+
# register(class_name, subcommand_alias, usage_list_string, description_string)
|
133
|
+
register(LaneKit::Generators::Generate, "generate", "generate", "Runs a generator")
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
//
|
2
|
+
// <%=@file_name%>.h
|
3
|
+
//
|
4
|
+
// This model was created on <%=@model_date%> by LaneKit.
|
5
|
+
//
|
6
|
+
//
|
7
|
+
|
8
|
+
#import <Foundation/Foundation.h><% if @using_core_data %>
|
9
|
+
#import <CoreData/CoreData.h><% end %>
|
10
|
+
|
11
|
+
@class RKObjectMapping;
|
12
|
+
|
13
|
+
@interface <%=@class_name%> : NSObject
|
14
|
+
|
15
|
+
<% @attributes.each do |attribute| %>@property (nonatomic,strong) <%=attribute[:objective_c_type]%><%=attribute[:name]%>;<% if attribute[:relationship] %> // relates to: <%=attribute[:relationship]%><% end %><% end %>
|
16
|
+
|
17
|
+
+ (RKObjectMapping *)modelMapping;
|
18
|
+
|
19
|
+
@end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
//
|
2
|
+
// <%=@file_name%>.m
|
3
|
+
//
|
4
|
+
// This model was created on <%=@model_date%> by LaneKit.
|
5
|
+
//
|
6
|
+
//
|
7
|
+
|
8
|
+
#import "<%=@file_name%>.h"
|
9
|
+
#import "MobileCoreServices/MobileCoreServices.h"
|
10
|
+
#import "SystemConfiguration/SystemConfiguration.h"
|
11
|
+
#import "RestKit.h"
|
12
|
+
<% @attributes.each do |attribute| %><% if attribute[:relationship] %>#import "<%=attribute[:relationship]%>.h"<%end%><%end%>
|
13
|
+
|
14
|
+
@implementation <%=@class_name%>
|
15
|
+
|
16
|
+
+ (void)initialize
|
17
|
+
{
|
18
|
+
if (self == [<%=@class_name%> class])
|
19
|
+
{
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
// Returns the RKObjectMapping for this class
|
24
|
+
+ (RKObjectMapping *)modelMapping
|
25
|
+
{
|
26
|
+
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[<%=@class_name%> class]];
|
27
|
+
[mapping addAttributeMappingsFromDictionary:@{
|
28
|
+
<% @attributes.each_with_index do |attribute, index| %>
|
29
|
+
<% if !attribute[:relationship] %>
|
30
|
+
@"<%=attribute[:name]%>": @"<%=attribute[:name]%>"<% if index != @attributes.size-1 %>,<% end %>
|
31
|
+
<% end %><% end %> }];
|
32
|
+
<% @attributes.each_with_index do |attribute, index| %>
|
33
|
+
<% if attribute[:relationship] %>
|
34
|
+
[mapping addRelationshipMappingWithSourceKeyPath:@"<%=attribute[:name]%>" mapping:[<%=attribute[:relationship]%> modelMapping]];
|
35
|
+
<% end %><% end %>
|
36
|
+
|
37
|
+
return mapping;
|
38
|
+
}
|
39
|
+
|
40
|
+
@end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lanekit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Larry Aasen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: xcodeproj
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.5.5
|
27
|
+
description: an Objective-C model creator for RestKit.
|
28
|
+
email:
|
29
|
+
- larryaasen@gmail.com
|
30
|
+
executables:
|
31
|
+
- lanekit
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- lib/lanekit/version.rb
|
36
|
+
- lib/lanekit.rb
|
37
|
+
- lib/template/model.h.erb
|
38
|
+
- lib/template/model.m.erb
|
39
|
+
- bin/lanekit
|
40
|
+
- README.md
|
41
|
+
- LICENSE
|
42
|
+
homepage: https://github.com/LarryAasen/LaneKit
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.8.7
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.0.3
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: LaneKit is a Ruby command line app that creates Objective-C models for integration
|
66
|
+
to RestKit.
|
67
|
+
test_files: []
|