xquery 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c136c8a16f768441bc0e2dc4e26e84a2376454da
4
- data.tar.gz: d43cc44d95877c754849b0dac45c29866ee37191
3
+ metadata.gz: 876688b968422788335514201e580c31a562daf3
4
+ data.tar.gz: 5ed3c53f8347b42cfd3fef711512fe49d6b2a005
5
5
  SHA512:
6
- metadata.gz: 1032c489a451dc1f3f32371a7bbc1ddcd095eb2534103c5e1b02fcd8a8f3c5109c6054687c1c8ff87fe089bd34b3727a0fdf7bd89148d301cfd71dea2e859a4b
7
- data.tar.gz: 8a0b8a61c0aeb65377c671573cea95cf1b5b2c4f123ab044114d4bf69746fb2669250e5051be5d989de23362df1276c90e0bc4b0c6903c5d41f053fccd069323
6
+ metadata.gz: 95462d4e6f98c48e113a046a664ba08b2acb5919c886a836c95781856beb91ecb61576c9ca958a60ea02dbb79a42e788d6946bcdb24842e937330794e42db617
7
+ data.tar.gz: bafcc91a9b266af4a91388238cd289fd4ee019d36633dcb37bbff6fe11fd63ed317041a722d961bcc56c2775b06d993662393e3bacf12c9edec60689033d5042
@@ -4,7 +4,16 @@ require 'active_support'
4
4
  # convert it in a builder classes
5
5
  # see [README.md] for more information
6
6
  module XQuery
7
+ autoload :Abstract, 'xquery/abstract'
8
+ autoload :QuerySuperclassChanged, 'xquery/errors'
9
+ autoload :Generic, 'xquery/generic'
10
+ autoload :QueryProxy, 'xquery/query_proxy'
11
+ autoload :VERSION, 'xquery/version'
7
12
  end
8
13
 
9
- require 'xquery/version'
10
- require 'xquery/generic'
14
+ # Allows you to do all query magic on a generic object
15
+ # @param model [Object] any object
16
+ # @yield block where instance will be yielded
17
+ def XQuery(model)
18
+ XQuery::Generic.with(model) { |instance| yield(instance) }
19
+ end
@@ -5,22 +5,27 @@ require 'xquery/errors'
5
5
 
6
6
  module XQuery
7
7
  # Abstract superclass, should be inherited, not used
8
+ # @attr query
9
+ # contains current state of wrapped query
8
10
  class Abstract
9
11
  class_attribute :query_superclass
12
+ self.query_superclass = Object
13
+
14
+ attr_reader :query
10
15
 
11
16
  # Yields instance inside block. I suggest to name it `q`
12
- # @param args [Array(Object)] array of arguments would be passed to
13
- # @param block [#to_proc] block to witch instance would be yielded
14
- def self.with(*args, &block)
15
- instance = new(*args)
16
- block.call(instance)
17
- instance.query
17
+ # @param args [Array(Object)]
18
+ # array of arguments would be passed to `new`
19
+ # @yield [XQuery::Abstract] new intance
20
+ # @return resulting query
21
+ def self.with(*args)
22
+ new(*args).with { |instance| yield(instance) }
18
23
  end
19
24
 
20
25
  # Defines `method`, `__method` and `q.method`.
21
- # Both of wich changes query to query.method
26
+ # Both of witch changes query to query.method
22
27
  # @param name [#to_sym] name of method on query
23
- # @param as [#to_sym] name of method defined
28
+ # @option as [#to_sym] name of method defined
24
29
  def self.wrap_method(name, as: name)
25
30
  define_method(as) { |*args, &block| _update_query(name, *args, &block) }
26
31
  alias_on_q(as, true)
@@ -51,13 +56,12 @@ module XQuery
51
56
  end
52
57
 
53
58
  # inherited classes should also have their query_proxies inherited
59
+ # @api private
60
+ # @param child [Class] class inheriting this
54
61
  def self.inherited(child)
55
62
  child.instance_variable_set(:@query_proxy, Class.new(query_proxy))
56
63
  end
57
64
 
58
- # contains current state of wrapped query
59
- attr_reader :query
60
-
61
65
  # @param query [Object] generic query
62
66
  def initialize(query)
63
67
  self.query = query
