cog 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e1f8ad2d26be0b178e872bf2bb7f4b19e5500c35
4
+ data.tar.gz: 88a8343d3f76b4c2f26c44d77a2b643e760a5973
5
+ SHA512:
6
+ metadata.gz: a20bef1a00a8a084a0fc3274f59ecd4a7e8cb9cceb58ea4a3a23f27533e508b03fb8449e541c95bea886339eefd5aba097dc82934946c93c1ea3509836d83e6c
7
+ data.tar.gz: 564cc0f972a33830b20223727e733456ba7fb4ec3ec4836faecbf77b0c8ae734b564f4c5718738b1beb7317ea24cb36bed9e43b7a786d2ef27d4569ca67b695b
@@ -1,7 +1,11 @@
1
1
  <% unless abstract? %>
2
2
  <%= return_type.to_prim %> <%= seed.name %>::<%= name %>(<%= params.collect(&:stamp_decl).join ', ' %>)
3
3
  {
4
- // keep: <%= keep_name %>
4
+ // keep: <%= keep_name %> {
5
+ <% if returns_a_value? %>
6
+ return <%= return_type.default_lit %>;
7
+ <% end %>
8
+ // keep: }
5
9
  }
6
10
 
7
11
  <% end %>
@@ -1,7 +1,8 @@
1
+ <%= access %>:
1
2
  /**
2
3
  <%= desc %>
3
4
  <% params.each do |p| %>
4
5
  @param <%= p.name %> <%= p.desc %>
5
6
  <% end %>
6
7
  */
7
- <%= return_type.to_prim %> <%= name %>(<%= params.collect(&:stamp_decl).join ', ' %>)<% if abstract? %> = 0<% end %>;
8
+ <% if virtual? %>virtual <% end %><%= return_type.to_prim %> <%= name %>(<%= params.collect(&:stamp_decl).join ', ' %>)<% if abstract? %> = 0<% end %>;
@@ -2,6 +2,8 @@
2
2
 
3
3
  <%= guard %>
4
4
 
5
+ #include <string>
6
+
5
7
  <% if in_scope %>
6
8
  <%= named_scope_begin in_scope %>
7
9
  <% end %>
@@ -10,7 +10,7 @@ module Cog
10
10
 
11
11
  # @api developer
12
12
  def initialize(seed, name, opt={})
13
- @feature = Seed::Feature.new seed, name
13
+ @feature = Seed::Feature.new seed, name, opt
14
14
  end
15
15
 
16
16
  # Describe what this method does in one line
@@ -29,8 +29,34 @@ module Cog
29
29
  feature :destructor, &block
30
30
  end
31
31
 
32
+ # @api_developer
33
+ def respond_to?(meth)
34
+ meth.to_s.end_with?('_feature') || super(meth)
35
+ end
36
+
37
+ # @api developer
38
+ def method_missing(meth, *args, &block)
39
+ meth = meth.to_s
40
+ if meth.end_with? '_feature'
41
+ opt = args.last.is_a?(Hash) ? args.pop : {}
42
+ if /(?:\b|_)(public|protected|private)(?:\b|_)/ =~ meth
43
+ opt[:access] = $1.to_sym
44
+ end
45
+ if /(?:\b|_)(abstract|virtual)(?:\b|_)/ =~ meth
46
+ opt[$1.to_sym] = true
47
+ end
48
+ args << opt
49
+ feature(*args, &block)
50
+ else
51
+ super(meth, *args, &block)
52
+ end
53
+ end
54
+
32
55
  # Define a new feature for this seed
33
56
  # @param name [String] name of the feature
57
+ # @option opt [Symbol] :access (:private) one of `:public`, `:protected`, or `private`
58
+ # @option opt [Boolean] :abstract (false) is this an abstract feature? If so, no implementation will be generated
59
+ # @option opt [Boolean] :virtual (false) is this a virtual feature? Virtual features can be replaced in subclasses
34
60
  # @yieldparam f [FeatureDSL] use this to further specify the feature
35
61
  # @return [nil]
36
62
  def feature(name, opt={}, &block)
@@ -203,6 +203,32 @@ module Cog
203
203
  raise Errors::PrimitiveNotSupported.new :object => obj
204
204
  end
205
205
 
206
+ # @param name [Symbol] name of a primitive cog type
207
+ # @return [String] default value literal for the given primitive cog type
208
+ # @example
209
+ # # For C++
210
+ # lang.to_default_value :string # => '""'
211
+ def default_lit_for(name)
212
+ case name
213
+ when :boolean
214
+ to_boolean false
215
+ when :integer
216
+ to_integer 0
217
+ when :long
218
+ to_long 0
219
+ when :float
220
+ to_lit 0.0
221
+ when :double
222
+ to_double 0.0
223
+ when :char
224
+ to_char ''
225
+ when :string
226
+ to_string ''
227
+ when :null
228
+ to_null nil
229
+ end
230
+ end
231
+
206
232
  private
207
233
 
208
234
  # @api developer
@@ -43,7 +43,10 @@ class String
43
43
  # @api developer
