Class: MetaModel::Installer

Inherits:
Object
  • Object
show all
Includes:
Config::Mixin
Defined in:
lib/metamodel/installer.rb,
lib/metamodel/installer/renderer.rb

Defined Under Namespace

Classes: Renderer

Constant Summary collapse

BUILD_PRODUCTS_FOLDER =
"./metamodel/Build/Products"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Config::Mixin

#config

Constructor Details

#initialize(metafile) ⇒ Installer

Returns a new instance of Installer.



15
16
17
# File 'lib/metamodel/installer.rb', line 15

def initialize(metafile)
  @metafile = metafile
end

Instance Attribute Details

#associationsObject

Returns the value of attribute associations.



11
12
13
# File 'lib/metamodel/installer.rb', line 11

def associations
  @associations
end

#current_modelObject

Returns the value of attribute current_model.



13
14
15
# File 'lib/metamodel/installer.rb', line 13

def current_model
  @current_model
end

#metafileObject (readonly)

Returns the value of attribute metafile.



8
9
10
# File 'lib/metamodel/installer.rb', line 8

def metafile
  @metafile
end

#modelsObject

Returns the value of attribute models.



10
11
12
# File 'lib/metamodel/installer.rb', line 10

def models
  @models
end

Instance Method Details

#build_framework_on_iphoneosObject

Raises:



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/metamodel/installer.rb', line 55

def build_framework_on_iphoneos
  build_iphoneos = "xcodebuild -scheme MetaModel \
    -project MetaModel/MetaModel.xcodeproj \
    -configuration Release -sdk iphoneos \
    -derivedDataPath './metamodel' \
    BITCODE_GENERATION_MODE=bitcode \
    ONLY_ACTIVE_ARCH=NO \
    CODE_SIGNING_REQUIRED=NO \
    CODE_SIGN_IDENTITY= \
    clean build"
  result = system "#{build_iphoneos} > /dev/null"
  raise Informative, 'Building framework on iphoneos failed.' unless result
end

#build_framework_on_iphonesimulatorObject

Raises:



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/metamodel/installer.rb', line 69

def build_framework_on_iphonesimulator
  build_iphonesimulator = "xcodebuild -scheme MetaModel \
    -project MetaModel/MetaModel.xcodeproj \
    -configuration Release -sdk iphonesimulator \
    -derivedDataPath './metamodel' \
    ONLY_ACTIVE_ARCH=NO \
    CODE_SIGNING_REQUIRED=NO \
    CODE_SIGN_IDENTITY= \
    clean build"
    result = system "#{build_iphonesimulator} > /dev/null"
    raise Informative, 'Building framework on iphonesimulator failed.' unless result
end

#build_metamodel_frameworkObject



45
46
47
48
49
50
51
52
53
# File 'lib/metamodel/installer.rb', line 45

def build_metamodel_framework
  UI.section "Generating MetaModel.framework" do
    build_framework_on_iphoneos
    build_framework_on_iphonesimulator
    copy_framework_swiftmodule_files
    lipo_frameworks_on_different_archs
  end
  UI.message "-> ".green + "MetaModel.framework located in current folder"
end

#copy_framework_swiftmodule_filesObject



84
85
86
87
88
89
# File 'lib/metamodel/installer.rb', line 84

def copy_framework_swiftmodule_files
  copy_command = "cp -rf #{BUILD_PRODUCTS_FOLDER}/Release-iphoneos/MetaModel.framework . && \
    cp -rf #{BUILD_PRODUCTS_FOLDER}/Release-iphonesimulator/MetaModel.framework/Modules/MetaModel.swiftmodule/* \
            MetaModel.framework/Modules/MetaModel.swiftmodule/"
  system copy_command
end

#install!Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/metamodel/installer.rb', line 19

def install!
  @models = metafile.models
  @associations = metafile.associations
  Renderer.new(@models, @associations).tap do |renderer|
    renderer.render!
  end

  update_initialize_method
  update_packing_file
  build_metamodel_framework unless config.skip_build?
end

#lipo_frameworks_on_different_archsObject

Raises:



91
92
93
94
95
96
97
# File 'lib/metamodel/installer.rb', line 91

def lipo_frameworks_on_different_archs
  lipo_command = "lipo -create -output MetaModel.framework/MetaModel \
    #{BUILD_PRODUCTS_FOLDER}/Release-iphonesimulator/MetaModel.framework/MetaModel \
    #{BUILD_PRODUCTS_FOLDER}/Release-iphoneos/MetaModel.framework/MetaModel"
  result = system "#{lipo_command}"
  raise Informative, 'Copy framework to current folder failed.' unless result
end

#update_initialize_methodObject



31
32
33
34
35
36
# File 'lib/metamodel/installer.rb', line 31

def update_initialize_method
  template = File.read File.expand_path(File.join(File.dirname(__FILE__), "./template/metamodel.swift"))
  result = ErbalTemplate::render_from_hash(template, { :models => @models, :associations => @associations })
  model_path = Pathname.new("./metamodel/MetaModel/MetaModel.swift")
  File.write model_path, result
end

#update_packing_fileObject



38
39
40
41
42
43
# File 'lib/metamodel/installer.rb', line 38

def update_packing_file
  template = File.read File.expand_path(File.join(File.dirname(__FILE__), "./template/packing.swift"))
  result = ErbalTemplate::render_from_hash(template, { :models => @models, :associations => @associations })
  model_path = Pathname.new("./metamodel/MetaModel/Packing.swift")
  File.write model_path, result
end