xquery 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. checksums.yaml +7 -0
  2. metadata +227 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ca2ea723ba64628698695acc969bd8f60c172855
4
+ data.tar.gz: 352dabe6be5a151d95f0b441f5db8284e74e295d
5
+ SHA512:
6
+ metadata.gz: 5f728b160b85f0a1705374648e9f106a99e376673f79a4157996864be0896c40d5d5a98e9e786f9bfda54f0378e61104ce1a24efb44e0835ece0909c50c96831
7
+ data.tar.gz: a05b0d370bbab41f684455d4d28569ada79a0660a92de8f57f544495ecc72eb587c173e3749d7a8ebd5c0ea0da0f682c420dac9baf09b6491eefd0167870f48e
metadata ADDED
@@ -0,0 +1,227 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xquery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jelf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.35'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.35'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.8'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.8'
111
+ description: |
112
+ # XQuery
113
+ XQuery is designed to replace boring method call chains and allow to easier
114
+ convert it in a builder classes
115
+ ## Usage of `XQuery` function
116
+ `Xquery` is a shortcat to `Xquery::Generic.with`
117
+
118
+ ```
119
+ r = XQuery(''.html_safe) do |q|
120
+ # similar to tap
121
+ q << 'bla bla bla'
122
+ q << 'bla bla bla'
123
+ # using truncate
124
+ q.truncate(15)
125
+ # real content (q.send(:query)) mutated
126
+ q << '!'
127
+ end
128
+ r # => "bla bla blab...!"
129
+ ```
130
+ ## Usage of `XQuery::Abstract`
131
+ I designed this gem to help me with `ActiveRecord` Queries, so i inherited
132
+ `XQuery::Abstract` and used it's powers. It provides the following features
133
+ ### `wrap_method` and `wrap_methods`
134
+ when you call each of this methods they became automatically wrapped
135
+ (`XQuery::Abstract` basically wraps all methods query `#respond_to?`)
136
+ It means, that there are instance methods with same name defined and will
137
+ change a `#query` to their call result.
138
+ ```
139
+ self.query = query.foo(x)
140
+ # is basically the same as
141
+ foo(x)
142
+ # when `wrap_method :foo` called
143
+ ```
144
+
145
+ You can also specify new name using `wrap_method :foo, as: :bar` syntax
146
+ ### `q` object
147
+ `q` is a proxy object which holds all of wrapped methods,
148
+ but not methods you defined inside your class.
149
+ E.g. i have defined `wrap_method(:foo)`, but also delegated `#foo` to some
150
+ another object. If i call `q.foo`, i will get wrapped method.
151
+ Note, that if you redefine `#__foo` method, q.foo will call it instead of
152
+ normal work.
153
+ You can add additional methods to `q` using something like `alias_on_q :foo`.
154
+ I used it with `kaminary` and it was useful
155
+ ```
156
+ def page=(x)
157
+ apply { |query| query.page(x) }
158
+ end
159
+ alias_on_q :page=
160
+
161
+ def page
162
+ query.current_page
163
+ end
164
+ alias_on_q :page
165
+ ```
166
+
167
+ ### `query_superclass`
168
+ You should specify `query_superclass` class_attribute to inherit
169
+ `XQuery::Abstract`. Whenever `query.is_a?(query_superclass)` evaluate to false,
170
+ you will get `XQuery::QuerySuperclassChanged` exception.
171
+ It can save you much time when your class misconfigured.
172
+ E.g. you are using `select!` and it returns `nil`, because why not?
173
+
174
+ ### `#apply` method
175
+ `#apply` does exact what it source tells
176
+ ```
177
+ # yields query inside block
178
+ # @param block [#to_proc]
179
+ # @return [XQuery::Abstract] self
180
+ def apply(&block)
181
+ self.query = block.call(query)
182
+ self
183
+ end
184
+ ```
185
+ It is usefull to merge different queries.
186
+
187
+ ### `with` class method
188
+ You can get XQuery functionality even you have not defined a specific class
189
+ (You are still have to inherit XQuery::Abstract to use it)
190
+ You can see it in this document when i described `XQuery` function.
191
+ Note, that it yields a class instance, not `q` object.
192
+ It accepts any arguments, they will be passed to a constructor (except block)
193
+ If you want only to call one function on an instance (e.g. `#apply`),
194
+ you should prefer `execute` alias
195
+ email:
196
+ - begdory4+xquery@gmail.com
197
+ executables: []
198
+ extensions: []
199
+ extra_rdoc_files: []
200
+ files: []
201
+ homepage: https://github.com/JelF/xquery
202
+ licenses:
203
+ - WTFPL
204
+ metadata: {}
205
+ post_install_message:
206
+ rdoc_options: []
207
+ require_paths:
208
+ - lib
209
+ required_ruby_version: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ required_rubygems_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ requirements: []
220
+ rubyforge_project:
221
+ rubygems_version: 2.4.5.1
222
+ signing_key:
223
+ specification_version: 4
224
+ summary: XQuery is designed to replace boring method call chains and allow to easier
225
+ convert it in a builder classes see README.md for more information
226
+ test_files: []
227
+ has_rdoc: