conyard 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems' if RUBY_VERSION < '1.9'
4
+ require 'thor'
5
+ require 'erb'
6
+ require File.join(File.dirname(__FILE__),'../lib/String')
7
+
8
+ $OLDDIR = Dir.pwd
9
+ Dir.chdir File.expand_path(File.join(File.dirname(__FILE__),'..'))
10
+
11
+ class NSCoding < Thor
12
+
13
+ desc 'generate OUTFILE ivar:type,ivar:type,...', "Makes a new NSCoding stubfile"
14
+ def generate(outfile, ivars)
15
+ @outfile = File.expand_path(outfile) or raise "Outfile cannot be nil"
16
+ @ivars = Hash.new
17
+ ivars.split(/,\s*/).each do |ivar|
18
+ type, ivar = ivar.split ':'
19
+ @ivars[type.intern] = ivar
20
+ end
21
+ raise 'No ivars!' if @ivars.empty?
22
+
23
+ puts "Generating NSCoding stubs:"
24
+ puts " outfile: #{@outfile}"
25
+ puts " ivars:"
26
+ @ivars.each do |ivar, type|
27
+ puts " #{ivar}: #{type}"
28
+ end
29
+
30
+ of=File.new(@outfile, "w")
31
+ of.write(ERB.new(File.read('lib/NSCoding/NSCoding.m.erb')).result(binding))
32
+ of.close
33
+ end
34
+
35
+ end
36
+
37
+ NSCoding.start
@@ -7,7 +7,7 @@ require 'erb'
7
7
  $OLDDIR = Dir.pwd
8
8
  Dir.chdir File.expand_path(File.join(File.dirname(__FILE__),'..'))
9
9
 
10
- class VectorDispatcher < Thor
10
+ class Vector < Thor
11
11
 
12
12
  desc "generate NAME TYPE OUTFILE LOCALFILES GLOBALFILES", "Makes a new vector"
13
13
  def generate(name, datatype, outfile, local_include_files, global_include_files)
@@ -37,4 +37,4 @@ class VectorDispatcher < Thor
37
37
 
38
38
  end
39
39
 
40
- VectorDispatcher.start
40
+ Vector.start
@@ -0,0 +1,82 @@
1
+ //! Created by Chris Miller on 17 October 2011.
2
+ //! Copyright 2011 Chris Miller. All rights reserved.
3
+
4
+ //! This file is generated; you are supposed to take the output and paste it
5
+ //! into your own source code files. This is a boilerplate code generator, not
6
+ //! a standalone object.
7
+
8
+ /*-----------------------------------------------------------------------------\
9
+ | PREFIX HEADER |
10
+ | These definitions belong in your project's prefix header. I use them to ens- |
11
+ | re consistency across model changes, and are used by all the code I generate |
12
+ | You may safely change the values in the two error messages, but the serial |
13
+ | version key should not be changed. |
14
+ \-----------------------------------------------------------------------------*/
15
+
16
+ #define kSerialVersionKey @"SerialVersionId"
17
+ #define kUnkeyedCodingError @"Unkeyed Coder Detected!"
18
+ #define kUnknownSerialVersionId @"Unknown Serial Version ID Detected!"
19
+
20
+ /*-----------------------------------------------------------------------------\
21
+ | IMPLEMENTATION FILE - AFTER IMPORTS |
22
+ | This define is local to the implementation file, and you should increment it |
23
+ | whenever your schema changes so you can write a migration deserialization in |
24
+ | the case block in initWithCoder: |
25
+ \-----------------------------------------------------------------------------*/
26
+
27
+ #define kSerialVersionId 0
28
+
29
+ /*-----------------------------------------------------------------------------\
30
+ | IMPLEMENTATION FILE - BEFORE SYNTHESIZE |
31
+ | I use this to ensure that the tag names are consistent and without any capa- |
32
+ | city for typos. If you have the modify the generated code, it is wise to st- |
33
+ | ick with the convention and use these defines, instead of introducing more |
34
+ | string literals into the code. |
35
+ \-----------------------------------------------------------------------------*/
36
+
37
+ <% @ivars.each do |ivar, type| %>#define k<%= ivar.to_s.cap_first_letter %> @"<%= ivar %>"
38
+ <% end %>
39
+
40
+ /*-----------------------------------------------------------------------------\
41
+ | IMPLEMENTATION FILE - ANYWHERE IN IMPLEMENTATION AFTER SYNTHESIZE |
42
+ | This is the actual serialization boilerplate code. Modify this for any spec- |
43
+ | ial case handling you may have. |
44
+ \-----------------------------------------------------------------------------*/
45
+
46
+ #pragma mark NSCoding
47
+
48
+ - (id)initWithCoder:(NSCoder*)aDecoder
49
+ {
50
+ self = [self init];
51
+ if (self) {
52
+ if (![aDecoder allowsKeyedCoding])
53
+ [NSException raise:kUnkeyedCodingError
54
+ format:@"I cannot instaniciate an %@ from an unkeyed coder!", NSStringFromClass([self class])];
55
+
56
+ int64_t svid = [aDecoder decodeInt64ForKey:kSerialVersionKey];
57
+ switch (svid) {
58
+ case kSerialVersionId: // the current version
59
+ <% @ivars.each do |ivar, type| %>self.<%= ivar %> = [aDecoder decode<%= type.to_s.cap_first_letter %>ForKey:k<%= ivar.to_s.cap_first_letter %>];
60
+ <% end %>
61
+ break;
62
+ default:
63
+ [NSException raise:kUnknownSerialVersionIdError
64
+ format:@"I cannot instaniciate an %@ from an archive of version %d!", NSStringFromClass([self class]), svid];
65
+ break;
66
+ }
67
+ }
68
+
69
+ return self;
70
+ }
71
+
72
+ - (void)encodeWithCoder:(NSCoder*)aCoder
73
+ {
74
+ if (![aCoder allowsKeyedCoding])
75
+ [NSException raise:kUnkeyedCodingError
76
+ format:@"I cannot serialize an %@ to an unkeyed coder!", NSStringFromClass([self class])];
77
+
78
+ [aCoder encodeInt64:kSerialVersionId forKey:kSerialVersionKey];
79
+
80
+ <% @ivars.each do |ivar, type| %>[aCoder encode<%= type.to_s.cap_first_letter %>:<%= ivar %> forKey:k<%= ivar.to_s.cap_first_letter %>];
81
+ <% end %>
82
+ }
@@ -0,0 +1,5 @@
1
+ class String
2
+ def cap_first_letter
3
+ return self.slice(0,1).capitalize + self.slice(1..-1)
4
+ end
5
+ end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conyard
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 1
9
- - 5
10
- version: 0.1.5
8
+ - 6
9
+ version: 0.1.6
11
10
  platform: ruby
