Class: Ambition::Context

Inherits:
Object show all
Includes:
API
Defined in:
lib/ambition/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from API

#all?, #ambition_adapter, #ambition_adapter=, #ambition_owner, #any?, #detect, #each, #empty?, #entries, #first, #select, #slice, #sort_by

Constructor Details

#initialize(owner) ⇒ Context

Returns a new instance of Context.



21
22
23
24
25
# File 'lib/ambition/context.rb', line 21

def initialize(owner)
  @owner   = owner
  @clauses = {}
  @stash   = {}
end

Instance Attribute Details

#clausesObject (readonly)

These are the methods your Query and Translator classes will want to access.

+owner+   The class everything was called on.  Like `User' 

+clauses+ A hash of arrays, one key per processor.
          So, if someone called User.select, your
          +clauses+ hash would have a :select key with
          an array of translated strings via your Select
          class.

+stash+   A place for you to stick stuff.  Available to
          all Translators and your Query class.


19
20
21
# File 'lib/ambition/context.rb', line 19

def clauses
  @clauses
end

#ownerObject (readonly)

These are the methods your Query and Translator classes will want to access.

+owner+   The class everything was called on.  Like `User' 

+clauses+ A hash of arrays, one key per processor.
          So, if someone called User.select, your
          +clauses+ hash would have a :select key with
          an array of translated strings via your Select
          class.

+stash+   A place for you to stick stuff.  Available to
          all Translators and your Query class.


19
20
21
# File 'lib/ambition/context.rb', line 19

def owner
  @owner
end

#stashObject (readonly)

These are the methods your Query and Translator classes will want to access.

+owner+   The class everything was called on.  Like `User' 

+clauses+ A hash of arrays, one key per processor.
          So, if someone called User.select, your
          +clauses+ hash would have a :select key with
          an array of translated strings via your Select
          class.

+stash+   A place for you to stick stuff.  Available to
          all Translators and your Query class.


19
20
21
# File 'lib/ambition/context.rb', line 19

def stash
  @stash
end

Instance Method Details

#<<(clause) ⇒ Object



31
32
33
34
35
# File 'lib/ambition/context.rb', line 31

def <<(clause)
  @clauses[clause.key] ||= []
  @clauses[clause.key] << clause.to_s
  self
end

#adapter_queryObject



37
38
39
# File 'lib/ambition/context.rb', line 37

def adapter_query
  Processors::Base.translator(self, :Query)
end

#ambition_contextObject



27
28
29
# File 'lib/ambition/context.rb', line 27

def ambition_context
  self
end

#inspectObject



58
59
60
# File 'lib/ambition/context.rb', line 58

def inspect
  "(Query object: call #to_s or #to_hash to inspect, call an Enumerable (such as #each or #first) to request data)"
end

#kickObject



49
50
51
# File 'lib/ambition/context.rb', line 49

def kick
  adapter_query.kick
end

#sizeObject Also known as: length



53
54
55
# File 'lib/ambition/context.rb', line 53

def size
  adapter_query.size
end

#to_hashObject



41
42
43
# File 'lib/ambition/context.rb', line 41

def to_hash
  adapter_query.to_hash
end

#to_sObject



45
46
47
# File 'lib/ambition/context.rb', line 45

def to_s
  adapter_query.to_s
end