basic-scopes 0.1.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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MmU3ZjU5ODRmZDQ4YWY1MmQyOGJkOGEyYTIyNmUxMzI5MWQzZmFhZg==
5
+ data.tar.gz: !binary |-
6
+ MGJiZDA1Y2E1ZjY5NzVmMGFmNGUzYjAwNDg4YWU1OWEwY2Q5Y2I4ZA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NGI4ZGMyZjY5ZjFiYmEyNDJjYzUwZjE2OWJiMzBmZmI3OWVhNzBkMjEwNzIw
10
+ ZjQwOTM4ZjljOTRkY2NjOTExYTdjY2YyNjkxM2EyYjAxOTczNmEwM2QyNDE2
11
+ OTU2YzVlNjRlOGRlNDhkMTI2ZTJlYzBmYjA0YWNlYzhkYTMyODk=
12
+ data.tar.gz: !binary |-
13
+ NGY1ZmUyYzE3NDg5ZjZjNzNjMWI4YjhkN2JmYzY2YmE2M2JjMTY3NDc2OTc0
14
+ MjQwNDVhNzI0YmJmMjI1NGMyOTFhMzA0NmFmYWNiOWI1N2UxYjVhY2YwODNh
15
+ MWJjMGRjOGU1MGRlNTRmN2RkNjAxZTkzY2EyNTk3YzMzMjI5YTE=
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ ## basic-scopes
2
+ [![Build Status](https://travis-ci.org/vforge/basic-scopes.png)](https://travis-ci.org/vforge/basic-scopes)
3
+ [![Dependency Status](https://gemnasium.com/vforge/basic-scopes.png)](https://gemnasium.com/vforge/basic-scopes)
4
+ [![Code Climate](https://codeclimate.com/github/vforge/basic-scopes.png)](https://codeclimate.com/github/vforge/basic-scopes)
5
+
6
+ ActiveRecord basic scopes.
7
+
8
+ ## Usage
9
+
10
+ You can use basic-scopes just as normal ActiveRecord methods.
11
+
12
+ ### Filtering
13
+ * `except_ids(ids)` - all records without matching `ID` field
14
+ * `filter_ids(ids)` - all recorth with matching `ID` field
15
+ * `filter_updated_since(time)` - all records that have `UPDATED_AT` field greater than `time`
16
+ * `filter_updated_till(time)` - all records that have `UPDATED_AT` field lesser than `time`
17
+ * `filter_created_since(time)` - all records that have `CREATED_AT` field greater than `time`
18
+ * `filter_created_till(time)` - all records that have `CREATED_AT` field lesser than `time`
19
+
20
+
21
+ **NOTE**: `ids` param can be single `ID` or Array of `ID`s
22
+
23
+ ### Sorting / OrderBy
24
+ * `by_id` - order by `ID` descending
25
+ * `by_id_reversed` - order by `ID` ascending
26
+ * `by_created_at` - order by `CREATED_AT` descending
27
+ * `by_created_at_reversed` - order by `CREATED_AT` ascending
28
+ * `by_updated_at` - order by `UPDATED_AT` descending
29
+ * `by_updated_at_reversed` - order by `UPDATED_AT` ascending
30
+
31
+ ## Example
32
+
33
+ `User.filter_last_update(1.day).by_updated_at` - All users updated in the last one day, ordered by time
34
+
35
+
36
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/vforge/basic-scopes/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
37
+
@@ -0,0 +1,69 @@
1
+ require "basic-scopes/version"
2
+
3
+ require "active_record" unless defined?(ActiveRecord)
4
+ require "active_support" unless defined?(ActiveSupport)
5
+
6
+ module BasicScopes
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ class << self
11
+ def except_ids(ids)
12
+ self.where("#{self.table_name}.id NOT IN (?)", ids)
13
+ end
14
+
15
+ def filter_ids(ids)
16
+ self.where("#{self.table_name}.id IN (?)", ids)
17
+ end
18
+
19
+ def filter_updated_since(time)
20
+ self.where("#{self.table_name}.updated_at > ?", time.ago)
21
+ end
22
+
23
+ def filter_updated_till(time)
24
+ self.where("#{self.table_name}.updated_at < ?", time.ago)
25
+ end
26
+
27
+ def filter_created_since(time)
28
+ self.where("#{self.table_name}.created_at > ?", time.ago)
29
+ end
30
+
31
+ def filter_created_till(time)
32
+ self.where("#{self.table_name}.created_at < ?", time.ago)
33
+ end
34
+
35
+
36
+ def by_id
37
+ self.order("#{self.table_name}.id DESC")
38
+ end
39
+
40
+ def by_id_reversed
41
+ self.order("#{self.table_name}.id ASC")
42
+ end
43
+
44
+ def by_created_at
45
+ self.order("#{self.table_name}.created_at DESC")
46
+ end
47
+
48
+ def by_created_at_reversed
49
+ self.order("#{self.table_name}.created_at ASC")
50
+ end
51
+
52
+ def by_updated_at
53
+ self.order("#{self.table_name}.updated_at DESC")
54
+ end
55
+
56
+ def by_updated_at_reversed
57
+ self.order("#{self.table_name}.updated_at ASC")
58
+ end
59
+ end
60
+ end
61
+
62
+ module ClassMethods
63
+ end
64
+ end
65
+
66
+ # include the extension
67
+ ActiveRecord::Base.send :include, BasicScopes
68
+
69
+
@@ -0,0 +1,3 @@
1
+ module BasicScopes
2
+ VERSION = "0.1.2"
3
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: basic-scopes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Bartosz "V." Bentkowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ description: ActiveRecord basic scopes.
42
+ email: bartosz.bentkowski@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - README.md
48
+ - lib/basic-scopes.rb
49
+ - lib/basic-scopes/version.rb
50
+ homepage: https://github.com/vforge/basic-scopes
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 2.2.2
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: ActiveRecord basic scopes.
74
+ test_files: []