Class: Iut::Arc
- Inherits:
-
Object
- Object
- Iut::Arc
- Defined in:
- lib/iut/arc.rb
Instance Attribute Summary collapse
-
#project_path ⇒ Object
Returns the value of attribute project_path.
Class Method Summary collapse
Instance Method Summary collapse
- #arc?(class_name) ⇒ Boolean
- #change_project_settings ⇒ Object
- #clean ⇒ Object
-
#initialize ⇒ Arc
constructor
A new instance of Arc.
- #nonarc?(class_name) ⇒ Boolean
- #revert ⇒ Object
Constructor Details
#initialize ⇒ Arc
Returns a new instance of Arc.
11 12 13 |
# File 'lib/iut/arc.rb', line 11 def initialize @project_path = Dir.pwd end |
Instance Attribute Details
#project_path ⇒ Object
Returns the value of attribute project_path.
9 10 11 |
# File 'lib/iut/arc.rb', line 9 def project_path @project_path end |
Class Method Details
.parse ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/iut/arc.rb', line 121 def self.parse opt = OptionParser.new = {} opt.on('-p', '--project PROJECT', 'Set project path PROJECT.') {|v| [:PROJECT] = v } opt.parse!(ARGV) arc = self.new arc.project_path = [:PROJECT] if [:PROJECT] case ARGV[1] when /revert/ arc.revert when /clean/ arc.clean else arc.change_project_settings end end |
Instance Method Details
#arc?(class_name) ⇒ Boolean
51 52 53 |
# File 'lib/iut/arc.rb', line 51 def arc? class_name !self.nonarc? class_name end |
#change_project_settings ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/iut/arc.rb', line 55 def change_project_settings Dir.chdir self.project_path do Dir.glob("**/project.pbxproj") do |f| lines = [] xcbuild_config_section = false # backup FileUtils.cp f, "#{f}.#{ Time.now.strftime('%Y%m%d-%H%M%S') }" context = File.read f seted_arc_project_setting = /CLANG_ENABLE_OBJC_ARC/ =~ context context.each_line do |l| case l when /Begin XCBuildConfiguration section/ xcbuild_config_section = true when /End PBXBuildFile section/ xcbuild_config_section = false when /ARCHS/ unless seted_arc_project_setting l << "\t\t\t\tCLANG_ENABLE_OBJC_ARC = YES;\n" if xcbuild_config_section end when /(\S+)\.m.+in Sources.*isa = PBXBuildFile/i class_name = $1 unless /settings/ =~ l if nonarc? class_name l.gsub!("};\n", "settings = {COMPILER_FLAGS = \"-fno-objc-arc\"; }; };\n") end end end lines << l end File.open(f, "w") do |f| f.write lines.join end end end end |
#clean ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/iut/arc.rb', line 107 def clean Dir.chdir self.project_path do files = [] Dir.glob("**/project.pbxproj.*") do |f| files << f if /project.pbxproj.\d{8}\-\d{6}/ =~ f end unless files.size == 0 files.each do |f| FileUtils.rm f end end end end |
#nonarc?(class_name) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/iut/arc.rb', line 15 def nonarc? class_name return false if class_name == "NSObject" super_name = "NSObject" Dir.glob("**/#{class_name}\.[hm]") do |f| context = File.read f # remove comments context.gsub! /\/\/.*\n/, "" context.gsub! /\/\*.*\*\//m, "" # remove spaces context.gsub! /\s+/, " " case f[-2, 2] when /.h/i # get a name of super class a = context.scan(/@interface.*:\s(\S+)/) super_name = a.first.first if a.first case context when /@property\s*\(.*copy(\s*|\]|\))/, /@property\s*\(.*retain(\s*|\]|\))/ return true end when /.m/i case context when /\s+dealloc(\s*|\])/, /\s+autorelease(\s*|\])/, /\s+dealloc(\s*|\])/, /\s+release(\s*|\])/ return true end end end nonarc? super_name end |
#revert ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/iut/arc.rb', line 93 def revert Dir.chdir self.project_path do files = [] Dir.glob("**/project.pbxproj.*") do |f| files << f if /project.pbxproj.\d{8}\-\d{6}/ =~ f end unless files.size == 0 f = files.sort.reverse.first FileUtils.cp f, Dir.glob("**/project.pbxproj").first FileUtils.rm f end end end |