@@ -65,10 +69,10 @@ module XQuery
65
69
  end
66
70
 
67
71
  # Yields iteself inside block. I suggest to name it `q`
68
- # @param block [#to_proc] block to whitch instance would be yielded
72
+ # @yield [XQuery::Abstract] itself
69
73
  # @return [Object] query
70
- def with(&block)
71
- block.call(self)
74
+ def with
75
+ yield(self)
72
76
  query
73
77
  end
74
78
 
@@ -85,17 +89,17 @@ module XQuery
85
89
  end
86
90
 
87
91
  # Yields query inside block
88
- # @param block [#to_proc]
92
+ # @yield query
89
93
  # @return [XQuery::Abstract] self
90
- def apply(&block)
91
- self.query = block.call(query)
94
+ def apply
95
+ self.query = yield(query)
92
96
  self
93
97
  end
94
98
 
95
99
  private
96
100
 
97
- # Private Api!
98
101
  # Updates query by calling method on it and storing the result
102
+ # @api private
99
103
  # @return [XQuery::Abstract] self
100
104
  def _update_query(method, *args, &block)
101
105
  apply { |x| x.public_send(method, *args, &block) }
@@ -105,7 +109,7 @@ module XQuery
105
109
  # @raise XQuery::QuerySuperclassChanged
106
110
  def query=(x)
107
111
  unless x.is_a?(query_superclass)
108
- fail QuerySuperclassChanged.new(x, query_superclass)
112
+ raise QuerySuperclassChanged.new(x, query_superclass)
109
113
  end
110
114
 
111
115
  @query = x
@@ -1,10 +1,11 @@
1
1
  module XQuery
2
2
  # raised when superclass of query changed
3
+ # @attr result
4
+ # query on which constraint failed
5
+ # @attr [Class] expectation
6
+ # expected superclass of query
3
7
  class QuerySuperclassChanged < StandardError
4
- # query on which constraint failed
5
8
  attr_reader :result
6
-
7
- # expected superclass of query
8
9
  attr_reader :expectation
9
10
 
10
11
  # @param result [Object] query on which constraint failed
@@ -3,9 +3,6 @@ require 'xquery/abstract'
3
3
  module XQuery
4
4
  # delegates all operations to model
5
5
  class Generic < Abstract
6
- # never used but defined in case of need
7
- self.query_superclass = Object
8
-
9
6
  # all missing methods would be delegated to query
10
7
  # and processed as wrappers process them
11
8
  def method_missing(name, *args, &block)
@@ -26,10 +23,3 @@ module XQuery
26
23
  end
27
24
  end
28
25
  end
29
-
30
- # Allows you to do all query magic on a generic object
31
- # @param model [Object] any object
32
- # @param block [#to_proc] block where instance will be yielded
33
- def XQuery(model, &block)
34
- XQuery::Generic.with(model, &block)
35
- end
@@ -1,15 +1,16 @@
1
1
  module XQuery
2
2
  # This proxy can be used to access raw wrappers inside classes,
3
3
  # inherited from XQuery::Abstract
4
+ # @attr instance [XQuery::Abstract]
5
+ # Wrapped instance
4
6
  class QueryProxy
5
- # @param instance [Xquery::Abstract] instance to delegate methods
7
+ # @param instance [XQuery::Abstract] instance to delegate methods
6
8
  def initialize(instance)
7
9
  self.instance = instance
8
10
  end
9
11
 
10
12
  private
11
13
 
12
- # instance of Xquery::Abstract
13
14
  attr_accessor :instance
14
15
  end
15
16
  end
@@ -1,4 +1,4 @@
1
1
  module XQuery
2
2
  # defines XQuery version
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'.freeze
4
4
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - jelf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-14 00:00:00.000000000 Z
11
+ date: 2017-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
@@ -30,72 +30,72 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.10'
33
+ version: '1.12'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.10'
40
+ version: '1.12'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.3'
47
+ version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.3'
54
+ version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: pry
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.10'
61
+ version: '3.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.10'
68
+ version: '3.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '10.4'
75
+ version: '0.47'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '10.4'
82
+ version: '0.47'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rubocop
84
+ name: pry
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.35'
89
+ version: '0.10'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.35'
96
+ version: '0.10'
97
97
  - !ruby/object:Gem::Dependency
