Class: Grist::Type::Doc
Overview
Defines a Grist Workspace
Constant Summary collapse
- PATH =
"/docs"- KEYS =
%w[ name createdAt updatedAt id isPinned urlId trunkId type forks access ].freeze
Class Method Summary collapse
-
.all(org_id) ⇒ Object
List all workspaces # # @return [Array] Array of workspaces.
-
.create(ws_id, data) ⇒ Object
Updates the workspace # @param id [Integer] The ID of the workspace to delete # # @param data [Hash] The data to update the workspace with # @return [self | nil] The updated workspace or nil if not found.
-
.find(id) ⇒ Object
Finds an workspace by ID # @param id [Integer] The ID of the workspace to find # # return [self | nil] The workspace or nil if not found.
- .tables(doc_id) ⇒ Object
Instance Method Summary collapse
- #create_tables(data) ⇒ Object
-
#initialize(params = {}) ⇒ Doc
constructor
A new instance of Doc.
- #tables ⇒ Object
- #tables_path ⇒ Object
- #update_table(data) ⇒ Object
Methods inherited from Base
delete, #deleted?, #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 = {}) ⇒ Doc
23 24 25 26 27 |
# File 'lib/grist/type/doc.rb', line 23 def initialize(params = {}) super params @ws_id = params[:ws_id] @tables = [] end |
Class Method Details
.all(org_id) ⇒ Object
List all workspaces # # @return [Array] Array of workspaces
73 74 75 76 77 78 |
# File 'lib/grist/type/doc.rb', line 73 def self.all(org_id) grist_res = new(org_id: org_id).list return [] unless grist_res&.data.is_a?(Array) grist_res.data&.map { |org| Workspace.new(org) } end |
.create(ws_id, data) ⇒ Object
Updates the workspace # @param id [Integer] The ID of the workspace to delete # # @param data [Hash] The data to update the workspace with # @return [self | nil] The updated workspace or nil if not found
66 67 68 69 |
# File 'lib/grist/type/doc.rb', line 66 def self.create(ws_id, data) obj = new(ws_id: ws_id) obj.create(data) end |
.find(id) ⇒ Object
Finds an workspace by ID # @param id [Integer] The ID of the workspace to find # # return [self | nil] The workspace or nil if not found
83 84 85 86 87 88 89 |
# File 'lib/grist/type/doc.rb', line 83 def self.find(id) grist_res = new.get(id) puts grist_res.inspect return unless grist_res.success? && grist_res.data new(grist_res.data) end |
.tables(doc_id) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/grist/type/doc.rb', line 91 def self.tables(doc_id) org = find(doc_id) return unless org org.tables end |
Instance Method Details
#create_tables(data) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/grist/type/doc.rb', line 42 def create_tables(data) grist_res = request(:post, tables_path, data) return [] unless grist_res&.data.is_a?(Array) tables end |
#tables ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/grist/type/doc.rb', line 33 def tables grist_res = request(:get, tables_path) return [] if grist_res&.error? @tables = grist_res.data["tables"]&.map do |t| Table.new(t.merge(doc_id: @id, ws_id: @ws_id)) end end |
#tables_path ⇒ Object
29 30 31 |
# File 'lib/grist/type/doc.rb', line 29 def tables_path "#{path}/#{@id}/tables" end |
#update_table(data) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/grist/type/doc.rb', line 50 def update_table(data) grist_res = request(:patch, tables_path, data) return [] unless grist_res&.data.is_a?(Array) tables end |