Class: Smooth::Query

Inherits:
Object
  • Object
show all
Includes:
Documentation
Defined in:
lib/smooth/query.rb

Class Method Summary collapse

Methods included from Documentation

#desc, included, #inline_description

Class Method Details

.configObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/smooth/query.rb', line 50

def self.config
  val = query_config.send(@current_config || :base)

  if val.nil?
    val = query_config[@current_config] = {}
    return config
  end

  val
end

.configure(options, resource = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/smooth/query.rb', line 8

def self.configure options, resource=nil
  resource ||= Smooth.current_resource
  klass = define_or_open(options, resource)

  Array(options.blocks).each do |blk|
    klass.class_eval(&blk)
  end

  klass
end

.define_or_open(options, resource) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/smooth/query.rb', line 19

def self.define_or_open(options, resource)
  resource_name = resource.name
  base          = Smooth.query

  name = options.name
  name = nil if name == "Default"

  klass = "#{ resource_name }#{ name }".singularize + "Query"

  if query_klass = Object.const_get(klass) rescue nil
    return query_klass
  end

  Object.const_set(klass, Class.new(base))
end

.params(*args, &block) ⇒ Object



40
41
42
43
# File 'lib/smooth/query.rb', line 40

def self.params *args, &block
  options = args.extract_options!
  config.params = options
end

.role(name, &block) ⇒ Object



45
46
47
48
# File 'lib/smooth/query.rb', line 45

def self.role name, &block
  @current_config = name
  instance_eval(&block) if block_given?
end

.start_from(*args, &block) ⇒ Object



35
36
37
38
# File 'lib/smooth/query.rb', line 35

def self.start_from *args, &block
  options = args.extract_options!
  config.start_from = options
end