Sha256: 63d72fde687da45d153bc5f17d81569ea90f0c2c7cd2ec5b6dcf142de71a157a

Contents?: true

Size: 735 Bytes

Versions: 11

Compression:

Stored size: 735 Bytes

Contents

class Marty::ApiConfig < Marty::Base
  validates :script, presence: true

  def self.lookup(script, node, attr)
    res = where('node IS NULL OR node = ?', node).
            where('attr IS NULL OR attr = ?', attr).
            order('node nulls last, attr nulls last').
            find_by(script: script)

    res && res.as_json.except('id',
                              'created_at',
                              'updated_at',
                              'script',
                              'node',
                              'attr').symbolize_keys
  end

  def self.multi_lookup(script, node, attrs)
    (attrs.nil? ? [nil] : attrs).
      map { |attr| lookup(script, node, attr).try { |x| x.unshift(attr) } }
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
marty-14.3.0 app/models/marty/api_config.rb
marty-14.0.0 app/models/marty/api_config.rb
marty-13.0.2 app/models/marty/api_config.rb
marty-11.0.0 app/models/marty/api_config.rb
marty-10.0.3 app/models/marty/api_config.rb
marty-10.0.2 app/models/marty/api_config.rb
marty-10.0.0 app/models/marty/api_config.rb
marty-9.5.1 app/models/marty/api_config.rb
marty-9.5.0 app/models/marty/api_config.rb
marty-9.3.3 app/models/marty/api_config.rb
marty-9.3.2 app/models/marty/api_config.rb