Class: TaskHelper::Form

Inherits:
Base
  • Object
show all
Defined in:
lib/task_helper/form.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #created_at, #id, #to_h, #updated_at

Constructor Details

#initialize(args = {}, database: nil, **params) ⇒ Form

Returns a new instance of Form.



23
24
25
26
# File 'lib/task_helper/form.rb', line 23

def initialize(args = {}, database: nil, **params)
  @database = database
  super(args.merge(params))
end

Class Method Details

.allObject



7
8
9
# File 'lib/task_helper/form.rb', line 7

def self.all
  Database.all.lazy.flat_map { |db| db.forms }
end

.find(database:, form:) ⇒ Object



17
18
19
20
21
# File 'lib/task_helper/form.rb', line 17

def self.find(database:, form:)
  if response = get(route: "apps/#{database}/entities/#{form}.json")
    new response['form'] if response['form']
  end
end

.find_by(search) ⇒ Object



11
12
13
14
15
# File 'lib/task_helper/form.rb', line 11

def self.find_by(search)
  if response = get(route: 'apps/search/entities/search.json', params: search)
    new response['form'] if response['form']
  end
end

Instance Method Details

#databaseObject



28
29
30
# File 'lib/task_helper/form.rb', line 28

def database
  @database ||= Database.find(app_id)
end

#fieldsObject



32
33
34
35
36
# File 'lib/task_helper/form.rb', line 32

def fields
  @fields ||= Field.get(
    route: "apps/#{app_id}/entities/#{id}/properties.json")['fields']
      .map { |field| Field.new(field, form: self) }
end

#recordsObject



38
39
40
41
42
43
44
# File 'lib/task_helper/form.rb', line 38

def records
  if fields.any?
    @records ||= (1..page_count).lazy.flat_map do |page|
      record_page(page).lazy.map { |record| Record.new(record, form: self) }
    end
  end
end