Class: GoNative::Plugins::IOS::Rename

Inherits:
Object
  • Object
show all
Extended by:
DSL::Serviceable
Defined in:
lib/gonative/plugins/ios/rename.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Rename

Returns a new instance of Rename.



13
14
15
# File 'lib/gonative/plugins/ios/rename.rb', line 13

def initialize(name)
  @name = name.gsub(/[^0-9a-zA-Z]/, '')
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/gonative/plugins/ios/rename.rb', line 11

def name
  @name
end

#projObject (readonly)

Returns the value of attribute proj.



11
12
13
# File 'lib/gonative/plugins/ios/rename.rb', line 11

def proj
  @proj
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
# File 'lib/gonative/plugins/ios/rename.rb', line 17

def call
  system("mv MedianIOS.xcodeproj #{proj_path}")
  @proj = Xcodeproj::Project.open(proj_path)
  rename_target!
  recreate_scheme!
  fix_workspace_refs!
  system('pod install')
end

#fix_workspace_refs!Object



46
47
48
49
50
51
52
# File 'lib/gonative/plugins/ios/rename.rb', line 46

def fix_workspace_refs!
  FileUtils.rm_rf('MedianIOS.xcworkspace')
  proj_ref = Xcodeproj::Workspace::FileReference.new(proj_path)
  pods_ref = Xcodeproj::Workspace::FileReference.new('Pods/Pods.xcodeproj')
  workspace = Xcodeproj::Workspace.new(nil, proj_ref, pods_ref)
  workspace.save_as(workspace_path)
end

#recreate_scheme!Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gonative/plugins/ios/rename.rb', line 31

def recreate_scheme!
  schemes_dir = Xcodeproj::XCScheme.shared_data_dir(proj_path)
  FileUtils.rm_rf(schemes_dir)
  FileUtils.mkdir_p(schemes_dir)

  scheme = Xcodeproj::XCScheme.new
  target = proj.targets.first

  test_target = target if target.respond_to?(:test_target_type?) && target.test_target_type?
  launch_target = target.respond_to?(:launchable_target_type?) && target.launchable_target_type?
  scheme.configure_with_targets(target, test_target, launch_target: launch_target)

  scheme.save_as(proj_path, target.name, true)
end

#rename_target!Object



26
27
28
29
# File 'lib/gonative/plugins/ios/rename.rb', line 26

def rename_target!
  proj.targets.first.name = name
  proj.save
end