class AndroidXml::XmlFile

Attributes

filename[R]

Public Class Methods

new(filename, &block) click to toggle source
Calls superclass method
# File lib/android-xml/file.rb, line 10
def initialize(filename, &block)
  @filename = filename
  super(nil, &block)
  AndroidXml.files << self
end

Public Instance Methods

generate() click to toggle source
# File lib/android-xml/file.rb, line 26
def generate
  output = "<!-- Do not edit this file. It was generated by AndroidXml. -->\n"
  output << generate_block
end
method_missing(method_name, attrs={}, &block) click to toggle source
Calls superclass method
# File lib/android-xml/file.rb, line 16
def method_missing(method_name, attrs={}, &block)
  if @root
    raise "There can be only one (new: #{method_name}, old: #{@root})"
  end

  @root = super
  @root.is_root = true
  @root
end
out() click to toggle source
Calls superclass method
# File lib/android-xml/file.rb, line 31
def out
  puts "---- filename: #{@filename} ----"
  super
  puts "---------------#{'-' * @filename.to_s.length}-----"
end
write() click to toggle source
# File lib/android-xml/file.rb, line 37
def write
  dirname = File.dirname(self.filename)

  unless File.exists?(dirname)
    warn "\033[33m⚑\033[0m mkdir -p #{dirname}"
    FileUtils.mkdir_p(dirname)
  end

  File.open(self.filename, 'w') do |f|
    f.write(self.to_s)
  end
  warn "\033[32m✓\033[0m created #{self.filename}"
end