arqo 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1887e4c98d7848ac3d743b338ea8aeaf26f3d643
4
- data.tar.gz: 22d1f86473d4adc3437aedc2401fc64eb040fd70
3
+ metadata.gz: 4ba2c84fa910379b38e591ab84f766e057c76de6
4
+ data.tar.gz: b6e2b10c631038d4c766683b1159aebbe44325f9
5
5
  SHA512:
6
- metadata.gz: 2c0b3222b5b3023d9eb4d16a6bf9d244414523e19dc2e4295e0f1ff963fc08bde610fd55656a8e1881ca63a7e891f48578580f192945cd99b27b92cf5f36af10
7
- data.tar.gz: 9214d81840071fd81d134b89006fa4ff99bc50702b0ae9a81137cf089afa3db208553d2f8a88f4ecb451819a60c4677218bc00316d25f87c55897142476c89a3
6
+ metadata.gz: faa30d5cabb73243dc846d2f71eca8d521b0b3073467039df5350a7e4730096904320c935b1a727ac4f04a1f11b024004756b27dda8da993b5971f60fed271dd
7
+ data.tar.gz: d7199ec586500009c448606a63454cc29e9c68e121dfd19874b54a5fc7918ec5af737c1b521f76f03d3173c5a09768ab74a09854ad401d513c1f803877836f78
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 Santiago Bartesaghi
3
+ Copyright (c) 2020 Rootstrap
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -96,6 +96,22 @@ you can use it like this:
96
96
  CustomNamedQuery.new(User.all).active_last_week
97
97
  ```
98
98
 
99
+ you can also set the model class or relation to query from by overriding a simple method, like:
100
+
101
+ ```ruby
102
+ class CustomNamedQuery < ARQO::Query
103
+ module Scope
104
+ # ...
105
+ end
106
+
107
+ private
108
+
109
+ def associated_relation
110
+ User # you can also do something like User.some_scope
111
+ end
112
+ end
113
+ ```
114
+
99
115
  ## Chaining scopes
100
116
  Of course you can chain everything together, methods defined in the query object and scopes defined in the model or by Rails.
101
117
  ```ruby
@@ -127,7 +143,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
127
143
 
128
144
  ## Contributing
129
145
 
130
- Bug reports and pull requests are welcome on GitHub at https://github.com/santib/arqo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/santib/arqo/blob/master/CODE_OF_CONDUCT.md).
146
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rootstrap/arqo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/rootstrap/arqo/blob/master/CODE_OF_CONDUCT.md).
131
147
 
132
148
 
133
149
  ## License
@@ -136,7 +152,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
136
152
 
137
153
  ## Code of Conduct
138
154
 
139
- Everyone interacting in the ARQO project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/santib/arqo/blob/master/CODE_OF_CONDUCT.md).
155
+ Everyone interacting in the ARQO project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rootstrap/arqo/blob/master/CODE_OF_CONDUCT.md).
140
156
 
141
157
  ## Logo attribution
142
158
  Logo made by [iconixar](https://www.flaticon.com/free-icon/archery_3080892) from [www.flaticon.com](https://www.flaticon.com/)
@@ -6,18 +6,45 @@ module ARQO
6
6
  attr_reader :relation
7
7
  delegate_missing_to :relation
8
8
 
9
- def initialize(relation = derived_relation)
9
+ def initialize(relation = associated_relation)
10
10
  @relation = relation.extending(scope_module)
11
11
  end
12
12
 
13
13
  private
14
14
 
15
- def derived_relation_name
16
- self.class.name.sub(/Query$/, '')
17
- end
15
+ # Returns the model to which the query object is associated.
16
+ # By default it will infer the name from the query object's class
17
+ # assuming the name is the name of the model with "Query" as the suffix.
18
+ #
19
+ # As an example, UserQuery would be associated with the User model and
20
+ # Blog::PostQuery would be associated with the Blog::Post namespaced model.
21
+ #
22
+ # This method can be overridden to bypass this convention and associate
23
+ # the query object to another relation by returning it.
24
+ #
25
+ # ==== Example
26
+ # class PostQuery < ARQO::Query
27
+ # # ...
28
+ #
29
+ # private
30
+ #
31
+ # def associated_relation
32
+ # Blog::Post
33
+ # end
34
+ # end
35
+ #
36
+ # @return [Class, ActiveRecord::Relation]
37
+ def associated_relation
38
+ class_name = self.class.name
39
+ derived_relation_name = class_name.sub(/Query$/, '')
40
+
41
+ unless Object.const_defined?(derived_relation_name)
42
+ raise NameError, "Could not find model #{derived_relation_name} associated " \
43
+ "to query #{class_name}.\n Make sure the name is correct or override " \
44
+ '#associated_relation to provide a custom model'
45
+ end
18
46
 
19
- def derived_relation
20
- derived_relation_name.constantize.all if Object.const_defined?(derived_relation_name)
47
+ derived_relation_name.constantize.all
21
48
  end
22
49
 
23
50
  def scope_module
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ARQO
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arqo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Santiago Bartesaghi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-24 00:00:00.000000000 Z
11
+ date: 2020-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -130,7 +130,7 @@ dependencies:
130
130
  version: 1.4.2
131
131
  description:
132
132
  email:
133
- - sbartesaghi@hotmail.com
133
+ - santib@hey.com
134
134
  executables: []
135
135
  extensions: []
136
136
  extra_rdoc_files: []
@@ -140,12 +140,12 @@ files:
140
140
  - lib/arqo.rb
141
141
  - lib/arqo/query.rb
142
142
  - lib/arqo/version.rb
143
- homepage: https://github.com/santib/arqo
143
+ homepage: https://github.com/rootstrap/arqo
144
144
  licenses:
145
145
  - MIT
146
146
  metadata:
147
- homepage_uri: https://github.com/santib/arqo
148
- source_code_uri: https://github.com/santib/arqo
147
+ homepage_uri: https://github.com/rootstrap/arqo
148
+ source_code_uri: https://github.com/rootstrap/arqo
149
149
  post_install_message:
150
150
  rdoc_options: []
151
151
  require_paths: