eitil 0.3.1 → 0.3.2

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
  SHA256:
3
- metadata.gz: f822863c972553dc89dca4e80fce4b197c89c27f78456342195f46b920fa07f5
4
- data.tar.gz: 0e852adfd5a9127d3d67f349102bb6000121b730a5a42d0628b09beab45723fe
3
+ metadata.gz: 14233b2ffb39a1ca7d1710fd9a57925994d5784e427f8d022d21ceeb02eb2fdf
4
+ data.tar.gz: c3f42a3bda7b6efd0292f7e3b364ce3595ac023216a3d5d1364d90257828c1a5
5
5
  SHA512:
6
- metadata.gz: cc64496f6e70c4d737ddf6bf091988ab01425802852034dd1d0c083bee1cda38ee25381927b498fc74c0094f27c071b71e10b360fc00ac477e81635b509d1915
7
- data.tar.gz: ac2c18d0bd040e892caf008de55550cd09322fb69b09d15efd6adf6d147ce399b8e5aff547603af1311c7ebb86f0a8051da40211791d70042ee4e87a57ef23b3
6
+ metadata.gz: 7f0748ebb4cfeb31128024ac32226811205827db8ad381226dd3f04532c6cf2fc700448712e6bd16ba86770574bd161eebb56d6c44b20b03694ed5a0a9160ddc
7
+ data.tar.gz: 762bca6004ea991b05cad4df3a10f4cf16ba9c3f91e1d2d6b32c29dada7e2a9b7f8a6572d8096c6d53b5e3777a2e802662dab85df49ffecf4083f84b4caeacf8
data/README.md CHANGED
@@ -13,11 +13,19 @@ Add this line to your application's Gemfile:
13
13
 
14
14
  ```ruby
15
15
 
16
+ gem 'eitil' # check the latest version on https://rubygems.org/gems/eitil
17
+
18
+ ```
19
+
20
+ Or, if you want a specific branch (requires auth for private branch):
21
+
22
+ ```ruby
23
+
16
24
  gem 'eitil', git: 'https://github.com/eitje-app/eitil_engine', branch: 'production'
17
25
 
18
26
  ```
19
27
 
20
- Or this line, with your own path correctly set, for development purposes:
28
+ Or, for development purposes:
21
29
 
22
30
  ```ruby
23
31
 
@@ -79,10 +87,11 @@ all_methods(include_ancestors = true, grep: nil)
79
87
  ## Module
80
88
 
81
89
  ```ruby
82
- include_concerns_of(*directories)
83
- # includes all models/concerns/{sub_directory}/* within a module or class
90
+ include_concerns_of(*directories, namespace: nil)
91
+ # includes models/concerns/{directories}/* if no namespace if given, or all concerns within the given namespace
84
92
  # call as: include_concerns_of :user, :mail
85
93
  # => includes all modules of models/concerns/user/* and models/oncerns/mail/*
94
+ # or call as: include_concerns_of :request_service, namespace: Eivid::Concerns
86
95
  ```
87
96
 
88
97
 
@@ -109,6 +118,16 @@ slice_params(*args)
109
118
 
110
119
 
111
120
 
121
+ ## ApplicationRecord
122
+
123
+ ```ruby
124
+ self.all_associations
125
+ # returns all associations for a given model
126
+ # call as: Environment.all_associations
127
+ ```
128
+
129
+
130
+
112
131
  ## DateTime
113
132
 
114
133
  ```ruby
@@ -263,6 +282,22 @@ Scopes are generated through the columns of your model's database table. Which s
263
282
  .{column_name}_between_dates(start_date, end_date)
264
283
  .{column_name}_oldest_first
265
284
  .{column_name}_newest_first
