Module: Ycn

Defined in:
lib/ycn.rb,
lib/ycn/ycn.rb,
lib/ycn/version.rb

Defined Under Namespace

Modules: VERSION

Class Method Summary collapse

Class Method Details

.generate(language, config) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ycn/ycn.rb', line 4

def self.generate language, config
  $base_dir = Dir.pwd

  Header.configure_from config
  config[:package] =
    config[:package].to_s.gsub(' ', '_')
  
  config[:getters] = true unless config.has_key? :getters
  config[:setters] = true unless config.has_key? :setters
  config[:constructors] = true unless config.has_key? :constructors
  
  configatron { |c|
    c.package = config[:package]
    c.getters = config[:getters]
    c.setters = config[:setters]
    c.lang = language
  }
  
  classes_yaml = YAML::load(
    correct_for_blank_last_method( open(
      "#{$base_dir}/pcg/#{config[:package]}.yml")))

  classes = []

  classes_yaml.each_pair do |class_name, attr_hash|
    classes << attribute_hash_to_class( class_name, attr_hash )
  end

  fix_inheritance_and_overrides classes
  
  package_name = "pcg#{camelize configatron.package}"
  output_dir = "#{$base_dir}/#{package_name}"
  
  Dir.mkdir output_dir unless File.exists? output_dir

  classes.each do |klass|
    
    template = open( "#{File.dirname(__FILE__)}/#{language}/#{language}_class.erb" ).read
    
    file_name = "#{klass.name}.#{extension[language]}"
    
    File.open( "#{output_dir}/#{file_name}", 'w' ) { |f|
      content = klass.print_to( template )
      f.print content
      puts content
      #~ pp klass
    }
  end
end