Class: MetaModel::Installer::Renderer
- Inherits:
-
Object
- Object
- MetaModel::Installer::Renderer
- Includes:
- Config::Mixin
- Defined in:
- lib/metamodel/installer/renderer.rb
Instance Attribute Summary collapse
-
#associations ⇒ Object
readonly
Returns the value of attribute associations.
-
#models ⇒ Object
readonly
Returns the value of attribute models.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Instance Method Summary collapse
-
#initialize(models, associations) ⇒ Renderer
constructor
A new instance of Renderer.
- #remove_previous_files_refereneces ⇒ Object
- #render! ⇒ Object
- #render_association_files ⇒ Object
- #render_model_files ⇒ Object
Methods included from Config::Mixin
Constructor Details
Instance Attribute Details
#associations ⇒ Object (readonly)
Returns the value of attribute associations.
11 12 13 |
# File 'lib/metamodel/installer/renderer.rb', line 11 def associations @associations end |
#models ⇒ Object (readonly)
Returns the value of attribute models.
10 11 12 |
# File 'lib/metamodel/installer/renderer.rb', line 10 def models @models end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
8 9 10 |
# File 'lib/metamodel/installer/renderer.rb', line 8 def project @project end |
Instance Method Details
#remove_previous_files_refereneces ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/metamodel/installer/renderer.rb', line 30 def remove_previous_files_refereneces target = @project.targets.first @models.each do |model| target.source_build_phase.files_references.each do |file_ref| target.source_build_phase.remove_file_reference(file_ref) if file_ref && "#{model.name}.swift" == file_ref.name end end @associations.each do |association| target.source_build_phase.files_references.each do |file_ref| target.source_build_phase.remove_file_reference(file_ref) if file_ref && "#{association.class_name}.swift" == file_ref.name end end end |
#render! ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/metamodel/installer/renderer.rb', line 19 def render! remove_previous_files_refereneces UI.section "Generating model files" do render_model_files end UI.section "Generating association files" do render_association_files end @project.save end |
#render_association_files ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/metamodel/installer/renderer.rb', line 68 def render_association_files target = @project.targets.first association_group = @project.main_group.find_subpath('MetaModel/Associations', true) association_group.clear association_group.set_source_tree('SOURCE_ROOT') file_refs = [] @associations.each do |association| template = association.relation == :has_many ? has_many_association_template : belongs_to_association_template result = ErbalTemplate::render_from_hash(template, { :association => association }) file_name = "#{association.class_name}.swift" File.write Pathname.new("./metamodel/MetaModel/#{file_name}"), result file_refs << association_group.new_reference(Pathname.new("MetaModel/#{file_name}")) UI. '-> '.green + "Using #{file_name} file" end target.add_file_references file_refs end |
#render_model_files ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/metamodel/installer/renderer.rb', line 46 def render_model_files target = @project.targets.first models_group = @project.main_group.find_subpath('MetaModel/Models', true) models_group.clear models_group.set_source_tree('SOURCE_ROOT') file_refs = [] @models.each do |model| result = model_swift_templates.map { |template| ErbalTemplate::render_from_hash(template, { :model => model }) }.join("\n") model_path = Pathname.new("./metamodel/MetaModel/#{model.name}.swift") File.write model_path, result file_refs << models_group.new_reference(Pathname.new("MetaModel/#{model.name}.swift")) UI. '-> '.green + "Using #{model.name}.swift file" end target.add_file_references file_refs end |