12
11
  authors:
13
12
  - Christopher Miller
@@ -15,17 +14,16 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-10-17 00:00:00 Z
17
+ date: 2011-10-17 00:00:00 -06:00
18
+ default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: thor
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
24
  requirements:
26
25
  - - ">="
27
26
  - !ruby/object:Gem::Version
28
- hash: 3
29
27
  segments:
30
28
  - 0
31
29
  version: "0"
@@ -35,6 +33,7 @@ description: Conyard is a Ruby experiment in generating source code for use by C
35
33
  email: lordsauronthegreat@gmail.com
36
34
  executables:
37
35
  - conyard-vector
36
+ - conyard-nscoding
38
37
  extensions: []
39
38
 
40
39
  extra_rdoc_files: []
@@ -42,9 +41,13 @@ extra_rdoc_files: []
42
41
  files:
43
42
  - lib/vector/vector.c.erb
44
43
  - lib/vector/vector.h.erb
44
+ - lib/NSCoding/NSCoding.m.erb
45
+ - lib/String.rb
45
46
  - bin/conyard-vector
47
+ - bin/conyard-nscoding
46
48
  - README.md
47
49
  - COPYING.md
50
+ has_rdoc: true
48
51
  homepage: https://github.com/NSError/Conyard/wiki
49
52
  licenses: []
50
53
 
@@ -54,22 +57,18 @@ rdoc_options: []
54
57
  require_paths:
55
58
  - lib
56
59
  required_ruby_version: !ruby/object:Gem::Requirement
57
- none: false
58
60
  requirements:
59
61
  - - ">="
60
62
  - !ruby/object:Gem::Version
61
- hash: 57
62
63
  segments:
63
64
  - 1
64
65
  - 8
65
66
  - 7
66
67
  version: 1.8.7
67
68
  required_rubygems_version: !ruby/object:Gem::Requirement
68
- none: false
69
69
  requirements:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- hash: 23
73
72
  segments:
74
73
  - 1
75
74
  - 3
@@ -78,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
77
  requirements: []
79
78
 
80
79
  rubyforge_project: conyard
81
- rubygems_version: 1.8.10
80
+ rubygems_version: 1.3.6
82
81
  signing_key:
83
82
  specification_version: 3
84
83
  summary: Generators for typing-intensive programming tasks.