Class: Birdwatcher::Commands::Workspace
- Inherits:
-
Birdwatcher::Command
- Object
- Birdwatcher::Command
- Birdwatcher::Commands::Workspace
- Defined in:
- lib/birdwatcher/commands/workspace.rb
Constant Summary
Constants inherited from Birdwatcher::Command
Birdwatcher::Command::ARGUMENT_SEPARATOR
Constants included from Birdwatcher::Concerns::Concurrency
Birdwatcher::Concerns::Concurrency::DEFAULT_THREAD_POOL_SIZE
Constants included from Birdwatcher::Concerns::Core
Birdwatcher::Concerns::Core::DATA_DIRECTORY
Instance Attribute Summary
Attributes inherited from Birdwatcher::Command
Class Method Summary collapse
Instance Method Summary collapse
- #create_workspace ⇒ Object
- #delete_workspace ⇒ Object
- #list_workspaces ⇒ Object
- #rename_workspace ⇒ Object
- #run ⇒ Object
- #select_workspace(name = nil) ⇒ Object
Methods inherited from Birdwatcher::Command
auto_completion, auto_completion_strings, descendants, #execute, has_name?, meta, meta=
Methods included from Birdwatcher::Concerns::Concurrency
Methods included from Birdwatcher::Concerns::Persistence
included, #save_status, #save_user
Methods included from Birdwatcher::Concerns::Presentation
included, #make_status_summary_output, #make_url_summary_output, #make_user_details_output, #make_user_summary_output, #output_status_summary, #output_user_details, #output_user_summary, #page_text
Methods included from Birdwatcher::Concerns::Outputting
#confirm, #error, #fatal, included, #info, #line_separator, #newline, #output, #output_formatted, #task, #warn
Methods included from Birdwatcher::Concerns::Util
#escape_html, #excerpt, included, #number_to_human_size, #parse_time, #pluralize, #strip_control_characters, #strip_html, #suppress_output, #suppress_warnings, #time_ago_in_words, #unescape_html
Methods included from Birdwatcher::Concerns::Core
#console, #current_workspace, #current_workspace=, #database, included, #klout_client, #read_data_file, #twitter_client
Class Method Details
.detailed_usage ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/birdwatcher/commands/workspace.rb', line 10 def self.detailed_usage <<-USAGE Workspaces enable you to segment and manage users and data stored in the database. You can use workspaces to create logical separation between different users. For example, you may want to create a workspace for a company, a department or for a specific topic. There will always be a default workspace with the name #{Birdwatcher::Models::Workspace::DEFAULT_WORKSPACE_NAME.bold} which might be enough if you plan to use Birdwatcher for a small group of Twitter users. #{'USAGE:'.bold} #{'List available workspaces:'.bold} workspace list #{'Create a new workspace:'.bold} workspace create NAME [DESCRIPTION] #{'Switch to a workspace:'.bold} workspace use NAME #{'Delete a workspace:'.bold} workspace delete NAME #{'Rename a workspace'.bold} workspace rename NAME NEW_NAME USAGE end |
Instance Method Details
#create_workspace ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/birdwatcher/commands/workspace.rb', line 92 def create_workspace name = arguments[1] description = arguments[2..-1].to_a.join(" ") description = nil unless description if !name error("You must provide a workspace name") return false end if Birdwatcher::Models::Workspace.first(:name => name) error("There is already a workspace with that name") return false end workspace = Birdwatcher::Models::Workspace.create( :name => name, :description => description ) info("Created workspace: #{workspace.name.bold}") self.current_workspace = workspace end |
#delete_workspace ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/birdwatcher/commands/workspace.rb', line 148 def delete_workspace name = arguments[1] if !name error("You must provide a workspace name") return false end if workspace = Birdwatcher::Models::Workspace.first(:name => name) return unless confirm("Are you sure you want to delete #{name.bold} and all associated data?") workspace.destroy info("Deleted workspace: #{workspace.name.bold}") if workspace.default_workspace? self.current_workspace = Birdwatcher::Models::Workspace.create_default_workspace! return end if current_workspace.id == workspace.id self.current_workspace = Birdwatcher::Models::Workspace.first( :name => Birdwatcher::Models::Workspace::DEFAULT_WORKSPACE_NAME ) end else error("There is no workspace with that name") return false end end |
#list_workspaces ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/birdwatcher/commands/workspace.rb', line 61 def list_workspaces longest_workspace_name = Birdwatcher::Models::Workspace.all.map(&:name).max_by(&:length) info("Available workspaces:\n") Birdwatcher::Models::Workspace.order(:name).each do |workspace| if current_workspace.id == workspace.id workspace_name = "*".bold.light_green + " #{workspace.name}" else workspace_name = " #{workspace.name}" end output_formatted(" %-#{longest_workspace_name.bold.length}s \t\t%s\n", workspace_name.bold, workspace.description) end newline end |
#rename_workspace ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/birdwatcher/commands/workspace.rb', line 116 def rename_workspace old_name = arguments[1] new_name = arguments[2] if !old_name || !new_name error("You must provide workspace name and new name") return false end if old_name == Birdwatcher::Models::Workspace::DEFAULT_WORKSPACE_NAME error("Default workspace cannot be renamed") return false end if !old_workspace = Birdwatcher::Models::Workspace.first(:name => old_name) error("There is no workspace named #{old_name.bold}") return false end if Birdwatcher::Models::Workspace.first(:name => new_name) error("There is already a workspace named #{new_name.bold}") return false end old_workspace.update(:name => new_name) if old_workspace.id == current_workspace.id self.current_workspace = old_workspace end info("Workspace #{old_name.bold} renamed to #{new_name.bold}") end |
#run ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/birdwatcher/commands/workspace.rb', line 39 def run if !arguments? info("Current workspace: #{current_workspace.name.bold} (database ID: #{current_workspace.id.to_s.bold})") return true end action = arguments.first.downcase case action when "list" list_workspaces when "create", "add", "-a" create_workspace when "rename", "-r" rename_workspace when "select", "use" select_workspace when "delete", "destroy", "rm", "-d" delete_workspace else select_workspace(arguments.first) end end |
#select_workspace(name = nil) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/birdwatcher/commands/workspace.rb', line 76 def select_workspace(name = nil) name ||= arguments[1] if !name error("You must provide a workspace name") return false end if workspace = Birdwatcher::Models::Workspace.first(:name => name) self.current_workspace = workspace info("Now using workspace: #{workspace.name.bold}") else error("There is no workspace with that name") end end |