Skip to content

Commit 4059548

Browse files
committed
cdqi tool now works
1 parent 895c828 commit 4059548

File tree

3 files changed

+29
-41
lines changed

3 files changed

+29
-41
lines changed

Examples/TopHits/TopHits/ArtistAttribute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Generated by CDQI on 2016-10-09.
2+
// Generated by CDQI on 2016-10-14.
33
//
44
// This file was generated by a tool. Further invocations of this tool will overwrite this file.
55
// Edit it at your own risk.

Examples/TopHits/TopHits/SongAttribute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Generated by CDQI on 2016-10-09.
2+
// Generated by CDQI on 2016-10-14.
33
//
44
// This file was generated by a tool. Further invocations of this tool will overwrite this file.
55
// Edit it at your own risk.

bin/cdqi

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -87,73 +87,61 @@ class IndentWriter
8787
end
8888

8989
class Attribute
90-
attr_reader :name, :entity, :type
9190
def initialize(name, entity: nil, type: nil)
9291
@name = name
9392
@entity = entity
9493
@type = type
9594
end
96-
def render_property(io)
97-
if attribute_class =~ /^Numeric/
98-
io.puts "#{$options.access_modifier}private(set) lazy var #{@name}: #{attribute_class} = { #{attribute_class}(\"#{@name}\", parent: self, type: #{attribute_type}) }()"
99-
else
100-
io.puts "#{$options.access_modifier}private(set) lazy var #{@name}: #{attribute_class} = { #{attribute_class}(\"#{@name}\", parent: self) }()"
101-
end
102-
end
103-
def attribute_type
104-
case @type
105-
when 'Binary' then '.BinaryDataAttributeType'
106-
when 'Boolean' then '.BooleanAttributeType'
107-
when 'Date' then '.DateAttributeType'
108-
when 'Decimal' then '.DecimalAttributeType'
109-
when 'Double' then '.DoubleAttributeType'
110-
when 'Float' then '.FloatAttributeType'
111-
when 'Integer 16' then '.Integer16AttributeType'
112-
when 'Integer 32' then '.Integer32AttributeType'
113-
when 'Integer 64' then '.Integer64AttributeType'
114-
when 'String' then '.StringAttributeType'
115-
else 'nil'
116-
end
117-
end
118-
def attribute_class
119-
prefix = ""
120-
unless @type.nil?
121-
type_downcased = @type.downcase
122-
if ["integer", "float", "double", "decimal"].any? { |type| type_downcased.include? type }
123-
prefix = "Numeric"
124-
elsif type_downcased == "binary"
125-
prefix = "Data"
95+
96+
def attribute_class_name
97+
prefix = ''
98+
if @type
99+
case @type
100+
when 'Binary' then 'DateAttribute'
101+
when 'Boolean' then 'BooleanAttribute'
102+
when 'Date' then 'DateAttribute'
103+
when 'Decimal' then 'DecimalAttribute'
104+
when 'Double' then 'DoubleAttribute'
105+
when 'Float' then 'FloatAttribute'
106+
when 'Integer 16' then 'Integer16Attribute'
107+
when 'Integer 32' then 'Integer32Attribute'
108+
when 'Integer 64' then 'Integer64Attribute'
109+
when 'String' then 'StringAttribute'
126110
else
127-
prefix = @type
111+
raise @type
128112
end
129113
else
130-
prefix = "#{@entity || 'Key'}"
114+
"#{@entity}#{$options.suffix}"
131115
end
132-
"#{prefix}#{$options.suffix}"
116+
end
117+
118+
def render(io)
119+
io.puts "#{$options.access_modifier}private(set) lazy var #{@name}: #{attribute_class_name} = { #{attribute_class_name}(key: \"#{@name}\", parent: self) }()"
133120
end
134121
end
135122

136123
class Entity
137-
attr_reader :name
124+
attr_reader :name, :entity_class_name
138125
def initialize(name)
139126
@name = name
140127
@attributes = []
128+
@entity_class_name = "#{@name}#{$options.suffix}"
141129
end
142130
def <<(attribute)
143131
@attributes << attribute
144132
end
145133
def render(io)
146-
io.puts "#{$options.access_modifier}class #{@name}#{$options.suffix}: EntityAttribute, Aggregable {"
134+
io.puts "#{$options.access_modifier}final class #{@entity_class_name}: EntityAttribute, Subqueryable {"
147135
io.indent do
148136
@attributes.each do |attribute|
149-
attribute.render_property(io)
137+
attribute.render(io)
150138
end
151139
end
152140
io.puts "}"
153141
io.puts ""
154-
io.puts "extension #{@name}: EntityType {"
142+
io.puts "extension #{@name}: Entity {"
155143
io.indent do
156-
io.puts "#{$options.access_modifier}typealias EntityAttributeType = #{@name}#{$options.suffix}"
144+
io.puts "#{$options.access_modifier}typealias CDQIAttribute = #{@entity_class_name}"
157145
end
158146
io.puts "}"
159147
io.puts ""

0 commit comments

Comments
 (0)