44
44
  # @return [String, String] source and type, where type is one of <tt>:project</tt>, <tt>:user</tt>, <tt>:built_in</tt>, <tt>:gem</tt>, or <tt>:unknown</tt>
45
45
  def cog_source_and_type
46
- if start_with?(Cog.project_root) || start_with?(Cog.project_template_path) || start_with?(Cog.project_generator_path) || start_with?(Cog.project_plugin_path)
46
+ if ((Cog.project_root && start_with?(Cog.project_root)) ||
47
+ (Cog.project_template_path && start_with?(Cog.project_template_path)) ||
48
+ (Cog.project_generator_path && start_with?(Cog.project_generator_path)) ||
49
+ (Cog.project_plugin_path && start_with?(Cog.project_plugin_path)))
47
50
  [File.basename(Cog.project_root), :project]
48
51
  elsif start_with? Cog.user_dir
49
52
  [File.basename(ENV['HOME']), :user]
@@ -12,6 +12,14 @@ class Symbol
12
12
  def to_prim
13
13
  Cog.active_language.to_prim(self)
14
14
  end
15
+
16
+ # @return [String] assuming this symbol represents a cog primitive type, returns the literal representation of the default value for that type
17
+ # @example
18
+ # # For Objective-C
19
+ # :string.default_lit # => '@""'
20
+ def default_lit
21
+ Cog.active_language.default_lit_for(self)
22
+ end
15
23
  end
16
24
 
17
25
  # Helpers for {Bignum} and {Fixnum}
@@ -6,21 +6,34 @@ module Cog
6
6
 
7
7
  include Generator
8
8
 
9
+ # @api developer
10
+ # @return [Seed] seed to which this feature belongs
9
11
  attr_reader :seed
10
12
 
13
+ # @return [Symbol] access modifier. One of `:public`, `:protected`, or `:private`
14
+ attr_reader :access
15
+
11
16
  # @return [String] name of the method
12
17
  attr_reader :name
13
18
 
19
+ # @return [Array<Var>] list of parameters
14
20
  attr_reader :params
15
21
 
22
+ # @return [Symbol] the return type of the feature
16
23
  attr_reader :return_type
17
24
 
18
25
  # @api developer
19
- # @param name [String] name of the method
26
+ # @param seed [Seed] seed to which this feature belongs
27
+ # @param name [String] name of the feature
28
+ # @option opt [Symbol] :access (:private) one of `:public`, `:protected`, or `private`
29
+ # @option opt [Boolean] :abstract (false) is this an abstract feature? If so, no implementation will be generated. Note that all abstract features are virtual
30
+ # @option opt [Boolean] :virtual (false) is this a virtual feature? Virtual features can be replaced in subclasses
20
31
  def initialize(seed, name, opt={})
21
32
  @seed = seed
22
33
  @name = name.to_s.to_ident
23
- @abstract = false
34
+ @access = (opt[:access] || :private).to_sym
35
+ @abstract = !!opt[:abstract]
36
+ @virtual = !!opt[:virtual]
24
37
  @params = [] # [Var]
25
38
  @return_type = :void
26
39
  end
@@ -30,6 +43,16 @@ module Cog
30
43
  @abstract
31
44
  end
32
45
 
46
+ # @return [Boolean] is this a virtual method?
47
+ def virtual?
48
+ @abstract || @virtual
49
+ end
50
+
51
+ # @return [Boolean] does this feature return a value?
52
+ def returns_a_value?
53
+ @return_type != :void
54
+ end
55
+
33
56
  def desc
34
57
  @desc || 'Undocumented'
35
58
  end
@@ -6,17 +6,25 @@ module Cog
6
6
  # Points to the +cog+ command-line app
7
7
  class Runner
8
8
 
9
- # @param path_to_cl_app [String] path
10
- def initialize
11
- @cog = File.expand_path File.join(File.dirname(__FILE__), '..', '..', '..', 'bin', 'cog')
9
+ # @param exec_path [String] path to the executable
10
+ # @option opt [Array<String>] :flags (['--colorless']) command line flags to pass each time the executable is invoked
11
+ # @option opt [Boolean] :use_bundler (true) Should `bundle exec` prefix each invocation of the executable?
12
+ def initialize(exec_path = nil, opt={})
13
+ @exec_path = if exec_path
14
+ exec_path
15
+ else
16
+ File.expand_path File.join(File.dirname(__FILE__), '..', '..', '..', 'bin', 'cog')
17
+ end
18
+ @flags = opt[:flags] || ['--colorless']
19
+ @use_bundler = opt[:use_bundler].nil? ? true : opt[:use_bundler]
12
20
  end
13
21
 
14
22
  # Run cog with the given arguments
15
23
  # @param args [Array<String>] arguments to pass to +cog+
16
24
  # @return [Invocation] an object which can be used with custom {Matchers}
17
25
  def run(*args)
18
- args = [@cog, '--colorless'] + args
19
- Invocation.new(args.collect {|x| x.to_s})
26
+ cmd = ([@exec_path] + @flags + args).collect &:to_s
27
+ Invocation.new(cmd, :use_bundler => @use_bundler)
20
28
  end
