Module: Rql::Queryable

Extended by:
ActiveSupport::Concern
Defined in:
lib/rql/queryable.rb

Class Method Summary collapse

Class Method Details

.derive(*attributes) ⇒ Object

Preloads the specified derived attributes from the database

Parameters:

  • attributes (Array<Symbol>)

    the attributes to be preloaded

Returns:

  • scope including derived attributes



42
43
44
# File 'lib/rql/queryable.rb', line 42

def derive(*attributes)
  rql.select(self.arel_table[Arel.star], *attributes).all
end

.derive_attr(name) { ... } ⇒ Object

Defines a derived attribute on a model

Parameters:

  • name (Symbol)

    the name of the derived attribute

Yields:

  • the code to derive the attribute



30
31
32
33
34
35
36
# File 'lib/rql/queryable.rb', line 30

def derive_attr(name, &block)
  define_method(name) do
    attributes.has_key?(name.to_s) ? attributes[name.to_s] : instance_eval(&block)
  end

  derived_attributes[name] = block
end

.derived_attributesHash<Symbol, Proc>

Gets the derived attributes defined on the model

Returns:

  • (Hash<Symbol, Proc>)

    hash of derived attributes indexed by name



49
50
51
# File 'lib/rql/queryable.rb', line 49

def derived_attributes
  @derive_attribute ||= {}
end

.eval_rql(alias_derived_attr = false) { ... } ⇒ Rql::Dsl::Context

Evaluates a block of code against the RQL DSL

Parameters:

  • alias_derived_attr (Boolean) (defaults to: false)

    value specifying if derived attributes will be assigned an alias

Yields:

  • the code block to be converted to sql

Returns:



20
21
22
# File 'lib/rql/queryable.rb', line 20

def eval_rql(alias_derived_attr = false, &block)
  Dsl::Base.new(self, alias_derived_attr).instance_eval(&block)
end

.rqlRql::Scope::RqlScope

Gets an RQL scope object for access to rql query methods

Returns:



11
12
13
# File 'lib/rql/queryable.rb', line 11

def rql
  return Scope::RqlScope.new(all)
end