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

#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



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

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



73
74
75
76
77
78
79
# File 'lib/path_finder.rb', line 73

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

#current_project=(dir) ⇒ Object



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

def current_project=(dir)
  @current_project = dir
end

#flash_player_configObject



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

def flash_player_config
  return @user.flash_player_config
end

#flash_player_config_contentObject



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

def flash_player_config_content
  return @user.flash_player_config_content
end

#flash_player_homeObject



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

def flash_player_home
  return @user.flash_player_home
end

#flash_player_logObject



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

def flash_player_log
  return @user.flash_player_log
end

#flash_player_trustObject



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

def flash_player_trust
  return @user.flash_player_trust
end

#gem_asproject_homeObject



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

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



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/path_finder.rb', line 98

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



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/path_finder.rb', line 81

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:



161
162
163
164
165
166
167
# File 'lib/path_finder.rb', line 161

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



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/path_finder.rb', line 133

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



122
123
124
125
126
127
128
129
130
131
# File 'lib/path_finder.rb', line 122

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



152
153
154
155
156
157
158
159
# File 'lib/path_finder.rb', line 152

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

#remote_file_task(name, task) ⇒ Object



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

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

#userObject



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

def user
  return @user
end

#user_asproject_homeObject



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

def user_asproject_home
  return @user.asproject_home
end

#user_homeObject



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

def user_home
  return @user.home
end

#user_libraryObject



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

def user_library
  return @user.library
end