Class: Guard::Xcoder
Constant Summary collapse
- VERSION =
'0.1.0'
Instance Method Summary collapse
- #create_guard_for(full_source_path, command) ⇒ Object
- #default_builder_actions ⇒ Object
- #default_paths ⇒ Object
-
#file_watchers_for_project_watchers(watchers) ⇒ Array<Watcher>
A new list of watchers for every file within the matching project > target.
-
#initialize(watchers = [], options = {}) ⇒ Xcoder
constructor
A new instance of Xcoder.
- #projects ⇒ Object
- #run_all ⇒ Object
- #run_on_change(commands) ⇒ Object
- #start ⇒ Object
- #targets_in_path(pattern) ⇒ Object
- #watchers_for_source_files_in(pattern) ⇒ Object
Constructor Details
#initialize(watchers = [], options = {}) ⇒ Xcoder
Returns a new instance of Xcoder.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/guard/xcoder.rb', line 18 def initialize(watchers=[], = {}) @options = { :actions => default_builder_actions, :paths => default_paths, }.update() @paths = @options[:paths] file_watchers = file_watchers_for_project_watchers watchers watchers.replace file_watchers super end |
Instance Method Details
#create_guard_for(full_source_path, command) ⇒ Object
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/guard/xcoder.rb', line 131 def create_guard_for full_source_path, command relative_source_path = full_source_path.gsub("#{::Guard.listener.directory}/",'') # Given a file that is meant for the sources build phase, it # is likely that the file has an accompanying header file so # we expand the pattern to include that. source_regex = Regexp.new( Regexp.escape(relative_source_path).to_s.gsub(/(?:m?m)$/,'(?:m?m|h)') ) ::Guard::Watcher.new(source_regex,command) end |
#default_builder_actions ⇒ Object
10 11 12 |
# File 'lib/guard/xcoder.rb', line 10 def default_builder_actions [ :build ] end |
#default_paths ⇒ Object
14 15 16 |
# File 'lib/guard/xcoder.rb', line 14 def default_paths [ '.' ] end |
#file_watchers_for_project_watchers(watchers) ⇒ Array<Watcher>
Returns a new list of watchers for every file within the matching project > target. Each watcher when matched will return a path to the project//target//config that needs to be built.
79 80 81 82 83 84 85 |
# File 'lib/guard/xcoder.rb', line 79 def file_watchers_for_project_watchers(watchers) watchers.map do |watcher| watchers_for_source_files_in(watcher.pattern) end.flatten.compact end |
#projects ⇒ Object
66 67 68 69 70 71 |
# File 'lib/guard/xcoder.rb', line 66 def projects @project ||= begin # TODO: projects found multiple times will be duplicated. @paths.map {|path| Xcode.find_projects path }.flatten.compact end end |
#run_all ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/guard/xcoder.rb', line 36 def run_all projects.each do |project| project.targets.each do |target| config = target.config('Debug') UI.info(("*" * 80)) UI.info "Building #{project.name} - #{target.name} - #{config.name}" UI.info(("*" * 80)) config.builder.build end end end |
#run_on_change(commands) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/guard/xcoder.rb', line 53 def run_on_change(commands) project_name, target_name, config_name = commands.first.split("//") builder = Xcode.project(project_name).target(target_name).config(config_name).builder UI.info "[Guard::Xcoder] Performing [ #{@options[:actions].join(", ")} ] for #{project_name} > #{target_name} > #{config_name}" Array(@options[:actions]).each do |operation| builder.send(operation) end end |
#start ⇒ Object
31 32 33 34 |
# File 'lib/guard/xcoder.rb', line 31 def start projects UI.info "[Guard::Xcoder] is now monitoring #{projects.map {|p| p.name }.join(", ")}" end |
#targets_in_path(pattern) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/guard/xcoder.rb', line 118 def targets_in_path(pattern) project_name, target_name, config_name = pattern.split("//") projects.find_all {|project| project.name == project_name }.map do |project| if target_name project.targets.find_all {|target| target.name == target_name } else project.targets end end.flatten.compact end |
#watchers_for_source_files_in(pattern) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/guard/xcoder.rb', line 87 def watchers_for_source_files_in pattern targets_in_path(pattern).map do |target| # TODO: this is currently hard-coded to Debug configuration, though the user can specify Release build_action = lambda { "#{target.project.name}//#{target.name}//Debug" } project_root_dir = File.join(File.dirname(target.project.path), target.name) # Create a watcher for all source build files specified within the target new_guards = target.sources_build_phase.build_files.map do |file| full_source_path = File.join(project_root_dir,file.path) puts "Source Path: #{full_source_path}" create_guard_for full_source_path, build_action end # Create a watcher for the pch if one has been specified. if target.config('Debug').prefix_header prefix_header_path = File.join(File.dirname(target.project.path), target.config('Debug').prefix_header) puts prefix_header_path new_guards << create_guard_for(prefix_header_path, build_action) end new_guards end.flatten.compact end |