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



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

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



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

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

#get_by_key(key) ⇒ Object



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

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

#get_by_name(name) ⇒ Object



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

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