Sha256: 4a7087c8a904bc9de19b0c89cead31073f414431f306eb6aa88323cd23a2cf3e

Contents?: true

Size: 728 Bytes

Versions: 12

Compression:

Stored size: 728 Bytes

Contents

class Marty::ApiConfig < Marty::Base
  validates_presence_of :script

  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

12 entries across 12 versions & 1 rubygems

Version Path
marty-2.5.2 app/models/marty/api_config.rb
marty-2.5.1 app/models/marty/api_config.rb
marty-2.5.0 app/models/marty/api_config.rb
marty-2.4.9 app/models/marty/api_config.rb
marty-2.4.8 app/models/marty/api_config.rb
marty-2.4.7 app/models/marty/api_config.rb
marty-2.4.6 app/models/marty/api_config.rb
marty-2.4.5 app/models/marty/api_config.rb
marty-2.4.4 app/models/marty/api_config.rb
marty-2.4.3 app/models/marty/api_config.rb
marty-2.4.2 app/models/marty/api_config.rb
marty-2.4.1 app/models/marty/api_config.rb