Class: XQuery::Abstract
- Inherits:
-
Object
- Object
- XQuery::Abstract
- Defined in:
- lib/xquery/abstract.rb
Overview
Abstract superclass, should be inherited, not used
Direct Known Subclasses
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
contains current state of wrapped query.
Class Method Summary collapse
-
.alias_on_q(name, return_self = false) ⇒ Object
Aliases method to ‘#__method` and `q.method`.
-
.inherited(child) ⇒ Object
private
inherited classes should also have their query_proxies inherited.
-
.query_proxy ⇒ Class
Query_proxy (‘q`) class.
-
.with(*args) {|XQuery::Abstract| ... } ⇒ Object
Yields instance inside block.
-
.wrap_method(name, as: name) ⇒ Object
Defines ‘method`, `__method` and `q.method`.
-
.wrap_methods(*methods) ⇒ Object
Aame as wrap_method, but hanldes multiply methods.
Instance Method Summary collapse
-
#apply { ... } ⇒ XQuery::Abstract
Yields query inside block.
-
#execute(method, *args, &block) ⇒ Object
Executes specified method, returns query.
-
#initialize(query) ⇒ Abstract
constructor
A new instance of Abstract.
-
#with {|XQuery::Abstract| ... } ⇒ Object
Yields iteself inside block.
Constructor Details
#initialize(query) ⇒ Abstract
Returns a new instance of Abstract.
66 67 68 69 |
# File 'lib/xquery/abstract.rb', line 66 def initialize(query) self.query = query @query_proxy = self.class.query_proxy.new(self) end |
Instance Attribute Details
#query ⇒ Object
contains current state of wrapped query
10 11 12 |
# File 'lib/xquery/abstract.rb', line 10 def query @query end |
Class Method Details
.alias_on_q(name, return_self = false) ⇒ Object
Aliases method to ‘#__method` and `q.method`
43 44 45 46 47 48 49 50 51 |
# File 'lib/xquery/abstract.rb', line 43 def self.alias_on_q(name, return_self = false) alias_method("__#{name}", name) private("__#{name}") query_proxy.send(:define_method, name) do |*args, &block| result = instance.send("__#{name}", *args, &block) return_self ? self : result end end |
.inherited(child) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
inherited classes should also have their query_proxies inherited
61 62 63 |
# File 'lib/xquery/abstract.rb', line 61 def self.inherited(child) child.instance_variable_set(:@query_proxy, Class.new(query_proxy)) end |
.query_proxy ⇒ Class
Returns query_proxy (‘q`) class.
54 55 56 |
# File 'lib/xquery/abstract.rb', line 54 def self.query_proxy @query_proxy ||= Class.new(QueryProxy) end |
.with(*args) {|XQuery::Abstract| ... } ⇒ Object
Yields instance inside block. I suggest to name it ‘q`
21 22 23 |
# File 'lib/xquery/abstract.rb', line 21 def self.with(*args) new(*args).with { |instance| yield(instance) } end |
.wrap_method(name, as: name) ⇒ Object
Defines ‘method`, `__method` and `q.method`. Both of witch changes query to query.method
29 30 31 32 |
# File 'lib/xquery/abstract.rb', line 29 def self.wrap_method(name, as: name) define_method(as) { |*args, &block| _update_query(name, *args, &block) } alias_on_q(as, true) end |
.wrap_methods(*methods) ⇒ Object
Aame as wrap_method, but hanldes multiply methods
36 37 38 |
# File 'lib/xquery/abstract.rb', line 36 def self.wrap_methods(*methods) methods.each(&method(:wrap_method)) end |
Instance Method Details
#apply { ... } ⇒ XQuery::Abstract
Yields query inside block
94 95 96 97 |
# File 'lib/xquery/abstract.rb', line 94 def apply self.query = yield(query) self end |
#execute(method, *args, &block) ⇒ Object
Executes specified method, returns query. Feel free to redefine this method in case it’s only public api method in your class
86 87 88 89 |
# File 'lib/xquery/abstract.rb', line 86 def execute(method, *args, &block) public_send(method, *args, &block) query end |
#with {|XQuery::Abstract| ... } ⇒ Object
Yields iteself inside block. I suggest to name it ‘q`
74 75 76 77 |
# File 'lib/xquery/abstract.rb', line 74 def with yield(self) query end |