Module: Pipekit::FieldRepository

Includes:
Repository
Included in:
DealField, PersonField
Defined in:
lib/pipekit/field_repository.rb

Instance Method Summary collapse

Methods included from Repository

#all, #create, #find_by, #initialize, #update, #where

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Pipekit::Repository

Instance Method Details

#find_label(field:, id:) ⇒ Object



14
15
16
17
18
# File 'lib/pipekit/field_repository.rb', line 14

def find_label(field:, id:)
  find_values(field)
    .find(raise_label_not_found(field, id)) { |value| value["id"] == id.to_i }
    .fetch("label", "")
end

#find_values(field) ⇒ Object



20
21
22
# File 'lib/pipekit/field_repository.rb', line 20

def find_values(field)
  find_by(name: field).fetch("options", [], choose_first_value: false)
end

#get_by_key(key) ⇒ Object



5
6
7
8
# File 'lib/pipekit/field_repository.rb', line 5

def get_by_key(key)
  key = Config.field_id(parent_resource, key)
  search_fields("key", key)
end

#get_by_name(name) ⇒ Object



10
11
12
# File 'lib/pipekit/field_repository.rb', line 10

def get_by_name(name)
  search_fields("name", name)
end