dgp-schedule_attributes 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +28 -0
  5. data/Appraisals +21 -0
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +63 -0
  8. data/README.markdown +78 -0
  9. data/Rakefile +7 -0
  10. data/gemfiles/rails_3.2.gemfile +8 -0
  11. data/gemfiles/rails_3.2.gemfile.lock +112 -0
  12. data/gemfiles/rails_4.0.gemfile +7 -0
  13. data/gemfiles/rails_4.0.gemfile.lock +76 -0
  14. data/gemfiles/rails_4.1.gemfile +7 -0
  15. data/gemfiles/rails_4.1.gemfile.lock +75 -0
  16. data/gemfiles/rails_4.2.gemfile +7 -0
  17. data/gemfiles/rails_4.2.gemfile.lock +75 -0
  18. data/gemfiles/rails_edge.gemfile +8 -0
  19. data/gemfiles/rails_edge.gemfile.lock +83 -0
  20. data/lib/schedule_attributes.rb +18 -0
  21. data/lib/schedule_attributes/active_record.rb +50 -0
  22. data/lib/schedule_attributes/configuration.rb +22 -0
  23. data/lib/schedule_attributes/core.rb +146 -0
  24. data/lib/schedule_attributes/extensions/ice_cube.rb +11 -0
  25. data/lib/schedule_attributes/form_builder.rb +42 -0
  26. data/lib/schedule_attributes/input.rb +159 -0
  27. data/lib/schedule_attributes/model.rb +24 -0
  28. data/lib/schedule_attributes/railtie.rb +13 -0
  29. data/lib/schedule_attributes/rule_parser.rb +25 -0
  30. data/lib/schedule_attributes/rule_parser/base.rb +96 -0
  31. data/lib/schedule_attributes/rule_parser/day.rb +13 -0
  32. data/lib/schedule_attributes/rule_parser/month.rb +40 -0
  33. data/lib/schedule_attributes/rule_parser/week.rb +18 -0
  34. data/lib/schedule_attributes/rule_parser/year.rb +21 -0
  35. data/lib/schedule_attributes/serializer.rb +30 -0
  36. data/lib/schedule_attributes/time_helpers.rb +36 -0
  37. data/lib/schedule_attributes/version.rb +3 -0
  38. data/schedule_attributes.gemspec +32 -0
  39. data/spec/active_record_integration_spec.rb +57 -0
  40. data/spec/schedule_attributes/configuration_spec.rb +29 -0
  41. data/spec/schedule_attributes/input_spec.rb +182 -0
  42. data/spec/schedule_attributes/rule_parser/day_spec.rb +113 -0
  43. data/spec/schedule_attributes/rule_parser/month_spec.rb +47 -0
  44. data/spec/schedule_attributes/rule_parser/week_spec.rb +36 -0
  45. data/spec/schedule_attributes/rule_parser/year_spec.rb +53 -0
  46. data/spec/schedule_attributes/rule_parser_spec.rb +18 -0
  47. data/spec/schedule_attributes/time_helpers_spec.rb +39 -0
  48. data/spec/schedule_attributes_spec.rb +226 -0
  49. data/spec/spec_helper.rb +11 -0
  50. data/spec/support/parser_macros.rb +31 -0
  51. data/spec/support/scheduled_active_record_model.rb +39 -0
  52. data/spec/support/scheduled_model.rb +16 -0
  53. metadata +234 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d2b20ff92edf87c3c1ca146374feba93269d76b4
