Class: AsProject::AsProject

Inherits:
AsProjectBase show all
Defined in:
lib/asproject.rb

Constant Summary collapse

@@ASPROJECT_FILE_NAME =
'AsProject'
@@TEMPLATE_TYPE =
'asproject'
@@DEFAULT_TEMPLATES =
['as3', 'fb2as', 'asunit3', 'config']

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AsProjectBase

#capitalize, #finish, #out, #put_created, #uncapitalize

Constructor Details

#initialize(args = nil) ⇒ AsProject

Returns a new instance of AsProject.



28
29
30
# File 'lib/asproject.rb', line 28

def initialize(args=nil)
  execute(args)
end

Class Method Details

.ignore_file?(file) ⇒ Boolean

Do not copy files found in the ignore_files list

Returns:

  • (Boolean)


220
221
222
223
224
225
226
227
# File 'lib/asproject.rb', line 220

def AsProject.ignore_file? file
  @@COPY_IGNORE_FILES.each do |name|
    if(name == file)
      return true
    end
  end
  return false
end

Instance Method Details

#copy_templates(templates, target = nil, type = nil, render = true) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/asproject.rb', line 133

def copy_templates(templates, target=nil, type=nil, render=true)
  if(target.nil?)
    target = project_path
  end
  if(type.nil?)
    type = @@TEMPLATE_TYPE
  end
  templates.each do |template|
    @resolver.copy_files(@path_finder.get_template(type, template), target, render).each do |file|
      @created_files << file
    end
  end
end

#copy_templates_to_project(type = nil) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/asproject.rb', line 167

def copy_templates_to_project(type=nil)
  if(type.nil?)
    copy_templates_to_project('asproject')
    copy_templates_to_project('asclass')
    return
  end
  project_templates = File.join(project_path, 'config', 'templates', type)
  templates = @path_finder.get_available_templates(type)
  templates.each do |template|
    template_target = File.join(project_templates, template)
    if(!File.exists?(template_target))
      File.makedirs(template_target)
      @created_files << template_target
      copy_templates(template, template_target, type, false)
    end
  end
end

#copy_templates_to_user_home(type = nil) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/asproject.rb', line 147

def copy_templates_to_user_home(type=nil)
  if(type.nil?)
    copy_templates_to_user_home('asproject')
    copy_templates_to_user_home('asclass')
    return
  end
  user_templates = File.join(@path_finder.user_asproject_home, 'templates', type)
  templates = @path_finder.get_children(@path_finder.get_gem_template(type, ''))
  templates.each do |template|
    target = File.join(user_templates, template)
    if(!File.exists?(target))
      File.makedirs(target)
    end
    @created_files << target
    @resolver.copy_files(@path_finder.get_gem_template(type, template), target, false).each do |file|
      @created_files << file
    end
  end
end

#create_projectObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/asproject.rb', line 106

def create_project
  if(File.exists? project_path)
    if(@arguments.force?)
      msg = <<EOF

Are you sure you want to replace the entire directory at:
#{project_path}?

(y)es or (n)o
EOF
      out msg
      response = gets.chomp!
      if(response == 'y')
        FileUtils.rm_rf(project_path)
        out '>> Deleted: [' + project_path + ']'
      else
        raise ProjectError.new('Was unable to create the project at: ' + project_path)
      end
    else
      raise ProjectError.new('Directory at ' + project_path + ' already exists, use -f (--force) option to clobber.')
    end
  end
  Dir.mkdir(project_path)
  @created_files << project_path
#      create_config_yaml
end

#eclipse_project_nameObject



194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/asproject.rb', line 194

def eclipse_project_name
  if(File.exists?(File.join(@execution_dir, '.project')))
    begin
      @eclipse_project = EclipseProject.new(@execution_dir)
      if(!@eclipse_project.project_name.nil?)
        return @eclipse_project.project_name
      end
    rescue
      return nil
    end
  end
end

#execute(args = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
# File 'lib/asproject.rb', line 32

def execute(args=nil)
  begin
    @should_create_project = true
    @created_files = []
    if(args.nil?)
      @execution_dir = Dir.pwd
    else
      @execution_dir = args.execution_dir
      @project_name = args.project_name
    end
    @path_finder = PathFinder.new(@execution_dir)
    parse_args(args)

    @resolver = AsProjectResolver.new(self)
    if(@arguments.copy_to_home)
      copy_templates_to_user_home
    end
    
    out '---------------------------'
    begin
      project = @path_finder.current_project
      @should_create_project = false
      msg = ">> Working in existing project #{project_name} at: " + project
    rescue
      if(@arguments.project_name == '')
        finish
        exit
      end
      msg = ">> Creating a new project at: #{@execution_dir}#{File::SEPARATOR}#{@project_name}"
    end

    out msg

    if(@arguments.project_name == '')
      @execution_dir = File.expand_path(@path_finder.current_project)
      @path_finder.execution_dir = @execution_dir
      @arguments.execution_dir = @execution_dir
    else
      create_project
    end

    if(@arguments.copy_to_project)
      copy_templates_to_project
    end

    copy_templates(@arguments.selected_templates)

    finish
  rescue ProjectError => e
    out e.message
    exit
  end
end

#parse_args(args) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/asproject.rb', line 86

def parse_args args
  if(args.nil?)
    @arguments = ProjectArguments.new
    @arguments.should_create = @should_create_project
    @arguments.path_finder = @path_finder
    @arguments.default_templates = @@DEFAULT_TEMPLATES
    @arguments.project_templates = @path_finder.get_available_templates(@@TEMPLATE_TYPE)
    @arguments.execution_dir = @execution_dir
    @arguments.parse!(ARGV)
    if(@should_create_project)
      @project_name = @arguments.project_name
    end
  else
    @execution_dir = args.execution_dir
    @project_name = args.project_name
    @path_finder = PathFinder.new(@execution_dir)
    @arguments = args
  end
end

#presumed_project_nameObject



185
186
187
188
189
190
191
192
# File 'lib/asproject.rb', line 185

def presumed_project_name
  e_project_name = eclipse_project_name
  if(!e_project_name.nil?)
    return e_project_name
  else
    return File.basename(@execution_dir)
  end
end

#project_nameObject



207
208
209
# File 'lib/asproject.rb', line 207

def project_name
  return @project_name
end

#project_pathObject



211
212
213
# File 'lib/asproject.rb', line 211

def project_path
  return File.join(@execution_dir, @arguments.project_name)
end