udgenerator 1.0.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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +7 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/bin/udgenerator +28 -0
- data/file/Base.h +10 -0
- data/file/Base.swift +10 -0
- data/lib/udgenerator.rb +119 -0
- data/lib/udgenerator/objective.rb +50 -0
- data/lib/udgenerator/swift.rb +47 -0
- data/lib/udgenerator/type.rb +332 -0
- data/lib/udgenerator/version.rb +3 -0
- data/udgenerator.gemspec +24 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0e68988a61d769a6abee68a56cee1956af188da7
|
4
|
+
data.tar.gz: ff8b7ace5333f57e0657a51658f273dd3e9fd277
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f80fa89a633233e1c43d00a4b09e39579ece66628819f5b62ff2682a3bb7ca63d8ca1e757213a8b4e6ac29dc420b11df5af06b7a42fea0e574ef48535e76b3c9
|
7
|
+
data.tar.gz: 70bad755d4d4e4ccc6e3c29f404877116bad48fcf4f0b34c02f4f7f66c86404009e2ed644bcd460ff6dc745705a23665836a877b5686aa78b632620ff05927c3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 akuraru
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Udcreater
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/udcreater`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'udcreater'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install udcreater
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/udcreater/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "udcreater"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/bin/udgenerator
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "udgenerator/version"
|
4
|
+
require "udgenerator"
|
5
|
+
require "thor"
|
6
|
+
|
7
|
+
module Udgenerator
|
8
|
+
#= Udgenerator CLI
|
9
|
+
class CLI < Thor
|
10
|
+
default_task :update
|
11
|
+
|
12
|
+
option :auto_init, :type => :boolean, :aliases => '-a', :default => true, :desc => 'auto initialization. all zero or empty string, etc ...'
|
13
|
+
option :input, :type => :string, :aliases => '-i', :default => true, :required => true, :desc => 'input file'
|
14
|
+
option :output, :type => :string, :aliases => '-o', :default => true, :desc => 'output directory'
|
15
|
+
option :file_name, :type => :string, :aliases => '-f', :default => true, :desc => 'output file name'
|
16
|
+
desc "generate", "generate storyboard"
|
17
|
+
def update
|
18
|
+
Core.new.generate(options)
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "version", "version"
|
22
|
+
def version
|
23
|
+
p VERSION
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Udgenerator::CLI.start(ARGV)
|
data/file/Base.h
ADDED
data/file/Base.swift
ADDED
data/lib/udgenerator.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require "udgenerator/version"
|
2
|
+
require "udgenerator/type"
|
3
|
+
require "udgenerator/objective"
|
4
|
+
require "udgenerator/swift"
|
5
|
+
|
6
|
+
module Udgenerator
|
7
|
+
class Core
|
8
|
+
def generator(options)
|
9
|
+
FileUtils.mkdir_p(options[:output]) unless FileTest.exist?(options[:output])
|
10
|
+
|
11
|
+
if options[:swift] then
|
12
|
+
arrType = swift_exchange(self.fileRead(options[:input]))
|
13
|
+
File.open("#{options[:output]}#{options[:file_name]}.swift", "w:UTF-8").write swift(arrType, options[:file_name], options[:auto_init])
|
14
|
+
else
|
15
|
+
arrType = exchange(self.fileRead(options[:input]))
|
16
|
+
File.open("#{options[:output]}#{options[:file_name]}.h", "w:UTF-8").write header(arrType, options[:file_name], options[:auto_init])
|
17
|
+
File.open("#{options[:output]}#{options[:file_name]}.m", "w:UTF-8").write method(arrType, options[:file_name], options[:auto_init])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
def initialize
|
21
|
+
end
|
22
|
+
|
23
|
+
def fileRead(fileName)
|
24
|
+
File.open(fileName, :encoding => Encoding::UTF_8).read.scan(/(.*)\n/).flatten
|
25
|
+
end
|
26
|
+
def registHeader(register)
|
27
|
+
if (register)
|
28
|
+
""
|
29
|
+
else
|
30
|
+
"- (void)registerDefaults:(NSDictionary *)dict;\n"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
def header(arrType, fileName, register)
|
34
|
+
result = ""
|
35
|
+
arrType.each_pair{|k, v| result += interface(k, v) + "\n"}
|
36
|
+
"\#import <Foundation/Foundation.h>\n\n" +
|
37
|
+
imp_defines(arrType) +
|
38
|
+
"\n\@interface #{fileName} : NSObject\n\n+ (instancetype)sharedManager;\n#{self.registHeader(register)}\n" + result +
|
39
|
+
"\@end\n"
|
40
|
+
end
|
41
|
+
def registerDefaults(arrType)
|
42
|
+
result = ""
|
43
|
+
arrType.each_pair{|k, v|
|
44
|
+
d = register_default(k, v)
|
45
|
+
result += " "*12 + d + ",\n" if d != ""
|
46
|
+
}
|
47
|
+
" [defaults registerDefaults:@{\n" + result + " }];\n"
|
48
|
+
end
|
49
|
+
def init(arrType, register)
|
50
|
+
if (register)
|
51
|
+
"- (id)init {\n self = [super init];\n if (self != nil) {\n defaults = [NSUserDefaults standardUserDefaults];\n#{registerDefaults(arrType)} }\n\n return self;\n}\n"
|
52
|
+
else
|
53
|
+
"- (id)init {\n self = [super init];\n if (self != nil) {\n defaults = [NSUserDefaults standardUserDefaults];\n }\n\n return self;\n}\n- (void)registerDefaults:(NSDictionary *)dict {\n [defaults registerDefaults:dict];\n}\n"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
def imp_defines(arrType)
|
57
|
+
result = ""
|
58
|
+
arrType.each_pair{|s, d| result += imp_define(s, d)}
|
59
|
+
result
|
60
|
+
end
|
61
|
+
def implementation(arrType)
|
62
|
+
result = ""
|
63
|
+
arrType.each_pair{|s, d| result += impGetter(s, d) + impSetter(s, d) + "\n"}
|
64
|
+
result
|
65
|
+
end
|
66
|
+
def method(arrType, fileName, register)
|
67
|
+
"\#import \"#{fileName}.h\"\n\n" +
|
68
|
+
"\@implementation #{fileName} {\n NSUserDefaults *defaults;\n}\n\n+ (instancetype)sharedManager {\n static #{fileName} *sharedManager_ = nil;\n static dispatch_once_t onceToken;\n dispatch_once(&onceToken, ^{\n sharedManager_ = #{fileName}.new;\n });\n\n return sharedManager_;\n}\n\n" +
|
69
|
+
self.init(arrType, register) + "\n" +
|
70
|
+
self.implementation(arrType) +
|
71
|
+
"@end\n"
|
72
|
+
end
|
73
|
+
def swift(arrType, fileName, register)
|
74
|
+
"import Foundation\n\nstruct #{fileName}Register {\n#{structs(arrType)}}\n\nclass #{fileName} {" + '
|
75
|
+
class func sharedManager() -> UserDefaults {
|
76
|
+
struct Static {
|
77
|
+
static let instance = UserDefaults()
|
78
|
+
}
|
79
|
+
return Static.instance
|
80
|
+
}
|
81
|
+
init() {
|
82
|
+
' + swift_register_defaults(arrType, fileName, register) + '
|
83
|
+
}
|
84
|
+
func defaults() -> NSUserDefaults {
|
85
|
+
return NSUserDefaults.standardUserDefaults()
|
86
|
+
}
|
87
|
+
func set(value: AnyObject?, forKey: String) {
|
88
|
+
defaults().setObject(value, forKey: forKey)
|
89
|
+
defaults().synchronize()
|
90
|
+
}
|
91
|
+
func get(key: String) -> AnyObject? {
|
92
|
+
return defaults().objectForKey(key)
|
93
|
+
}
|
94
|
+
' + swift_get_sets(arrType, fileName) + "}\n"
|
95
|
+
end
|
96
|
+
def swift_register_defaults(arrType, fileName, register)
|
97
|
+
if register then
|
98
|
+
" defaults().registerDefaults([\n" + registers(arrType, fileName) + " ])"
|
99
|
+
else
|
100
|
+
" }\n func registerDefaults(dict: [String: AnyObject]) {\n defaults().registerDefaults(dict)"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
def registers(arrType, fileName)
|
104
|
+
result = ""
|
105
|
+
arrType.each_pair{|k, v| result += swift_register_default(k, v, fileName)}
|
106
|
+
result
|
107
|
+
end
|
108
|
+
def structs(arrType)
|
109
|
+
result = ""
|
110
|
+
arrType.each_pair{|s, d| result += struct(s) + "\n"}
|
111
|
+
result
|
112
|
+
end
|
113
|
+
def swift_get_sets(arrType, fileName)
|
114
|
+
result = ""
|
115
|
+
arrType.each_pair{|s, d| result += "\n #{swift_getter(s, d)} {\n return get(#{fileName}Register.#{s}) as #{d.swift_type_name}\n }\n #{swift_setter(s, d)} {\n set(#{s}, forKey: #{fileName}Register.#{s})\n }\n"}
|
116
|
+
result
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
module Udgenerator
|
3
|
+
class Objective
|
4
|
+
def parse(arrStr)
|
5
|
+
result = {}
|
6
|
+
arrStr.each{|s|
|
7
|
+
if /\s*(\w+) *\* *(\w+)\s*;\s*/ =~ s then
|
8
|
+
result[$2] = object($1)
|
9
|
+
elsif /- \((\w+) *\* *\)(\w+);/ =~ s then
|
10
|
+
result[$2] = object($1)
|
11
|
+
elsif /\s*(\w+)\s+(\w+)\s*;\s*/ =~ s then
|
12
|
+
result[$2] = value($1)
|
13
|
+
elsif /- \((\w+)\)(\w+);/ =~ s then
|
14
|
+
result[$2] = value($1)
|
15
|
+
end
|
16
|
+
}
|
17
|
+
result
|
18
|
+
end
|
19
|
+
def object(type)
|
20
|
+
if "NSString" == type
|
21
|
+
NSString.new()
|
22
|
+
elsif "NSNumber" == type
|
23
|
+
NSNumber.new()
|
24
|
+
elsif "NSArray" == type
|
25
|
+
NSArray.new()
|
26
|
+
elsif "NSDictionary" == type
|
27
|
+
NSDictionary.new()
|
28
|
+
elsif "NSData" == type
|
29
|
+
NSData.new()
|
30
|
+
elsif "NSDate" == type
|
31
|
+
NSDate.new()
|
32
|
+
else
|
33
|
+
AnyObject.new("#{type}")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
def value(type)
|
37
|
+
if "NSInteger" == type then
|
38
|
+
NSInteger.new()
|
39
|
+
elsif "BOOL" == type then
|
40
|
+
NSBOOL.new()
|
41
|
+
elsif "float" == type then
|
42
|
+
NSFloat.new()
|
43
|
+
elsif "double" == type then
|
44
|
+
NSDouble.new()
|
45
|
+
else
|
46
|
+
AnyObject.new("#{type}")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
module Udgenerator
|
3
|
+
class Swift
|
4
|
+
def parse(arrStr)
|
5
|
+
result = {}
|
6
|
+
arrStr.each{|s|
|
7
|
+
if /\s*(\w+) *\* *(\w+)\s*;\s*/ =~ s then
|
8
|
+
result[$2] = object($1)
|
9
|
+
elsif /- \((\w+) *\* *\)(\w+);/ =~ s then
|
10
|
+
result[$2] = object($1)
|
11
|
+
elsif /\s*func\s+(\w+)\(\s*\)\s*->\s*(\w+)\s*\{?\s*/ =~ s then
|
12
|
+
result[$1] = object($2)
|
13
|
+
elsif /\s*(var|let)\s+(\w+)\s*:\s*(\w+)\??\s*;?\s*/ =~ s then
|
14
|
+
result[$2] = object($3)
|
15
|
+
end
|
16
|
+
}
|
17
|
+
result
|
18
|
+
end
|
19
|
+
def object(type)
|
20
|
+
if "NSString" == type
|
21
|
+
NSString.new()
|
22
|
+
elsif "String" == type
|
23
|
+
NSString.new()
|
24
|
+
elsif "NSNumber" == type
|
25
|
+
NSNumber.new()
|
26
|
+
elsif "NSArray" == type
|
27
|
+
NSArray.new()
|
28
|
+
elsif "NSDictionary" == type
|
29
|
+
NSDictionary.new()
|
30
|
+
elsif "NSData" == type
|
31
|
+
NSData.new()
|
32
|
+
elsif "NSDate" == type
|
33
|
+
NSDate.new()
|
34
|
+
elsif "Bool" == type
|
35
|
+
NSBOOL.new()
|
36
|
+
elsif "Int" == type
|
37
|
+
NSInteger.new()
|
38
|
+
elsif "Double" == type
|
39
|
+
NSDouble.new()
|
40
|
+
elsif "Float" == type
|
41
|
+
NSFloat.new()
|
42
|
+
else
|
43
|
+
AnyObject.new("#{type}")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,332 @@
|
|
1
|
+
module Udgenerator
|
2
|
+
class Core
|
3
|
+
def capitalize(str)
|
4
|
+
str[0,1].capitalize + str[1..-1]
|
5
|
+
end
|
6
|
+
def define(str)
|
7
|
+
"k" + capitalize(str)
|
8
|
+
end
|
9
|
+
def to_nsstring(str)
|
10
|
+
'@"' + str + '"'
|
11
|
+
end
|
12
|
+
def getter(key, value)
|
13
|
+
"- (#{value.type_name})#{key}"
|
14
|
+
end
|
15
|
+
def interface_getter(key, value)
|
16
|
+
getter(key, value) + ";\n"
|
17
|
+
end
|
18
|
+
def setter(key, value)
|
19
|
+
"- (void)set#{capitalize(key)}:(#{value.type_name})#{key}"
|
20
|
+
end
|
21
|
+
def interface_setter(key, value)
|
22
|
+
setter(key, value) + ";\n"
|
23
|
+
end
|
24
|
+
def interface(key, value)
|
25
|
+
interface_getter(key, value) + interface_setter(key, value)
|
26
|
+
end
|
27
|
+
def imp_define(key, value)
|
28
|
+
"\#define #{define(key)} #{to_nsstring(key)}\n"
|
29
|
+
end
|
30
|
+
def register_default(key, value)
|
31
|
+
if (0 < value.defaultValue.length ) then
|
32
|
+
"#{define(key)} : #{value.defaultValue}"
|
33
|
+
else
|
34
|
+
""
|
35
|
+
end
|
36
|
+
end
|
37
|
+
def in_imp_getter(key, value)
|
38
|
+
" return [defaults #{value.imp_get_message}:#{define(key)}];\n"
|
39
|
+
end
|
40
|
+
def impGetter(key, value)
|
41
|
+
"#{getter(key, value)} \{\n#{in_imp_getter(key, value)}\}\n"
|
42
|
+
end
|
43
|
+
def in_imp_setter(key, value)
|
44
|
+
" [defaults #{value.imp_set_message}:#{key} forKey:#{define(key)}];\n [defaults synchronize];\n"
|
45
|
+
end
|
46
|
+
def impSetter(key, value)
|
47
|
+
"#{setter(key, value)} \{\n#{in_imp_setter(key, value)}\}\n"
|
48
|
+
end
|
49
|
+
def struct(key)
|
50
|
+
" static let #{key} = \"#{key}\""
|
51
|
+
end
|
52
|
+
def swift_getter(key, value)
|
53
|
+
"func #{key}() -> #{value.swift_type_name}"
|
54
|
+
end
|
55
|
+
def swift_setter(key, value)
|
56
|
+
"func set#{capitalize(key)}(#{key}: #{value.swift_type_name})"
|
57
|
+
end
|
58
|
+
def exchange(arrStr)
|
59
|
+
Objective.new().parse(arrStr)
|
60
|
+
end
|
61
|
+
def swift_exchange(arrStr)
|
62
|
+
Swift.new().parse(arrStr)
|
63
|
+
end
|
64
|
+
def swift_register_default(key, value, fileName)
|
65
|
+
if (0 < value.swift_default_value.length) then
|
66
|
+
" "*12 + "#{fileName}Register.#{key}: #{value.swift_default_value},\n"
|
67
|
+
else
|
68
|
+
""
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Type
|
74
|
+
def initialize()
|
75
|
+
end
|
76
|
+
def == (type)
|
77
|
+
true
|
78
|
+
end
|
79
|
+
def type_name
|
80
|
+
"Type"
|
81
|
+
end
|
82
|
+
def swift_type_name
|
83
|
+
"Type"
|
84
|
+
end
|
85
|
+
def defaultValue
|
86
|
+
""
|
87
|
+
end
|
88
|
+
def swift_default_value
|
89
|
+
""
|
90
|
+
end
|
91
|
+
def imp_set_message
|
92
|
+
""
|
93
|
+
end
|
94
|
+
def typeExchange(obj)
|
95
|
+
obj
|
96
|
+
end
|
97
|
+
def objectExchange(obj)
|
98
|
+
obj
|
99
|
+
end
|
100
|
+
def property
|
101
|
+
"@property #{self.type_name} #{self.name};\n"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
class NSObject < Type
|
105
|
+
def == (type)
|
106
|
+
NSObject === type && super(type)
|
107
|
+
end
|
108
|
+
def type_name
|
109
|
+
"id"
|
110
|
+
end
|
111
|
+
def swift_type_name
|
112
|
+
"AnyObject"
|
113
|
+
end
|
114
|
+
def imp_get_message
|
115
|
+
"objectForKey"
|
116
|
+
end
|
117
|
+
def imp_set_message
|
118
|
+
"setObject"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
class NSString < NSObject
|
122
|
+
def == (type)
|
123
|
+
NSString === type && super(type)
|
124
|
+
end
|
125
|
+
def type_name
|
126
|
+
"NSString *"
|
127
|
+
end
|
128
|
+
def swift_type_name
|
129
|
+
"String"
|
130
|
+
end
|
131
|
+
def defaultValue
|
132
|
+
"@\"\""
|
133
|
+
end
|
134
|
+
def swift_default_value
|
135
|
+
"\"\""
|
136
|
+
end
|
137
|
+
end
|
138
|
+
class NSNumber < NSObject
|
139
|
+
def == (type)
|
140
|
+
NSNumber === type && super(type)
|
141
|
+
end
|
142
|
+
def type_name
|
143
|
+
"NSNumber *"
|
144
|
+
end
|
145
|
+
def swift_type_name
|
146
|
+
"NSNumber"
|
147
|
+
end
|
148
|
+
def defaultValue
|
149
|
+
"\@0"
|
150
|
+
end
|
151
|
+
def swift_default_value
|
152
|
+
"0"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
class NSArray < NSObject
|
156
|
+
def == (type)
|
157
|
+
NSArray === type && super(type)
|
158
|
+
end
|
159
|
+
def type_name
|
160
|
+
"NSArray *"
|
161
|
+
end
|
162
|
+
def swift_type_name
|
163
|
+
"NSArray"
|
164
|
+
end
|
165
|
+
def defaultValue
|
166
|
+
"@[]"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
class NSDictionary < NSObject
|
170
|
+
def == (type)
|
171
|
+
NSDictionary === type && super(type)
|
172
|
+
end
|
173
|
+
def type_name
|
174
|
+
"NSDictionary *"
|
175
|
+
end
|
176
|
+
def swift_type_name
|
177
|
+
"NSDictionary"
|
178
|
+
end
|
179
|
+
def defaultValue
|
180
|
+
"@{}"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
class NSData < NSObject
|
184
|
+
def == (type)
|
185
|
+
NSData === type && super(type)
|
186
|
+
end
|
187
|
+
def type_name
|
188
|
+
"NSData *"
|
189
|
+
end
|
190
|
+
def swift_type_name
|
191
|
+
"NSData"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
class NSDate < NSObject
|
195
|
+
def == (type)
|
196
|
+
NSDate === type && super(type)
|
197
|
+
end
|
198
|
+
def type_name
|
199
|
+
"NSDate *"
|
200
|
+
end
|
201
|
+
def swift_type_name
|
202
|
+
"NSDate"
|
203
|
+
end
|
204
|
+
def defaultValue
|
205
|
+
"[NSDate date]"
|
206
|
+
end
|
207
|
+
def swift_default_value
|
208
|
+
"NSDate()"
|
209
|
+
end
|
210
|
+
end
|
211
|
+
class AnyObject < NSObject
|
212
|
+
attr :type
|
213
|
+
def initialize(type)
|
214
|
+
@type = type
|
215
|
+
end
|
216
|
+
def == (type)
|
217
|
+
AnyObject === type && @type === type.type && super(type)
|
218
|
+
end
|
219
|
+
def type_name
|
220
|
+
"#{@type} *"
|
221
|
+
end
|
222
|
+
def swift_type_name
|
223
|
+
@type
|
224
|
+
end
|
225
|
+
end
|
226
|
+
class NSValue < Type
|
227
|
+
def == (type)
|
228
|
+
NSValue === type && super(type)
|
229
|
+
end
|
230
|
+
def type_name
|
231
|
+
"NSValue"
|
232
|
+
end
|
233
|
+
def swift_type_name
|
234
|
+
"NSValue"
|
235
|
+
end
|
236
|
+
def defaultValue
|
237
|
+
"@0"
|
238
|
+
end
|
239
|
+
def typeExchange(obj)
|
240
|
+
"[#{obj} integerValue]"
|
241
|
+
end
|
242
|
+
def objectExchange(value)
|
243
|
+
"@(#{value})"
|
244
|
+
end
|
245
|
+
def swift_default_value
|
246
|
+
"0"
|
247
|
+
end
|
248
|
+
end
|
249
|
+
class NSInteger < NSValue
|
250
|
+
def == (type)
|
251
|
+
NSInteger === type && super(type)
|
252
|
+
end
|
253
|
+
def type_name
|
254
|
+
"NSInteger"
|
255
|
+
end
|
256
|
+
def swift_type_name
|
257
|
+
"Int"
|
258
|
+
end
|
259
|
+
def imp_get_message
|
260
|
+
"integerForKey"
|
261
|
+
end
|
262
|
+
def imp_set_message
|
263
|
+
"setInteger"
|
264
|
+
end
|
265
|
+
def typeExchange(obj)
|
266
|
+
"[#{obj} integerValue]"
|
267
|
+
end
|
268
|
+
end
|
269
|
+
class NSBOOL < NSValue
|
270
|
+
def == (type)
|
271
|
+
NSBOOL === type && super(type)
|
272
|
+
end
|
273
|
+
def type_name
|
274
|
+
"BOOL"
|
275
|
+
end
|
276
|
+
def swift_type_name
|
277
|
+
"Bool"
|
278
|
+
end
|
279
|
+
def imp_get_message
|
280
|
+
"boolForKey"
|
281
|
+
end
|
282
|
+
def imp_set_message
|
283
|
+
"setBool"
|
284
|
+
end
|
285
|
+
def typeExchange(obj)
|
286
|
+
"[#{obj} boolValue]"
|
287
|
+
end
|
288
|
+
def swift_default_value
|
289
|
+
"false"
|
290
|
+
end
|
291
|
+
end
|
292
|
+
class NSFloat < NSValue
|
293
|
+
def == (type)
|
294
|
+
NSFloat === type && super(type)
|
295
|
+
end
|
296
|
+
def type_name
|
297
|
+
"float"
|
298
|
+
end
|
299
|
+
def swift_type_name
|
300
|
+
"Float"
|
301
|
+
end
|
302
|
+
def imp_get_message
|
303
|
+
"floatForKey"
|
304
|
+
end
|
305
|
+
def imp_set_message
|
306
|
+
"setFloat"
|
307
|
+
end
|
308
|
+
def typeExchange(obj)
|
309
|
+
"[#{obj} floatValue]"
|
310
|
+
end
|
311
|
+
end
|
312
|
+
class NSDouble < NSValue
|
313
|
+
def == (type)
|
314
|
+
NSDouble === type && super(type)
|
315
|
+
end
|
316
|
+
def type_name
|
317
|
+
"double"
|
318
|
+
end
|
319
|
+
def swift_type_name
|
320
|
+
"Double"
|
321
|
+
end
|
322
|
+
def imp_get_message
|
323
|
+
"doubleForKey"
|
324
|
+
end
|
325
|
+
def imp_set_message
|
326
|
+
"setDouble"
|
327
|
+
end
|
328
|
+
def typeExchange(obj)
|
329
|
+
"[#{obj} doubleValue]"
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
data/udgenerator.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'udgenerator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "udgenerator"
|
8
|
+
spec.version = Udgenerator::VERSION
|
9
|
+
spec.authors = ["akuraru"]
|
10
|
+
spec.email = ["akuraru@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{generate NSUserDefaults rapper}
|
13
|
+
spec.description = %q{generate a wrapper of NSUserDefaults from type and name}
|
14
|
+
spec.homepage = "https://github.com/akuraru/UserDefaultsCreator"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: udgenerator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- akuraru
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: generate a wrapper of NSUserDefaults from type and name
|
42
|
+
email:
|
43
|
+
- akuraru@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".travis.yml"
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- Gemfile
|
53
|
+
- Guardfile
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- bin/console
|
58
|
+
- bin/setup
|
59
|
+
- bin/udgenerator
|
60
|
+
- file/Base.h
|
61
|
+
- file/Base.swift
|
62
|
+
- lib/udgenerator.rb
|
63
|
+
- lib/udgenerator/objective.rb
|
64
|
+
- lib/udgenerator/swift.rb
|
65
|
+
- lib/udgenerator/type.rb
|
66
|
+
- lib/udgenerator/version.rb
|
67
|
+
- udgenerator.gemspec
|
68
|
+
homepage: https://github.com/akuraru/UserDefaultsCreator
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.4.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: generate NSUserDefaults rapper
|
92
|
+
test_files: []
|