21
29
  end
22
30
 
@@ -26,9 +34,11 @@ module Cog
26
34
  class Invocation
27
35
 
28
36
  # @api developer
29
- # @param cmd [Array<String>] path to +cog+ executable and arguments
37
+ # @param cmd [Array<String>]
38
+ # @option opt [Boolean] :use_bundler (false)
30
39
  def initialize(cmd, opt={})
31
40
  @cmd = cmd
41
+ @use_bundler = opt[:use_bundler]
32
42
  end
33
43
 
34
44
  # Execute the command
@@ -36,9 +46,10 @@ module Cog
36
46
  # @yield [stdin, stdout, stderr] standard pipes for the invocation
37
47
  # @return [nil]
38
48
  def exec(&block)
39
- @cmd = ['bundle', 'exec'] + @cmd
49
+ full_cmd = @cmd
50
+ full_cmd = ['bundle', 'exec'] + full_cmd if @use_bundler
40
51
  ENV['HOME'] = SpecHelpers.active_home_fixture_dir
41
- Open3.popen3 *@cmd do |i,o,e,t|
52
+ Open3.popen3 *full_cmd do |i,o,e,t|
42
53
  block.call i,o,e
43
54
  end
44
55
  end
@@ -1,5 +1,5 @@
1
1
  module Cog
2
2
  unless const_defined? :VERSION
3
- VERSION = '0.3.2'
3
+ VERSION = '0.3.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,143 +1,134 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cog
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 2
10
- version: 0.3.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Kevin Tonon
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2013-01-30 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2013-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: active_support
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
32
20
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: gli
36
21
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
46
34
  type: :runtime
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: i18n
50
35
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: i18n
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
60
48
  type: :runtime
61
- version_requirements: *id003
62
- - !ruby/object:Gem::Dependency
63
- name: rainbow
64
49
  prerelease: false
65
- requirement: &id004 !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rainbow
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
74
62
  type: :runtime
75
- version_requirements: *id004
76
- - !ruby/object:Gem::Dependency
77
- name: rake
78
63
  prerelease: false
79
- requirement: &id005 !ruby/object:Gem::Requirement
80
- none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- hash: 3
85
- segments:
86
- - 0
87
- version: "0"
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
88
76
  type: :development
89
- version_requirements: *id005
90
- - !ruby/object:Gem::Dependency
91
- name: redcarpet
92
77
  prerelease: false
93
- requirement: &id006 !ruby/object:Gem::Requirement
94
- none: false
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- hash: 3
99
- segments:
100
- - 0
101
- version: "0"
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: redcarpet
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
102
90
  type: :development
103
- version_requirements: *id006
104
- - !ruby/object:Gem::Dependency
105
- name: rspec
106
91
  prerelease: false
107
- requirement: &id007 !ruby/object:Gem::Requirement
108
- none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- hash: 3
113
- segments:
114
- - 0
115
- version: "0"
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
116
104
  type: :development
117
- version_requirements: *id007
118
- - !ruby/object:Gem::Dependency
119
- name: yard
120
105
  prerelease: false
121
- requirement: &id008 !ruby/object:Gem::Requirement
122
- none: false
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- hash: 3
127
- segments:
128
- - 0
129
- version: "0"
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
130
118
  type: :development
131
- version_requirements: *id008
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
132
125
  description:
133
126
  email: kevin@betweenconcepts.com
134
- executables:
127
+ executables:
135
128
  - cog
136
129
  extensions: []
137
-
138
130
  extra_rdoc_files: []
139
-
140
- files:
131
+ files:
141
132
  - bin/cog
142
133
  - BuiltIn.cogfile
143
134
  - LICENSE
@@ -196,37 +187,26 @@ files:
196
187
  - yard-templates/default/fulldoc/html/css/common.css
197
188
  homepage: https://github.com/ktonon/cog
198
189
  licenses: []
199
-
190
+ metadata: {}
200
191
  post_install_message:
201
192
  rdoc_options: []
202
-
203
- require_paths:
193
+ require_paths:
204
194
  - lib
205
195
  - lib
206
- required_ruby_version: !ruby/object:Gem::Requirement
207
- none: false
208
- requirements:
209
- - - ">="
210
- - !ruby/object:Gem::Version
211
- hash: 3
212
- segments:
213
- - 0
214
- version: "0"
215
- required_rubygems_version: !ruby/object:Gem::Requirement
216
- none: false
217
- requirements:
218
- - - ">="
219
- - !ruby/object:Gem::Version
220
- hash: 3
221
- segments:
222
- - 0
223
- version: "0"
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - '>='
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
224
206
  requirements: []
225
-
226
207
  rubyforge_project:
227
- rubygems_version: 1.8.24
208
+ rubygems_version: 2.0.3
228
209
  signing_key:
229
- specification_version: 3
210
+ specification_version: 4
230
211
  summary: This is a utility to help you write code generators.
231
212
  test_files: []
232
-