Sha256: 14f882e72bbaf2d821795f7810ce4aa4a6b55cdbea1df3d181e7f8993b41675a

Contents?: true

Size: 731 Bytes

Versions: 40

Compression:

Stored size: 731 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

40 entries across 40 versions & 1 rubygems

Version Path
marty-9.3.0 app/models/marty/api_config.rb
marty-8.5.0 app/models/marty/api_config.rb
marty-8.4.1 app/models/marty/api_config.rb
marty-8.3.1 app/models/marty/api_config.rb
marty-8.2.0 app/models/marty/api_config.rb
marty-8.0.0 app/models/marty/api_config.rb
marty-6.1.0 app/models/marty/api_config.rb
marty-5.2.0 app/models/marty/api_config.rb
marty-5.1.4 app/models/marty/api_config.rb
marty-5.1.3 app/models/marty/api_config.rb
marty-5.1.2 app/models/marty/api_config.rb
marty-5.1.1 app/models/marty/api_config.rb
marty-5.1.0 app/models/marty/api_config.rb
marty-3.1.0 app/models/marty/api_config.rb
marty-3.0.1 app/models/marty/api_config.rb
marty-4.0.0.rc2 app/models/marty/api_config.rb
marty-3.0.0 app/models/marty/api_config.rb
marty-2.9.3 app/models/marty/api_config.rb
marty-2.9.2 app/models/marty/api_config.rb
marty-2.9.1 app/models/marty/api_config.rb