Class: MetaModel::Command::Install

Inherits:
MetaModel::Command show all
Includes:
MetaModel::Config::Mixin
Defined in:
lib/metamodel/command/install.rb,
lib/metamodel/installer/validator.rb

Defined Under Namespace

Classes: Validator

Constant Summary

Constants inherited from MetaModel::Command

METAMODEL_COMMAND_ALIAS, METAMODEL_OPTION_ALIAS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MetaModel::Config::Mixin

#config

Methods inherited from MetaModel::Command

#installer_for_config, options, run

Constructor Details

#initialize(argv) ⇒ Install

Returns a new instance of Install.



15
16
17
18
# File 'lib/metamodel/command/install.rb', line 15

def initialize(argv)
  validate!
  super
end

Instance Attribute Details

#modelsObject

Returns the value of attribute models.



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

def models
  @models
end

Instance Method Details

#clone_projectObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/metamodel/command/install.rb', line 36

def clone_project
  if File.exist? config.metamodel_xcode_project
    UI.message "Existing project `#{config.metamodel_xcode_project}`"
  else
    UI.section "Cloning MetaModel project into `./metamodel` folder" do
      Git.clone(config.metamodel_template_uri, 'metamodel', :depth => 1)
      UI.message "Using `#{config.metamodel_xcode_project}` to build module"
    end
  end
end

#integrate_to_projectObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/metamodel/command/install.rb', line 47

def integrate_to_project
  xcodeprojs = Dir.glob("#{config.installation_root}/*.xcodeproj")
  project = Xcodeproj::Project.open(xcodeprojs.first)
  target = project.targets.first
  return if target.build_phases.find { |build_phase| build_phase.to_s == "[MetaModel] Embedded Frameworks"}

  # Get useful variables
  frameworks_group = project.main_group.find_subpath('MetaModel', true)
  frameworks_group.clear
  frameworks_group.set_source_tree('SOURCE_ROOT')
  frameworks_build_phase = target.build_phases.find { |build_phase| build_phase.to_s == 'FrameworksBuildPhase' }

  # Add new "Embed Frameworks" build phase to target
  embedded_frameworks_build_phase = project.new(Xcodeproj::Project::Object::PBXCopyFilesBuildPhase)
  embedded_frameworks_build_phase.name = '[MetaModel] Embedded Frameworks'
  embedded_frameworks_build_phase.symbol_dst_subfolder_spec = :frameworks
  target.build_phases << embedded_frameworks_build_phase

  # Add framework to target as "Embedded Frameworks"
  framework_ref = frameworks_group.new_file("./MetaModel.framework")
  build_file = embedded_frameworks_build_phase.add_file_reference(framework_ref)
  frameworks_build_phase.add_file_reference(framework_ref)
  build_file.settings = { 'ATTRIBUTES' => ['CodeSignOnCopy', 'RemoveHeadersOnCopy'] }
  project.save
end

#prepareObject



32
33
34
# File 'lib/metamodel/command/install.rb', line 32

def prepare
  clone_project
end

#runObject



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

def run
  UI.section "Building MetaModel.framework in project" do
    prepare
    installer = installer_for_config
    installer.install!
  end
  UI.section "Copying MetaModel.framework into Embedded Binaries phrase." do
    integrate_to_project
  end
  # UI.notice "Please drag MetaModel.framework into Embedded Binaries phrase.\n"
end

#validate!Object

Raises:



73
74
75
76
# File 'lib/metamodel/command/install.rb', line 73

def validate!
  # super
  raise Informative, 'No Metafile in current directory' unless config.metafile_in_dir(Pathname.pwd)
end