Class: XCDM::Schema::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/xcdm/schema.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, inpath, outpath) ⇒ Runner

Returns a new instance of Runner.



68
69
70
71
72
73
# File 'lib/xcdm/schema.rb', line 68

def initialize(name, inpath, outpath)
  @inpath = inpath
  @name = name
  @container_path = File.join(outpath, "#{name}.xcdatamodeld")
  @loader = Loader.new
end

Instance Method Details

#datamodel_file(version) ⇒ Object



75
76
77
78
79
# File 'lib/xcdm/schema.rb', line 75

def datamodel_file(version)
  dir = File.join(@container_path, "#{version}.xcdatamodel")
  FileUtils.mkdir_p(dir)
  File.join(dir, 'contents')
end

#load_allObject



81
82
83
84
85
86
87
88
# File 'lib/xcdm/schema.rb', line 81

def load_all
  Dir["#{@inpath}/*.rb"].each do |file|
    if File.file?(file)
      puts "loading #{file}..."
      @loader.load_file(file)
    end
  end
end

#write_allObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/xcdm/schema.rb', line 90

def write_all
  @loader.schemas.each do |schema|
    filename = datamodel_file(schema.version)
    puts "writing #{filename}"
    File.open(filename, "w+") do |f|
      f.write(schema.to_xml)
    end
  end

  max = @loader.schemas.map(&:version).max
  File.open(File.join(@container_path, ".xccurrentversion"), "w+") do |f|
    f.write({ "_XCCurrentVersionName" => "#{max}.xcdatamodel" }.to_plist)
  end

end