Skip to content

Commit

Permalink
Merge pull request #7 from DaveTD/0.7.0
Browse files Browse the repository at this point in the history
Move logic into private methods, add required fields, remove colons f…
  • Loading branch information
DaveTD committed Jan 25, 2016
2 parents b7054e0 + ee0e71b commit dd0c1cd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
31 changes: 22 additions & 9 deletions lib/generators/superstudio/schema_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,41 @@ def create_schema_file
column_type = column.type
column_type = :string if [:datetime].include? column.type
column_type = :number if [:decimal].include? column.type

model_columns[column.name] = column_type
end

file_data = %Q({
file_data = template_header
model_columns.each do |name, type|
file_data << data_column(name, type)
end

file_data = file_data.chomp(",")
file_data << template_footer

model_klass_name = model_klass.name.gsub(":", "")
create_file "app/json_schemas/#{model_klass_name}.json.schema", file_data
end

private
def template_header
%Q({
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Get a patient",
"type": "object",
"properties": {)
end

model_columns.each do |name, type|
file_data << %Q(
def data_column(name, type)
%Q(
"#{name}": {
"type": "#{type}"
},)
end
file_data = file_data.chomp(",")

file_data << "
def template_footer
%Q(
}
}"
create_file "app/json_schemas/#{model_klass}.json.schema", file_data
"required": ["id"]
})
end
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/generators/superstudio/schema_map_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def create_map_file
interpreted_hashes = []

interpreted_schema.template_bodies.each do |key, template|
# This is how JSON parse works? Thanks Obama.
inter = JSON.parse("{" << template.gsub("%", "").slice(1..template.length).chomp("}").gsub('{', '"').gsub('}', '"') << "}")
temp_string = PP.pp(inter, '')
interpreted_hashes << inter
Expand Down
2 changes: 1 addition & 1 deletion superstudio.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'superstudio'
s.version = '0.7.1'
s.version = '0.7.2'
s.date = '2016-01-04'
s.summary = "An alternative way of thinking about creating JSON output: life without creating ruby objects."
s.description = ""
Expand Down

0 comments on commit dd0c1cd

Please sign in to comment.