Module: LucaRecord::IO

Includes:
LucaSupport::Code
Included in:
Base, LucaSupport::Mail
Defined in:
lib/luca_record/io.rb

Overview

IO

Read / Write hash data with id and/or date. Manage both database & historical records.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LucaSupport::Code

decimalize, decode_date, decode_id, decode_month, decode_term, decode_txid, delimit_num, encode_date, encode_dirname, encode_month, encode_term, encode_txid, has_status?, issue_random_id, keys_stringify, match_score, parse_current, readable, take_current, take_history, to_ngram

Class Method Details

.included(klass) ⇒ Object

:nodoc:



20
21
22
# File 'lib/luca_record/io.rb', line 20

def self.included(klass) # :nodoc:
  klass.extend ClassMethods
end

Instance Method Details

#load_config(path = nil) ⇒ Object



536
537
538
539
540
541
542
543
# File 'lib/luca_record/io.rb', line 536

def load_config(path = nil)
  path = path.to_s
  if File.exist?(path)
    YAML.safe_load(File.read(path), permitted_classes: [Date])
  else
    {}
  end
end

#where(**query) ⇒ Object

Used @date for searching current settings query can be nested hash for other than ‘val’

where(contract_status: 'active')
where(graded: {rank: 5})


521
522
523
524
525
526
527
528
529
530
531
532
533
534
# File 'lib/luca_record/io.rb', line 521

def where(**query)
  return enum_for(:where, **query) unless block_given?

  query.each do |key, val|
    v = val.respond_to?(:values) ? val.values.first : val
    label = val.respond_to?(:keys) ? val.keys.first : 'val'
    self.class.all do |data|
      next unless data.keys.map(&:to_sym).include?(key)

      processed = parse_current(data)
      yield processed if v == processed.dig(key.to_s, label.to_s)
    end
  end
end