Class: DataMapper::MetaMapper::Generators::CPP

Inherits:
DataMapper::MetaMapper::Generator show all
Defined in:
lib/dm-metamapper/generators/cpp.rb

Instance Attribute Summary

Attributes inherited from DataMapper::MetaMapper::Generator

#model

Instance Method Summary collapse

Methods inherited from DataMapper::MetaMapper::Generator

[], generator_name, #initialize, run, #run

Constructor Details

This class inherits a constructor from DataMapper::MetaMapper::Generator

Instance Method Details

#child_key(child_model) ⇒ Object



48
49
50
51
52
# File 'lib/dm-metamapper/generators/cpp.rb', line 48

def child_key(child_model)
  child_model.relationships.select {|m|
    m.class.name == 'DataMapper::Associations::ManyToOne::Relationship' && m.parent_model_name == model.name
  }.first.child_key.first.name.to_s
end

#key_to_parentObject



41
42
43
44
45
46
# File 'lib/dm-metamapper/generators/cpp.rb', line 41

def key_to_parent
  many_to_one.inject({}) do |hash, (r,m)|
    hash[m.child_key.first.name] = decolonize(m.parent_model_name.to_const_string)
    hash
  end
end

#output_path(model, template) ⇒ Object



54
55
56
57
# File 'lib/dm-metamapper/generators/cpp.rb', line 54

def output_path(model, template)
  name = model ? template.name.sub("%model%", decolonize(model.name)) : template.name
  File.join(self.class.config.output_dir, name)
end