4
+ data.tar.gz: 2a7689f49ace828eaf0dffe311e22e5a03dcf134
5
+ SHA512:
6
+ metadata.gz: 8c28fc148b35a7e4a79f4f677a43e931f1794de1daf33b2d19aed2b2b8e159b285901502d9a77c740150e5abd0a67fb1e2f9a60c70a883fc21e0db811367e3c5
7
+ data.tar.gz: aca106ba76e5fd28f47fadf356020231f0d3e77e297ae87b46299743eb071a2278c38ab9b6958250c71307fea08f3b0a0042506122a15d840f8c9583201b5aaa
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,28 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.5
5
+ - 2.2.2
6
+ - ruby-head
7
+ gemfile:
8
+ - gemfiles/rails_3.2.gemfile
9
+ - gemfiles/rails_4.0.gemfile
10
+ - gemfiles/rails_4.1.gemfile
11
+ - gemfiles/rails_4.2.gemfile
12
+ - gemfiles/rails_edge.gemfile
13
+ matrix:
14
+ exclude:
15
+ - rvm: 2.1.5
16
+ gemfile: gemfiles/rails_3.2.gemfile
17
+ - rvm: 2.2.2
18
+ gemfile: gemfiles/rails_3.2.gemfile
19
+ - rvm: ruby-head
20
+ gemfile: gemfiles/rails_3.2.gemfile
21
+ - rvm: 1.9.3
22
+ gemfile: gemfiles/rails_edge.gemfile
23
+ - rvm: 2.0.0
24
+ gemfile: gemfiles/rails_edge.gemfile
25
+ - rvm: 2.1.5
26
+ gemfile: gemfiles/rails_edge.gemfile
27
+ allow_failures:
28
+ - gemfile: gemfiles/rails_edge.gemfile
@@ -0,0 +1,21 @@
1
+ appraise "rails-3.2" do
2
+ gem 'activesupport', github: "rails/rails", branch: '3-2-stable'
3
+ gem 'strong_parameters'
4
+ end
5
+
6
+ appraise "rails-4.0" do
7
+ gem "activesupport", github: "rails/rails", branch: '4-0-stable'
8
+ end
9
+
10
+ appraise "rails-4.1" do
11
+ gem "activesupport", github: "rails/rails", branch: '4-1-stable'
12
+ end
13
+
14
+ appraise "rails-4.2" do
15
+ gem "activesupport", github: "rails/rails", branch: '4-2-stable'
16
+ end
17
+
18
+ appraise "rails-edge" do
19
+ gem "activesupport", github: "rails/rails"
20
+ gem 'arel', github: 'rails/arel'
21
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in schedule_atts.gemspec
4
+ gemspec
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dgp-schedule_attributes (0.4.0)
5
+ activesupport (>= 3.2)
6
+ ice_cube (~> 0.13)
7
+ tzinfo
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ activemodel (3.2.13)
13
+ activesupport (= 3.2.13)
14
+ builder (~> 3.0.0)
15
+ activerecord (3.2.13)
16
+ activemodel (= 3.2.13)
17
+ activesupport (= 3.2.13)
18
+ arel (~> 3.0.2)
19
+ tzinfo (~> 0.3.29)
20
+ activesupport (3.2.13)
21
+ i18n (= 0.6.1)
22
+ multi_json (~> 1.0)
23
+ appraisal (2.1.0)
24
+ bundler
25
+ rake
26
+ thor (>= 0.14.0)
27
+ arel (3.0.2)
28
+ builder (3.0.4)
29
+ coderay (1.0.9)
30
+ diff-lcs (1.2.5)
31
+ i18n (0.6.1)
32
+ ice_cube (0.13.0)
33
+ method_source (0.8.1)
34
+ multi_json (1.7.3)
35
+ pry (0.9.12.1)
36
+ coderay (~> 1.0.5)
37
+ method_source (~> 0.8)
38
+ slop (~> 3.4)
39
+ rake (10.0.4)
40
+ rspec (2.99.0)
41
+ rspec-core (~> 2.99.0)
42
+ rspec-expectations (~> 2.99.0)
43
+ rspec-mocks (~> 2.99.0)
44
+ rspec-core (2.99.2)
45
+ rspec-expectations (2.99.2)
46
+ diff-lcs (>= 1.1.3, < 2.0)
47
+ rspec-mocks (2.99.4)
48
+ slop (3.4.4)
49
+ sqlite3 (1.3.10)
50
+ thor (0.19.1)
51
+ tzinfo (0.3.37)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ activerecord (>= 3.2)
58
+ appraisal
59
+ dgp-schedule_attributes!
60
+ pry
61
+ rake
62
+ rspec (~> 2.99)
63
+ sqlite3
@@ -0,0 +1,78 @@
1
+ # Schedule Attributes
2
+ [![Build Status](https://travis-ci.org/dgilperez/schedule_attributes.png)](https://travis-ci.org/dgilperez/schedule_attributes)
3
+
4
+ Schedule Attributes allows models (ORM agnostic) to accept recurring schedule form parameters and translate them into an [IceCube](https://github.com/seejohnrun/ice_cube/) `Schedule` object. Schedule Attributes adds `#schedule_attributes` and `#schedule_attributes=` methods that let your model automatically populate Rails forms and receive HTML form parameters. Additionally, it provides access to the `IceCube::Schedule` object itself.
5
+
6
+ **Note**: This is a fork of [avit/schedule_attributes](https://github.com/avit/schedule_attributes), adding support for newest versions of *IceCube* and Rails 4 support.
7
+
8
+ ## Usage
9
+
10
+ Install using
11
+
12
+ gem install 'dgp-schedule_attributes'
13
+
14
+ Or add to your *Gemfile*:
15
+
16
+ gem 'dgp-schedule_attributes', '~> 0.4'
17
+
18
+ To use, include the `ScheduleAttributes` module in your model class.
19
+
20
+ class SomeModel
21
+ include ScheduleAttributes
22
+ end
23
+
24
+ Your model must respond to `:schedule_yaml` and `:schedule_yaml=`, because ScheduleAttributes will serialize and deserialize the schedule in YAML using this column. If you are using ActiveRecord, make a string column called `schedule_yaml`. If you're using Mongoid, make a string field like so: `field :schedule_yaml`.
25
+
26
+ You model will gain the following methods:
27
+
28
+ ## `schedule_attributes=`
29
+
30
+ Accepts form a parameter hash that represent a schedule, and creates an `IceCube::Schedule` object, and serializes it into your `schedule_yaml` field.
31
+
32
+ E.x.
33
+
34
+ @event.schedule_attributes = params[:event][:schedule_attributes]
35
+
36
+ ### Parameters Accepted
37
+
38
+ Because they are coming from a form, all parameters are expected to be in string format.
39
+
40
+ ##### `:repeat`
41
+
42
+ Can be `0` or `1`. The parameter should respond to `:to_i`. `0` indicates that the event does not repeat. Anything else indicates that the event repeats.
43
+
44
+ #### Parameters for non-repeating events
45
+
46
+ The following parameters will only be used if the `repeat` parameter is `0`.
47
+
48
+ ##### `:date`
49
+
50
+ The date that this (non-repeating) event is scheduled for. Should be parseable by `Time.parse`. This parameter is only used if `:repeat` is `0`.
51
+
52
+ #### Parameters for repeating events
53
+
54
+ The following parameters will only be used if the `repeat` parameter is `1`.
55
+
56
+ ##### `:start_date`
57
+
58
+ The date at which the event starts repeating. Must be parseable by `Time.parse`.
59
+
60
+ #### `:interval_unit`
61
+
62
+ The interval unit by which the event repeats. Can be `"day"` or `"week"`. For example, if the even repeats every day, this would be `"day"`. If it repeats weekly, this would be `"week"`.
63
+
64
+ #### `:interval`
65
+
66
+ The interval by which the event repeats. Should be an integer (in string format). For example, if the event repeats every other day, this parameter should be `2`, and `:interval_unit` should be `"day"`. If it repeats every other week, it should be `2` and interval unit should be `"week"`.
67
+
68
+ #### `:sunday`, `:monday`, `:tuesday`, `:wednesday`, `:thursday`, `:friday`, `:saturday`
69
+
70
+ Indicates with a `0` or `1` whether the event repeats on this day. For example, if the event repeats every other week on Tues and Thursday, then the parameters would include these: `:interval => "2", :interval_unit => "week", :tuesday => "1", :thursday => "1"`. These parameters are only used if `:repeat` is `1` and `:interval_unit` is `"week"`.
71
+
72
+ ## `schedule_attributes`
73
+
74
+ Provides an OStruct with methods that correspond to the attributes accepted by `#schedule_attributes=`. ActiveRecord can use this object to populate a form using [`FormHelper#fields_for`](http://apidock.com/rails/ActionView/Helpers/FormHelper/fields_for).
75
+
76
+ ##`schedule`
77
+
78
+ Returns a the `IceCube::Schedule` object that is serialized to the model's `schedule_yaml` field. If there is none, it returns a schedule with `start_date` of the current date, recurring daily, ending never.
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task :default => :spec
7
+
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "activesupport", :github => "rails/rails", :branch => "3-2-stable"
6
+ gem "strong_parameters"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,112 @@
1
+ GIT
2
+ remote: git://github.com/rails/rails.git
3
+ revision: d94d77c55c59f861201ac42f991ede0ff31481d5
4
+ branch: 3-2-stable
5
+ specs:
6
+ actionpack (3.2.22)
7
+ activemodel (= 3.2.22)
8
+ activesupport (= 3.2.22)
9
+ builder (~> 3.0.0)
10
+ erubis (~> 2.7.0)
11
+ journey (~> 1.0.4)
12
+ rack (~> 1.4.5)
13
+ rack-cache (~> 1.2)
14
+ rack-test (~> 0.6.1)
15
+ sprockets (~> 2.2.1)
16
+ activemodel (3.2.22)
17
+ activesupport (= 3.2.22)
18
+ builder (~> 3.0.0)
19
+ activerecord (3.2.22)
20
+ activemodel (= 3.2.22)
21
+ activesupport (= 3.2.22)
22
+ arel (~> 3.0.2)
23
+ tzinfo (~> 0.3.29)
24
+ activesupport (3.2.22)
25
+ i18n (~> 0.6, >= 0.6.4)
26
+ multi_json (~> 1.0)
27
+ railties (3.2.22)
28
+ actionpack (= 3.2.22)
29
+ activesupport (= 3.2.22)
30
+ rack-ssl (~> 1.3.2)
31
+ rake (>= 0.8.7)
32
+ rdoc (~> 3.4)
33
+ thor (>= 0.14.6, < 2.0)
34
+
35
+ PATH
36
+ remote: ../
37
+ specs:
38
+ dgp-schedule_attributes (0.4.0)
39
+ activesupport (>= 3.2)
40
+ ice_cube (~> 0.13)
41
+ tzinfo
42
+
43
+ GEM
44
+ remote: http://rubygems.org/
45
+ specs:
46
+ appraisal (2.1.0)
47
+ bundler
48
+ rake
49
+ thor (>= 0.14.0)
50
+ arel (3.0.3)
51
+ builder (3.0.4)
52
+ coderay (1.1.0)
53
+ diff-lcs (1.2.5)
54
+ erubis (2.7.0)
55
+ hike (1.2.3)
56
+ i18n (0.7.0)
57
+ ice_cube (0.13.0)
58
+ journey (1.0.4)
59
+ json (1.8.3)
60
+ method_source (0.8.2)
61
+ multi_json (1.11.2)
62
+ pry (0.10.1)
63
+ coderay (~> 1.1.0)
64
+ method_source (~> 0.8.1)
65
+ slop (~> 3.4)
66
+ rack (1.4.7)
67
+ rack-cache (1.2)
68
+ rack (>= 0.4)
69
+ rack-ssl (1.3.4)
70
+ rack
71
+ rack-test (0.6.3)
72
+ rack (>= 1.0)
73
+ rake (10.4.2)
74
+ rdoc (3.12.2)
75
+ json (~> 1.4)
76
+ rspec (2.99.0)
77
+ rspec-core (~> 2.99.0)
78
+ rspec-expectations (~> 2.99.0)
79
+ rspec-mocks (~> 2.99.0)
80
+ rspec-core (2.99.2)
81
+ rspec-expectations (2.99.2)
82
+ diff-lcs (>= 1.1.3, < 2.0)
83
+ rspec-mocks (2.99.4)
84
+ slop (3.6.0)
85
+ sprockets (2.2.3)
86
+ hike (~> 1.2)
87
+ multi_json (~> 1.0)
88
+ rack (~> 1.0)
89
+ tilt (~> 1.1, != 1.3.0)
90
+ sqlite3 (1.3.10)
91
+ strong_parameters (0.2.3)
92
+ actionpack (~> 3.0)
93
+ activemodel (~> 3.0)
94
+ activesupport (~> 3.0)
95
+ railties (~> 3.0)
96
+ thor (0.19.1)
97
+ tilt (1.4.1)
98
+ tzinfo (0.3.44)
99
+
100
+ PLATFORMS
101
+ ruby
102
+
103
+ DEPENDENCIES
104
+ activerecord (>= 3.2)
105
+ activesupport!
106
+ appraisal
107
+ dgp-schedule_attributes!
108
+ pry
109
+ rake
110
+ rspec (~> 2.99)
111
+ sqlite3
112
+ strong_parameters
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "activesupport", :github => "rails/rails", :branch => "4-0-stable"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,76 @@
1
+ GIT
2
+ remote: git://github.com/rails/rails.git
3
+ revision: 9be9597e510d185ca7964d0a05b4ea2a7f2d50d1
4
+ branch: 4-0-stable
5
+ specs:
6
+ activemodel (4.0.13)
7
+ activesupport (= 4.0.13)
8
+ builder (~> 3.1.0)
9
+ activerecord (4.0.13)
10
+ activemodel (= 4.0.13)
11
+ activerecord-deprecated_finders (~> 1.0.2)
12
+ activesupport (= 4.0.13)
13
+ arel (~> 4.0.0)
14
+ activesupport (4.0.13)
15
+ i18n (~> 0.6, >= 0.6.9)
16
+ minitest (~> 4.2)
17
+ multi_json (~> 1.3)
18
+ thread_safe (~> 0.1)
19
+ tzinfo (~> 0.3.37)
20
+
21
+ PATH
22
+ remote: ../
23
+ specs:
24
+ dgp-schedule_attributes (0.4.0)
25
+ activesupport (>= 3.2)
26
+ ice_cube (~> 0.13)
27
+ tzinfo
28
+
29
+ GEM
30
+ remote: http://rubygems.org/
31
+ specs:
32
+ activerecord-deprecated_finders (1.0.4)
33
+ appraisal (2.1.0)
34
+ bundler
35
+ rake
36
+ thor (>= 0.14.0)
37
+ arel (4.0.2)
38
+ builder (3.1.4)
39
+ coderay (1.1.0)
40
+ diff-lcs (1.2.5)
41
+ i18n (0.7.0)
42
+ ice_cube (0.13.0)
43
+ method_source (0.8.2)
44
+ minitest (4.7.5)
45
+ multi_json (1.11.2)
46
+ pry (0.10.1)
47
+ coderay (~> 1.1.0)
48
+ method_source (~> 0.8.1)
49
+ slop (~> 3.4)
50
+ rake (10.4.2)
51
+ rspec (2.99.0)
52
+ rspec-core (~> 2.99.0)
53
+ rspec-expectations (~> 2.99.0)
54
+ rspec-mocks (~> 2.99.0)
55
+ rspec-core (2.99.2)
56
+ rspec-expectations (2.99.2)
57
+ diff-lcs (>= 1.1.3, < 2.0)
58
+ rspec-mocks (2.99.4)
59
+ slop (3.6.0)
60
+ sqlite3 (1.3.10)
61
+ thor (0.19.1)
62
+ thread_safe (0.3.5)
63
+ tzinfo (0.3.44)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ activerecord (>= 3.2)
70
+ activesupport!
71
+ appraisal
72
+ dgp-schedule_attributes!
73
+ pry
74
+ rake
75
+ rspec (~> 2.99)
76
+ sqlite3
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "activesupport", :github => "rails/rails", :branch => "4-1-stable"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,75 @@
1
+ GIT
2
+ remote: git://github.com/rails/rails.git
3
+ revision: af68f1f4dd1c716fdab49de9d7e70656346db70e
4
+ branch: 4-1-stable
5
+ specs:
6
+ activemodel (4.1.13)
7
+ activesupport (= 4.1.13)
8
+ builder (~> 3.1)
9
+ activerecord (4.1.13)
10
+ activemodel (= 4.1.13)
11
+ activesupport (= 4.1.13)
12
+ arel (~> 5.0.0)
13
+ activesupport (4.1.13)
14
+ i18n (~> 0.6, >= 0.6.9)
15
+ json (~> 1.7, >= 1.7.7)
16
+ minitest (~> 5.1)
17
+ thread_safe (~> 0.1)
18
+ tzinfo (~> 1.1)
19
+
20
+ PATH
21
+ remote: ../
22
+ specs:
23
+ dgp-schedule_attributes (0.4.0)
24
+ activesupport (>= 3.2)
25
+ ice_cube (~> 0.13)
26
+ tzinfo
27
+
28
+ GEM
29
+ remote: http://rubygems.org/
30
+ specs:
31
+ appraisal (2.1.0)
32
+ bundler
33
+ rake
34
+ thor (>= 0.14.0)
35
+ arel (5.0.1.20140414130214)
36
+ builder (3.2.2)
37
+ coderay (1.1.0)
38
+ diff-lcs (1.2.5)
39
+ i18n (0.7.0)
40
+ ice_cube (0.13.0)
41
+ json (1.8.3)
42
+ method_source (0.8.2)
43
+ minitest (5.8.0)
44
+ pry (0.10.1)
45
+ coderay (~> 1.1.0)
46
+ method_source (~> 0.8.1)
47
+ slop (~> 3.4)
48
+ rake (10.4.2)
49
+ rspec (2.99.0)
50
+ rspec-core (~> 2.99.0)
51
+ rspec-expectations (~> 2.99.0)
52
+ rspec-mocks (~> 2.99.0)
53
+ rspec-core (2.99.2)
54
+ rspec-expectations (2.99.2)
55
+ diff-lcs (>= 1.1.3, < 2.0)
56
+ rspec-mocks (2.99.4)
57
+ slop (3.6.0)
58
+ sqlite3 (1.3.10)
59
+ thor (0.19.1)
60
+ thread_safe (0.3.5)
61
+ tzinfo (1.2.2)
62
+ thread_safe (~> 0.1)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ activerecord (>= 3.2)
69
+ activesupport!
70
+ appraisal
71
+ dgp-schedule_attributes!
72
+ pry
73
+ rake
74
+ rspec (~> 2.99)
75
+ sqlite3