birthday 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,19 +4,78 @@ This is a small gem that hooks into ActiveRecord and allows to tag a database fi
4
4
 
5
5
  ## How To Install
6
6
 
7
- After the gem has been properly tested, it will be released on RubyGems, and will be available to be installed with:
7
+ To install this gem, fire this command from your terminal:
8
8
 
9
9
  gem install birthday
10
10
 
11
- or in your Gemfile:
11
+ or add this line to your Gemfile:
12
12
 
13
13
  gem 'birthday', '~> 0.1.0'
14
14
 
15
15
  ## Synopsis
16
16
 
17
- Read [a blog post about the gem](http://blog.railslove.com/2011/10/17/birthday-gem-easy-anniversaries-handling-ruby/) at Railslove blog to get a comprehensive guide to usage of this gem.
17
+ After installing this gem, you are able to work with anniversaries, such as birthdays in such a manner:
18
18
 
19
- You can create your own adapters for the ORM adapters we're not supporting yet by writing a class with a class method `scope_hash`, which will return a hash normally used in `active_record` scopes.
19
+ class User < ActiveRecord::Base
20
+
21
+ acts_as_birthday :birthday
22
+
23
+ end
24
+
25
+ Add `acts_as_birthday :field_name` to your ActiveRecord model (or symbols for multiple fields, if you need to), and right away you can access methods:
26
+
27
+ * `birthday_age` - which will calculate current anniversary/age from the point in time,
28
+ * `birthday_today?` - which will return true or false, depending on whether the anniversary happens today.
29
+
30
+ ### Created instance methods
31
+
32
+ If you add more fields to `acts_as_birthday` method, like:
33
+
34
+ acts_as_birthday :birthday, :anniversary, :something_else
35
+
36
+ it will automatically create methods: `birthday_age`, `birthday_today?`, `anniversary_age`, `anniversary_today?`, `something_else_age`, `something_else_today?`.
37
+
38
+ ### Created scopes
39
+
40
+ On top of that you get useful scopes: `find_birthdays_for`, `find_anniversaries_for` and `find_something_elses_for`.
41
+
42
+ These scopes accept maximum of two parameters, which have to respond to method `to_date` (by default objects of class Date, Time and DateTime). Thanks to these now you can search for birthdays...
43
+
44
+ * on a specific date:
45
+
46
+ > User.find_birthdays_for(Date.parse('04-04-2000'))
47
+ => [#<User id: 23, birthday: "1961-04-04">, #<User id: 34, birthday: "1985-04-04">]
48
+
49
+ * between a specific range:
50
+
51
+ > User.find_birthdays_for(Date.parse('04-04-2000'), Date.parse('05-04-2000'))
52
+ => [#<User id: 23, birthday: "1961-04-04">, #<User id: 34, birthday: "1985-04-04">, #<User id: 56, birthday: "1976-04-24">, #<User id: 57, birthday: "1958-04-30">, #<User id: 60, birthday: "1986-05-04">]
53
+
54
+ * and even at the turn of the years:
55
+
56
+ # This will search for birthdays between 12.12 and 3.01
57
+ > User.find_birthdays_for(Date.parse('12-12-2000'), Date.parse('03-01-2001'))
58
+ => [#<User id: 1, birthday: "1961-12-14">, #<User id: 12, birthday: "1985-12-15">, #<User id: 25, birthday: "1961-12-24">, #<User id: 27, birthday: "1985-01-01">, #<User id: 40, birthday: "1961-01-02">]
59
+
60
+ Since all these are essentially scopes, there's nothing stopping you from chaining them with other scopes:
61
+
62
+ class User < ActiveRecord::Base
63
+
64
+ acts_as_birthday :birthday
65
+
66
+ scope :admins, {:is_admin => true}
67
+ scope :named_like, lambda { |name| { :conditions => [ "first_name LIKE :q OR email LIKE :q OR last_name LIKE :q", { :q => "%#{name}%" } ] } }
68
+
69
+ end
70
+
71
+
72
+ > User.admins.named_like("Mike").find_birthdays_for(Date.parse('12-12-2000'), Date.parse('03-01-2001'))
73
+
74
+ ### Your own adapters
75
+
76
+ At this moment, this gem supports only MySQL and PostgreSQL databases. If you want to support another type of database (perhaps SQLite), you can write your own adapter.
77
+
78
+ You can create your own birthday adapters for the ORM adapters we're not supporting yet by writing a class with a class method `scope_hash`, which will return a hash normally used in `active_record` scopes.
20
79
 
21
80
  module Railslove
22
81
  module Acts
@@ -36,6 +95,8 @@ You can create your own adapters for the ORM adapters we're not supporting yet b
36
95
 
37
96
  With this namespacing (`Railslove::Acts::Birthday::Adapter`) and naming the class after `active_record`'s ORM adapter (like `SqliteAdapter` in the example above) you can automatically use your own adapters with this gem.
38
97
 
98
+ If you happen to write one of the adapters, don't hesitate to [make a pull request](https://github.com/railslove/birthday/pull/new/master)! You will help the whole Ruby community with it!
99
+
39
100
  ### To do
40
101
 
41
102
  * kick class_eval?
@@ -58,6 +119,11 @@ Copyright (c) 2011 Railslove
58
119
  * [@Holek (Mike Połtyn)](http://github.com/Holek)
59
120
  * [@Bumi (Michael Bumann)](http://github.com/bumi)
60
121
 
122
+ ## External links
123
+
124
+ * [Railslove blog post about the usage of this gem](http://blog.railslove.com/2011/10/17/birthday-gem-easy-anniversaries-handling-ruby/)
125
+ * [Rubygems.org site for `birthday` gem](http://rubygems.org/gems/birthday)
126
+
61
127
  ## License
62
128
 
63
129
  The MIT License
@@ -2,6 +2,7 @@
2
2
  module Railslove
3
3
  module Acts #:nodoc:
4
4
  module Birthday #:nodoc:
5
+ autoload :Adapter, 'railslove/acts/birthday/adapter'
5
6
 
6
7
  def self.included(base)
7
8
  base.extend ClassMethods
@@ -1,7 +1,7 @@
1
1
  module Railslove
2
2
  module Acts
3
3
  module Birthday
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: birthday
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Mike Po\xC5\x82tyn"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-18 00:00:00 Z
18
+ date: 2011-11-23 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rake