98
- name: yard
98
+ name: coveralls
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
@@ -109,104 +109,71 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.8'
111
111
  - !ruby/object:Gem::Dependency
112
- name: simplecov
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.9'
125
+ - !ruby/object:Gem::Dependency
126
+ name: launchy
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '0.11'
131
+ version: 2.4.3
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '0.11'
125
- description: |
126
- # XQuery
127
- XQuery is designed to replace boring method call chains and allow to easier
128
- convert it in a builder classes
129
- [![Build Status](https://travis-ci.org/JelF/xquery.svg?branch=master)](https://travis-ci.org/JelF/xquery)
130
- ## Usage of `XQuery` function
131
- `Xquery` is a shortcat to `Xquery::Generic.with`
132
-
133
- ```
134
- r = XQuery(''.html_safe) do |q|
135
- # similar to tap
136
- q << 'bla bla bla'
137
- q << 'bla bla bla'
138
- # using truncate
139
- q.truncate(15)
140
- # real content (q.send(:query)) mutated
141
- q << '!'
142
- end
143
- r # => "bla bla blab...!"
144
- ```
145
- ## Usage of `XQuery::Abstract`
146
- I designed this gem to help me with `ActiveRecord` Queries, so i inherited
147
- `XQuery::Abstract` and used it's powers. It provides the following features
148
- ### `wrap_method` and `wrap_methods`
149
- when you call each of this methods they became automatically wrapped
150
- (`XQuery::Abstract` basically wraps all methods query `#respond_to?`)
151
- It means, that there are instance methods with same name defined and will
152
- change a `#query` to their call result.
153
- ```
154
- self.query = query.foo(x)
155
- # is basically the same as
156
- foo(x)
157
- # when `wrap_method :foo` called
158
- ```
159
-
160
- You can also specify new name using `wrap_method :foo, as: :bar` syntax
161
- ### `q` object
162
- `q` is a proxy object which holds all of wrapped methods,
163
- but not methods you defined inside your class.
164
- E.g. i have defined `wrap_method(:foo)`, but also delegated `#foo` to some
165
- another object. If i call `q.foo`, i will get wrapped method.
166
- Note, that if you redefine `#__foo` method, q.foo will call it instead of
167
- normal work.
168
- You can add additional methods to `q` using something like `alias_on_q :foo`.
169
- I used it with `kaminary` and it was useful
170
- ```
171
- def page=(x)
172
- apply { |query| query.page(x) }
173
- end
174
- alias_on_q :page=
175
-
176
- def page
177
- query.current_page
178
- end
179
- alias_on_q :page
180
- ```
181
-
182
- ### `query_superclass`
183
- You should specify `query_superclass` class_attribute to inherit
184
- `XQuery::Abstract`. Whenever `query.is_a?(query_superclass)` evaluate to false,
185
- you will get `XQuery::QuerySuperclassChanged` exception.
186
- It can save you much time when your class misconfigured.
187
- E.g. you are using `select!` and it returns `nil`, because why not?
188
-
189
- ### `#apply` method
190
- `#apply` does exact what it source tells
191
- ```
192
- # yields query inside block
193
- # @param block [#to_proc]
194
- # @return [XQuery::Abstract] self
195
- def apply(&block)
196
- self.query = block.call(query)
197
- self
198
- end
199
- ```
200
- It is usefull to merge different queries.
201
-
202
- ### `with` class method
203
- You can get XQuery functionality even you have not defined a specific class
204
- (You are still have to inherit XQuery::Abstract to use it)
205
- You can see it in this document when i described `XQuery` function.
206
- Note, that it yields a class instance, not `q` object.
207
- It accepts any arguments, they will be passed to a constructor (except block)
208
- If you want only to call one function on an instance (e.g. `#apply`),
209
- you should prefer `execute` alias
138
+ version: 2.4.3
139
+ description: "# XQuery\n\n[![Join the chat at https://gitter.im/JelF/xquery](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/JelF/xquery?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n[![Build
140
+ Status](https://travis-ci.org/JelF/xquery.svg?branch=master)](https://travis-ci.org/JelF/xquery)\n[![Code
141
+ Climate](https://codeclimate.com/github/JelF/xquery/badges/gpa.svg)](https://codeclimate.com/github/JelF/xquery)\n[![Test
142
+ Coverage](https://codeclimate.com/github/JelF/xquery/badges/coverage.svg)](https://codeclimate.com/github/JelF/xquery/coverage)\n[![Issue
143
+ Count](https://codeclimate.com/github/JelF/xquery/badges/issue_count.svg)](https://codeclimate.com/github/JelF/xquery)
144
+ \ \nXQuery is designed to replace boring method call chains and allow to easier\nconvert
145
+ it in a builder classes\n## Usage of `XQuery` function\n`XQuery` is a shortcat to
146
+ `XQuery::Generic.with`\n\n```\nr = XQuery(''.html_safe) do |q|\n # similar to tap\n
147
+ \ q << 'bla bla bla'\n q << 'bla bla bla'\n # using truncate\n q.truncate(15)\n
148
+ \ # real content (q.send(:query)) mutated\n q << '!'\nend\nr # => \"bla bla blab...!\"\n```\n##
149
+ Usage of `XQuery::Abstract`\nI designed this gem to help me with `ActiveRecord`
150
+ Queries, so i inherited\n`XQuery::Abstract` and used it's powers. It provides the
151
+ following features\n### `wrap_method` and `wrap_methods`\nwhen you call each of
152
+ this methods they became automatically wrapped\n(`XQuery::Abstract` basically wraps
153
+ all methods query `#respond_to?`)\nIt means, that there are instance methods with
154
+ same name defined and will\nchange a `#query` to their call result.\n```\nself.query
155
+ = query.foo(x)\n# is basically the same as\nfoo(x)\n# when `wrap_method :foo` called\n```\n\nYou
156
+ can also specify new name using `wrap_method :foo, as: :bar` syntax\n### `q` object\n`q`
157
+ is a proxy object which holds all of wrapped methods,\nbut not methods you defined
158
+ inside your class.\nE.g. i have defined `wrap_method(:foo)`, but also delegated
159
+ `#foo` to some\nanother object. If i call `q.foo`, i will get wrapped method.\nNote,
160
+ that if you redefine `#__foo` method, q.foo will call it instead of\nnormal work.\nYou
161
+ can add additional methods to `q` using something like `alias_on_q :foo`.\nI used
162
+ it with `kaminary` and it was useful\n```\ndef page=(x)\n apply { |query| query.page(x)
163
+ }\nend\nalias_on_q :page=\n\ndef page\n query.current_page\nend\nalias_on_q :page\n```\n\n###
164
+ `query_superclass`\nYou should specify `query_superclass` class_attribute to inherit\n`XQuery::Abstract`.
165
+ Whenever `query.is_a?(query_superclass)` evaluate to false,\nyou will get `XQuery::QuerySuperclassChanged`
166
+ exception.\nIt can save you much time when your class misconfigured.\nE.g. you are
167
+ using `select!` and it returns `nil`, because why not?\n\n### `#apply` method\n`#apply`
168
+ does exact what it source tells\n```\n# yields query inside block\n# @param block
169
+ [#to_proc]\n# @return [XQuery::Abstract] self\ndef apply(&block)\n self.query =
170
+ block.call(query)\n self\nend\n```\nIt is usefull to merge different queries.\n\n###
171
+ `with` class method\nYou can get XQuery functionality even you have not defined
172
+ a specific class\n(You are still have to inherit XQuery::Abstract to use it)\nYou
173
+ can see it in this document when i described `XQuery` function.\nNote, that it yields
174
+ a class instance, not `q` object.\nIt accepts any arguments, they will be passed
175
+ to a constructor (except block)\n\n### `execute` method\nPreferred way to call public
176
+ instance methods.\nResulting query would be returned\n"
210
177
  email:
211
178
  - begdory4+xquery@gmail.com
212
179
  executables: []
@@ -239,10 +206,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
206
  version: '0'
240
207
  requirements: []
241
208
  rubyforge_project:
242
- rubygems_version: 2.4.5.1
209
+ rubygems_version: 2.5.1
243
210
  signing_key:
244
211
  specification_version: 4
245
212
  summary: XQuery is designed to replace boring method call chains and allow to easier
246
213
  convert it in a builder classes see README.md for more information
247
214
  test_files: []
248
- has_rdoc: