Class: ManifestGenerator
Instance Method Summary
collapse
#_append, _use_by_files, _use_by_models, #get_classname, #get_pluralized_name, #get_singular_name, #get_type, #get_value, #id_type, #indent, is_file_based?, #make_block, #null_id, #order_by, prepare, #ptr_type, #reset, #resource_name, #should_generate_for, #should_generate_from_manifest, #should_skip_on_client?, sourcefile_to_destfile, #unindent, use, #visibility
Constructor Details
Returns a new instance of ManifestGenerator.
6
7
8
|
# File 'lib/metarecord/manifest_generator.rb', line 6
def initialize
@manifest_data = {}
end
|
Instance Method Details
#generate(output) ⇒ Object
10
11
12
13
14
15
16
17
18
|
# File 'lib/metarecord/manifest_generator.rb', line 10
def generate output
Model.list.each do |model|
@manifest_data[model[:name]] = @current_manifest_item = Hash.new
self.instance_eval &model[:block]
end
File.open output, 'w' do |f|
f.write JSON.pretty_generate(@manifest_data)
end
end
|
#has_many(type, name, options = {}) ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/metarecord/manifest_generator.rb', line 34
def has_many type, name, options = {}
if options[:joined] == false
db_options = options[:db] || Hash.new
column_name = db_options[:column] || "#{get_singular_name name}_id"
db_options.delete :column
@current_manifest_item[column_name] = { type: "INTEGER[]", options: db_options }
end
end
|
#has_one(type, name, options = {}) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/metarecord/manifest_generator.rb', line 27
def has_one type, name, options = {}
db_options = options[:db] || Hash.new
column_name = db_options[:column] || "#{name}_id"
db_options.delete :column
@current_manifest_item[column_name] = { type: "Crails::Odb::id_type", options: db_options }
end
|
#property(type, name, options = {}) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/metarecord/manifest_generator.rb', line 20
def property type, name, options = {}
db_options = options[:db] || Hash.new
column_name = db_options[:column] || name
db_options.delete :column
@current_manifest_item[column_name] = { type: type, options: db_options }
end
|