Class: Sly::ProjectManager
- Inherits:
-
Object
- Object
- Sly::ProjectManager
- Includes:
- FileUtils
- Defined in:
- lib/sly/project_manager.rb
Instance Attribute Summary collapse
-
#available_projects ⇒ Object
readonly
Returns the value of attribute available_projects.
-
#connector ⇒ Object
readonly
Returns the value of attribute connector.
-
#projects_json ⇒ Object
readonly
Returns the value of attribute projects_json.
Instance Method Summary collapse
-
#initialize ⇒ ProjectManager
constructor
A new instance of ProjectManager.
- #project_listings ⇒ Object
- #setup_project(directory, project_id) ⇒ Object
Constructor Details
#initialize ⇒ ProjectManager
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_projects ⇒ Object (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 |
#connector ⇒ Object (readonly)
Returns the value of attribute connector.
8 9 10 |
# File 'lib/sly/project_manager.rb', line 8 def connector @connector end |
#projects_json ⇒ Object (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_listings ⇒ Object
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 |