Class: Sly::ProjectManager

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/sly/project_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProjectManager

Returns a new instance of ProjectManager.



11
12
13
14
15
16
17
18
# File 'lib/sly/project_manager.rb', line 11

def initialize
  @connector = Sly::Connector.connect_with_defaults
  @projects_json = @connector.products
  @available_projects = []
  @projects_json.each do |project_json|
    @available_projects << Sly::Project.new(project_json)
  end
end

Instance Attribute Details

#available_projectsObject (readonly)

Returns the value of attribute available_projects.



7
8
9
# File 'lib/sly/project_manager.rb', line 7

def available_projects
  @available_projects
end

#connectorObject (readonly)

Returns the value of attribute connector.



8
9
10
# File 'lib/sly/project_manager.rb', line 8

def connector
  @connector
end

#projects_jsonObject (readonly)

Returns the value of attribute projects_json.



9
10
11
# File 'lib/sly/project_manager.rb', line 9

def projects_json
  @projects_json
end

Instance Method Details

#project_listingsObject



20
21
22
# File 'lib/sly/project_manager.rb', line 20

def project_listings
  return @available_projects.map(&:to_s).join("\n")
end

#setup_project(directory, project_id) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sly/project_manager.rb', line 24

def setup_project(directory, project_id)
  target_directory = File.join(directory, ".sly")
  target_file = File.join(target_directory, "project")
  mkdir_p target_directory
  touch target_file
  selected_project = @available_projects.select { |project| project.id == project_id.to_i }.first
  if selected_project
    File.open(target_file, 'w') { |file| file.write selected_project.to_yaml }
    $stdout.write "Thanks! That's Sly all setup for the current project, run `sly help` to see the commands available.\n"
  else
    raise "That ID does not match any of the projects available; please try again:"
  end
end