Class: CoreDataMotion::FileWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/core_data_motion/file_writer.rb

Instance Method Summary collapse

Instance Method Details

#create_model_definitionObject



28
29
30
31
32
33
34
# File 'lib/core_data_motion/file_writer.rb', line 28

def create_model_definition
  Dir.glob("./settings/*.rb") { |filename| load filename }
  FileUtils.mkpath path_to_model_contents
  File.open(model_contents_path, "w") do |f|
    f.puts model_xml_content
  end
end

#entity_definition_class_nameObject



3
4
5
6
7
# File 'lib/core_data_motion/file_writer.rb', line 3

def entity_definition_class_name
  @entity_definition_class_name ||= begin
    Object.const_get file_prefix.split("_").map(&:capitalize).join
  end
end

#file_prefixObject



9
10
11
# File 'lib/core_data_motion/file_writer.rb', line 9

def file_prefix
  @file_prefix ||= "model_definition"
end

#model_contents_pathObject



18
19
20
# File 'lib/core_data_motion/file_writer.rb', line 18

def model_contents_path
  @model_contents_path ||= "#{path_to_model_contents}/contents"
end

#model_xml_contentObject



22
23
24
25
26
# File 'lib/core_data_motion/file_writer.rb', line 22

def model_xml_content
  tmp_instance = entity_definition_class_name.new
  tmp_instance.define_model
  tmp_instance.to_xml
end

#path_to_model_contentsObject



13
14
15
16
# File 'lib/core_data_motion/file_writer.rb', line 13

def path_to_model_contents
  @path_to_model_contents ||=
    "./resources/#{file_prefix}.xcdatamodeld/#{file_prefix}.xcdatamodel"
end