285
+
286
+ # columns of datatype: integer
287
+ .{column_name}_equal_to(number)
288
+ .{column_name}_lower_than(number)
289
+ .{column_name}_higher_than(number)
290
+ .{column_name}_between(min, max)
291
+ .{column_name}_ascending
292
+ .{column_name}_descending
293
+
294
+ # columns of datatype: float
295
+ .{column_name}_equal_to(number)
296
+ .{column_name}_lower_than(number)
297
+ .{column_name}_higher_than(number)
298
+ .{column_name}_between(min, max)
299
+ .{column_name}_ascending
300
+ .{column_name}_descending
266
301
  ```
267
302
 
268
303
  ### Configuration
@@ -1,4 +1,4 @@
1
- module ApplicationMonkey
1
+ module ApplicationControllerMonkey
2
2
  extend ActiveSupport::Concern
3
3
  included do
4
4
 
@@ -11,4 +11,4 @@ module ApplicationMonkey
11
11
  end
12
12
  end
13
13
 
14
- ApplicationController.send :include, ApplicationMonkey
14
+ ApplicationController.send :include, ApplicationControllerMonkey
@@ -0,0 +1,17 @@
1
+ require "#{Eitil::Engine.root.to_s}/config/initializers/wrappers/scopes/default_scopes.rb"
2
+
3
+ module ApplicationRecordMonkey
4
+ extend ActiveSupport::Concern
5
+ included do
6
+
7
+ def self.all_associations
8
+ reflect_on_all_associations.map do |assoc|
9
+ assoc_type = assoc.association_class.to_s.split('::').last
10
+ "#{assoc.name} (#{assoc_type})"
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+
17
+ ApplicationRecord.send :include, ApplicationRecordMonkey
@@ -1,7 +1,7 @@
1
1
  class Module
2
2
 
3
- def include_concerns_of(*directories)
4
- directories.map! { |dir| dir.to_s.camelcase }
3
+ def include_concerns_of(*directories, namespace: nil)
4
+ directories.map! { |dir| "#{namespace}::#{dir.to_s.camelcase}" }
5
5
 
6
6
  directories.each do |dir|
7
7
  konstants = dir.constantize.constants(false)
@@ -11,19 +11,28 @@ module Eitil
11
11
  eitil_scope :"#{column}_on_date", -> (date) { where("#{column} = ?", date) }
12
12
  eitil_scope :"#{column}_before_date", -> (date) { where("#{column} = ?", date) }
13
13
  eitil_scope :"#{column}_after_date", -> (date) { where("#{column} = ?", date) }
14
-
15
14
  eitil_scope :"#{column}_between_dates", -> (from, till) { where("#{column} >= ? and #{column} <= ?", from, till) }
16
15
 
17
16
  eitil_scope :"#{column}_oldest_first", -> { order("#{column} ASC") }
18
17
  eitil_scope :"#{column}_newest_first", -> { order("#{column} DESC") }
19
18
  }
20
19
 
20
+ SharableNumScopes = -> (column) {
21
+ eitil_scope :"#{column}_equal_to", -> (number) { where("#{column} = ?", number) }
22
+ eitil_scope :"#{column}_lower_than", -> (number) { where("#{column} = <", number) }
23
+ eitil_scope :"#{column}_higher_than", -> (number) { where("#{column} = >", number) }
24
+ eitil_scope :"#{column}_between", -> (min, max) { where("#{column} >= ? and #{column} <= ?", min, max) }
25
+
26
+ eitil_scope :"#{column}_ascending", -> { order("#{column} ASC") }
27
+ eitil_scope :"#{column}_descending", -> { order("#{column} DESC") }
28
+ }
29
+
21
30
  class << self
22
31
 
23
32
  private
24
33
 
25
34
  def use_eitil_scopes
26
- %i[boolean datetime date].each { |_type| send :"create_eitil_#{_type}_scopes" }
35
+ %i[boolean datetime date integer float].each { |_type| send :"create_eitil_#{_type}_scopes" }
27
36
  end
28
37
 
29
38
  def eitil_scope(_name, _proc)
@@ -53,6 +62,18 @@ module Eitil
53
62
  end
54
63
  end
55
64
 
65
+ def create_eitil_integer_scopes
66
+ columns_of_type(:integer).map do |column, object|
67
+ SharableNumScopes.call column
68
+ end
69
+ end
70
+
71
+ def create_eitil_float_scopes
72
+ columns_of_type(:float).map do |column, object|
73
+ SharableNumScopes.call column
74
+ end
75
+ end
76
+
56
77
  end
57
78
 
58
79
  end
data/lib/eitil/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eitil
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eitil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurriaan Schrofer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-26 00:00:00.000000000 Z
11
+ date: 2021-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -53,6 +53,7 @@ files:
53
53
  - app/mailers/eitil/application_mailer.rb
54
54
  - app/models/eitil/application_record.rb
55
55
  - config/initializers/monkeys/application_controller.rb
56
+ - config/initializers/monkeys/application_record.rb
56
57
  - config/initializers/monkeys/date_time.rb
57
58
  - config/initializers/monkeys/hash.rb
58
59
  - config/initializers/monkeys/kernel.rb