Class: AsProject::PathFinder

Inherits:
TemplateResolver show all
Defined in:
lib/path_finder.rb

Direct Known Subclasses

Project

Instance Attribute Summary collapse

Attributes inherited from TemplateResolver

#ignore_all, #replace_all

Instance Method Summary collapse

Methods inherited from TemplateResolver

#b, #clean_file_name, #copy_file, #copy_files, #is_binary?, #project_name, #render_file, #should_render?, #write_file?

Constructor Details

#initialize(execution_dir = nil) ⇒ PathFinder

Returns a new instance of PathFinder.



6
7
8
9
10
11
12
13
14
15
# File 'lib/path_finder.rb', line 6

def initialize(execution_dir=nil)
  super()
  if(execution_dir.nil?)
    @execution_dir = Dir.pwd
  else
    @execution_dir = execution_dir
  end
  @current_project = nil
  @user = create_user
end

Instance Attribute Details

#execution_dirObject

Returns the value of attribute execution_dir.



4
5
6
# File 'lib/path_finder.rb', line 4

def execution_dir
  @execution_dir
end

Instance Method Details

#asproject_player_trustObject



41
42
43
# File 'lib/path_finder.rb', line 41

def asproject_player_trust
  return @user.asproject_player_trust
end

#current_projectObject

Don’t store the ‘inspected’ current_project Only store it if the value was set from outside



85
86
87
88
89
90
91
# File 'lib/path_finder.rb', line 85

def current_project
  if(@current_project.nil?)
    return find_project(@execution_dir)
  else
    return @current_project
  end
end

#current_project=(dir) ⇒ Object



78
79
80
# File 'lib/path_finder.rb', line 78

def current_project=(dir)
  @current_project = dir
end

#downloadsObject



58
59
60
# File 'lib/path_finder.rb', line 58

def downloads
  return user.downloads
end

#flash_player_configObject



29
30
31
# File 'lib/path_finder.rb', line 29

def flash_player_config
  return @user.flash_player_config
end

#flash_player_config_contentObject



33
34
35
# File 'lib/path_finder.rb', line 33

def flash_player_config_content
  return @user.flash_player_config_content
end

#flash_player_homeObject



21
22
23
# File 'lib/path_finder.rb', line 21

def flash_player_home
  return @user.flash_player_home
end

#flash_player_logObject



25
26
27
# File 'lib/path_finder.rb', line 25

def flash_player_log
  return @user.flash_player_log
end

#flash_player_trustObject



37
38
39
# File 'lib/path_finder.rb', line 37

def flash_player_trust
  return @user.flash_player_trust
end

#gem_asproject_homeObject



49
50
51
52
# File 'lib/path_finder.rb', line 49

def gem_asproject_home
  parent = File.dirname(File.dirname(__FILE__))
  return File.expand_path(parent)
end

#get_available_templates(type) ⇒ Object

Collect and return all available templates from: (PROJECT_PATH)/config/templates/(TYPE)/ (USER_HOME)/(ASPROJECT_HOME)/templates/ (ASPROJECT_GEM_HOME)/templates



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/path_finder.rb', line 110

def get_available_templates(type)
  project_templates = get_children(get_project_template(type, ''))
  user_templates = get_children(get_user_template(type, ''))
  gem_templates = get_children(get_gem_template(type, ''))
  result = []
  project_templates.each do |template|
    result << template
  end
  user_templates.each do |template|
    if(!result.index(template))
      result << template
    end
  end
  gem_templates.each do |template|
    if(!result.index(template))
      result << template
    end
  end
  return result
end

#get_children(dir) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/path_finder.rb', line 93

def get_children(dir)
  list = []
  if(dir.nil?)
    return list
  end
  Dir.open(dir).each do |child|
    if(!AsProject.ignore_file? child)
      list << child
    end
  end
  return list
end

#get_gem_template(type, name) ⇒ Object

Raises:



173
174
175
176
177
178
179
# File 'lib/path_finder.rb', line 173

def get_gem_template(type, name)
  template = File.expand_path(File.join(gem_asproject_home, 'templates', type, name))
  if(File.exists? template)
    return template
  end
  raise ProjectError.new('Requested template not found at ' + template)
end

#get_project_template(type, name) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/path_finder.rb', line 145

def get_project_template(type, name)
  begin
    if(@execution_dir.nil?)
      dir = Dir.pwd
    else
      dir = @execution_dir
    end
    project = find_project(dir)
    template = File.join(project, 'config', 'templates', type, name)
    if(File.exists? template)
      return template
    else
      return nil
    end
  rescue
    return nil
  end
end

#get_template(type, name) ⇒ Object

@type: ‘class’ or ‘project’ @name: ‘as3’, ‘mxml’, ‘fb2’, or user-created folder name Represents folders inside of the appropriate template type dir



134
135
136
137
138
139
140
141
142
143
# File 'lib/path_finder.rb', line 134

def get_template(type, name)
  template = get_project_template(type, name)
  if(template.nil?)
    template = get_user_template(type, name)
  end
  if(template.nil?)
    template = get_gem_template(type, name)
  end
  return template
end

#get_user_template(type, name) ⇒ Object



164
165
166
167
168
169
170
171
# File 'lib/path_finder.rb', line 164

def get_user_template(type, name)
  template = File.expand_path(File.join(user_asproject_home, 'templates', type, name))
  if(File.exists? template)
    return template
  else
    return nil
  end
end

#lib_downloadsObject



54
55
56
# File 'lib/path_finder.rb', line 54

def lib_downloads
  return File.join(downloads, 'lib')
end

#mxmlcObject



17
18
19
# File 'lib/path_finder.rb', line 17

def mxmlc
  return @user.mxmlc
end

#remote_file_task(name, task) ⇒ Object



45
46
47
# File 'lib/path_finder.rb', line 45

def remote_file_task(name, task)
  return @user.remote_file_task(name, task)
end

#userObject



62
63
64
# File 'lib/path_finder.rb', line 62

def user
  return @user
end

#user_asproject_homeObject



74
75
76
# File 'lib/path_finder.rb', line 74

def user_asproject_home
  return @user.asproject_home
end

#user_homeObject



70
71
72
# File 'lib/path_finder.rb', line 70

def user_home
  return @user.home
end

#user_libraryObject



66
67
68
# File 'lib/path_finder.rb', line 66

def user_library
  return @user.library
end