class EntitySchema::Transformers::Abstract

Transform raw valid options to usefull options

Public Class Methods

call(*args) click to toggle source
# File lib/entity_schema/transformers/abstract.rb, line 11
def self.call(*args)
  instance.call(*args)
end

Public Instance Methods

call(name, owner_name, type, raw_options) click to toggle source
# File lib/entity_schema/transformers/abstract.rb, line 15
def call(name, owner_name, type, raw_options)
  transform_options(name: name, owner_name: owner_name, map_to: type, **raw_options)
end

Private Instance Methods

bool_key?(key) click to toggle source
# File lib/entity_schema/transformers/abstract.rb, line 26
def bool_key?(key)
  [true, false].include? options.fetch(key, nil)
end
callable(subject) click to toggle source
# File lib/entity_schema/transformers/abstract.rb, line 54
def callable(subject)
  subject if subject.respond_to?(:call)
end
eql(input, pairs) click to toggle source

eql(hash, a: 1, b: [1, 2, :value])

# File lib/entity_schema/transformers/abstract.rb, line 45
def eql(input, pairs)
  pairs.each do |k, values|
    Array(values).each do |v|
      return true if input[k] == v
    end
  end
  nil
end
find(*alternatives) click to toggle source
# File lib/entity_schema/transformers/abstract.rb, line 40
def find(*alternatives)
  alternatives.compact.first
end
new_strict_hash() click to toggle source
# File lib/entity_schema/transformers/abstract.rb, line 34
def new_strict_hash
  Hash.new do |h, k|
    raise "Gem works wrong: missed option `#{k.inspect}` called. Options is: #{h.keys}"
  end
end
owner_meth(option) click to toggle source
# File lib/entity_schema/transformers/abstract.rb, line 58
def owner_meth(option)
  return unless option.is_a?(Symbol)
  owner.method(option)
end
to_bool(subject) click to toggle source
# File lib/entity_schema/transformers/abstract.rb, line 67
def to_bool(subject)
  subject ? true : false
end
transform_options(_options) click to toggle source

Hook for ancestors

# File lib/entity_schema/transformers/abstract.rb, line 22
def transform_options(_options)
  new_strict_hash
end
truth(subject) click to toggle source
# File lib/entity_schema/transformers/abstract.rb, line 63
def truth(subject)
  subject == true ? true : nil
end
without_predicate(key) click to toggle source
# File lib/entity_schema/transformers/abstract.rb, line 30
def without_predicate(key)
  key.to_s.delete('?').to_sym
end