duck_puncher 0.0.6 → 0.1.0

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: eacd12db4d97e6d70b3c7dcaa4a01850f287364d
4
- data.tar.gz: 57312f98a87dc5f07aa93ac1783e929fd65bb621
3
+ metadata.gz: c52a5b764d5dc7a286d6ada85982741b157205c3
4
+ data.tar.gz: dedd7138c91f6f476bc6f1d76ef4c558cd21f145
5
5
  SHA512:
6
- metadata.gz: 47457f129e09dc4489aaf495f77f33535f34625619a4d672edb9645158ca6350e7d0af36812eb1aae022ddfe27794f73223c59cbefe5b82564cc760cc659723e
7
- data.tar.gz: 6c697d9668c2e4d2c71e2fc9eb9426586b800f780098ad133ba413c69173dc1915cfd24283034ebc19283c3ec37a6add55df50c4ae8f54b6cd17bfa8d032383d
6
+ metadata.gz: f8085d2e1876893bf3c48aaeb09e2b7a5d5caa1d9579647d0e971a5ef5b67a30fb3e9c08442353069a2453053ad6495394b0c307f4f6448496ec9a529f1bdb59
7
+ data.tar.gz: c2eca11e375dc8016fa0c32077dcaa2d1d890cf0fa0cff166f8c4f7b290a0f5d590493a6824e436be1f94fa95083389671836b173bf51064c08ef7031dd55f95
@@ -0,0 +1,43 @@
1
+ module ActiveRecordExtensions
2
+ def self.included(base)
3
+ base.extend(ClassMethods)
4
+ end
5
+
6
+ def associations?
7
+ associations.present?
8
+ end
9
+
10
+ def associations
11
+ reflections.select { |key, _| send(key).present? rescue nil }.keys
12
+ end
13
+
14
+ module ClassMethods
15
+ def except_for(*ids)
16
+ scoped.where("#{quoted_table_name}.id NOT IN (?)", ids)
17
+ end
18
+
19
+ def since(time)
20
+ scoped.where("#{quoted_table_name}.created_at > ?", time)
21
+ end
22
+
23
+ alias created_since since
24
+
25
+ def before(time)
26
+ scoped.where("#{quoted_table_name}.created_at < ?", time)
27
+ end
28
+
29
+ def updated_since(time)
30
+ scoped.where("#{quoted_table_name}.updated_at > ?", time)
31
+ end
32
+
33
+ def between(start_at, end_at)
34
+ scoped.where("#{quoted_table_name}.created_at BETWEEN ? AND ", start_at, end_at)
35
+ end
36
+
37
+ def latest
38
+ scoped.order("#{quoted_table_name}.id ASC").last
39
+ end
40
+ end
41
+ end
42
+
43
+ ActiveRecord::Base.send(:include, ActiveRecordExtensions)
@@ -6,4 +6,4 @@ module DuckPuncher
6
6
  end
7
7
  end
8
8
 
9
- Array.send(:include, DuckPuncher::Array)
9
+ Array.send(:include, DuckPuncher::Array)
@@ -22,4 +22,4 @@ module DuckPuncher
22
22
  end
23
23
  end
24
24
 
25
- Hash.send(:include, DuckPuncher::Hash)
25
+ Hash.send(:include, DuckPuncher::Hash)
@@ -23,6 +23,7 @@ module DuckPuncher
23
23
  buffer
24
24
  end
25
25
 
26
+ # similar to Rails' #time_ago_in_words
26
27
  def to_time_ago
27
28
  secs = to_i
28
29
  mins = secs / 60
@@ -47,4 +48,4 @@ module DuckPuncher
47
48
  end
48
49
  end
49
50
 
50
- Numeric.send(:include, DuckPuncher::Numeric)
51
+ Numeric.send(:include, DuckPuncher::Numeric)
@@ -6,4 +6,4 @@ module DuckPuncher
6
6
  end
7
7
  end
8
8
 
9
- String.send(:include, DuckPuncher::String)
9
+ String.send(:include, DuckPuncher::String)
@@ -1,3 +1,3 @@
1
1
  module DuckPuncher
2
- VERSION = '0.0.6'.freeze
2
+ VERSION = '0.1.0'.freeze
3
3
  end
data/lib/duck_puncher.rb CHANGED
@@ -6,3 +6,5 @@ require 'duck_puncher/string'
6
6
 
7
7
  module DuckPuncher
8
8
  end
9
+
10
+ require 'duck_puncher/active_record_extensions' if defined?(Rails)
@@ -3,10 +3,10 @@ require 'duck_puncher'
3
3
 
4
4
  class HashTest < MiniTest::Unit::TestCase
5
5
  def test_seek
6
- my_hash = {a: 1, b: {c: 2}}
6
+ my_hash = { a: 1, b: { c: 2 } }
7
7
  assert_equal my_hash.seek(:a), 1
8
8
  assert_equal my_hash.seek(:b, :a), nil
9
9
  assert_equal my_hash.seek(:b, :c), 2
10
- assert_equal my_hash.seek(:b), {c: 2}
10
+ assert_equal my_hash.seek(:b), { c: 2 }
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duck_puncher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Buckley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-28 00:00:00.000000000 Z
11
+ date: 2014-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,7 @@ files:
52
52
  - Rakefile
53
53
  - duck_puncher.gemspec
54
54
  - lib/duck_puncher.rb
55
+ - lib/duck_puncher/active_record_extensions.rb
55
56
  - lib/duck_puncher/array.rb
56
57
  - lib/duck_puncher/hash.rb
57
58
  - lib/duck_puncher/numeric.rb