Class: Grist::Type::Workspace
Overview
Defines a Grist Workspace
Constant Summary collapse
- PATH =
"/workspaces"- KEYS =
%w[ id name createdAt updatedAt isSupportWorkspace docs access owner orgDomain ].freeze
Instance Attribute Summary collapse
-
#org_id ⇒ Object
readonly
Returns the value of attribute org_id.
Class Method Summary collapse
-
.all(org_id) ⇒ Array
List all workspaces.
-
.create(org_id, data) ⇒ Grist::Type::Workspace?
Creates the workspace.
Instance Method Summary collapse
-
#create_doc(data) ⇒ Grist::Type::Doc?
Create a new Doc in the workspace.
- #docs ⇒ Object
-
#initialize(params = {}) ⇒ Workspace
constructor
A new instance of Workspace.
Methods inherited from Base
delete, #deleted?, find, #keys, update
Methods included from Searchable
Methods included from Accessible
Methods included from Rest
#create, #delete, #get, #list, #path, #request, #update
Constructor Details
#initialize(params = {}) ⇒ Workspace
Returns a new instance of Workspace.
23 24 25 26 27 |
# File 'lib/grist/type/workspace.rb', line 23 def initialize(params = {}) @org_id = params[:org_id] @docs = [] super params end |
Instance Attribute Details
#org_id ⇒ Object (readonly)
Returns the value of attribute org_id.
21 22 23 |
# File 'lib/grist/type/workspace.rb', line 21 def org_id @org_id end |
Class Method Details
.all(org_id) ⇒ Array
List all workspaces
70 71 72 73 74 75 76 77 |
# File 'lib/grist/type/workspace.rb', line 70 def self.all(org_id) grist_res = new(org_id: org_id).list return [] unless grist_res&.data.is_a?(Array) return [] unless grist_res&.data&.any? grist_res.data.map { |org| Workspace.new(org) } end |
.create(org_id, data) ⇒ Grist::Type::Workspace?
Creates the workspace
62 63 64 65 |
# File 'lib/grist/type/workspace.rb', line 62 def self.create(org_id, data) org = Type::Organization.find(org_id) org.create_workspace(data) end |
Instance Method Details
#create_doc(data) ⇒ Grist::Type::Doc?
Create a new Doc in the workspace
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/grist/type/workspace.rb', line 44 def create_doc(data) grist_res = request(:post, doc_path, data) return unless grist_res.success? data["id"] = grist_res.data data.transform_keys!(&:to_s) doc = Doc.new(data) @docs ||= [] @docs << doc doc end |
#docs ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/grist/type/workspace.rb', line 29 def docs return @docs if @docs&.any? && @docs.first.is_a?(Doc) if @docs.any? && @docs.first.is_a?(Hash) @docs = @docs.map do |doc| Doc.new(doc.merge(ws_id: @id)) end end @docs end |