diff --git a/Gemfile b/Gemfile index d1693d7..311becf 100644 --- a/Gemfile +++ b/Gemfile @@ -4,4 +4,4 @@ source "http://rubygems.org" gemspec gem 'autotest' -gem 'ruby-debug19' +# gem 'debugger' diff --git a/Gemfile.lock b/Gemfile.lock index 1261fd5..d129a9b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - schedule_atts (0.0.1) + schedule_atts (0.0.2) activesupport ice_cube (>= 0.6.4) @@ -10,15 +10,11 @@ GEM specs: ZenTest (4.4.2) activesupport (3.0.3) - archive-tar-minitar (0.5.2) autotest (4.4.6) ZenTest (>= 4.4.1) - columnize (0.3.2) diff-lcs (1.1.2) facets (2.9.0) ice_cube (0.6.4) - linecache19 (0.5.11) - ruby_core_source (>= 0.1.4) rspec (2.3.0) rspec-core (~> 2.3.0) rspec-expectations (~> 2.3.0) @@ -27,25 +23,12 @@ GEM rspec-expectations (2.3.0) diff-lcs (~> 1.1.2) rspec-mocks (2.3.0) - ruby-debug-base19 (0.11.24) - columnize (>= 0.3.1) - linecache19 (>= 0.5.11) - ruby_core_source (>= 0.1.4) - ruby-debug19 (0.11.6) - columnize (>= 0.3.1) - linecache19 (>= 0.5.11) - ruby-debug-base19 (>= 0.11.19) - ruby_core_source (0.1.4) - archive-tar-minitar (>= 0.5.2) PLATFORMS ruby DEPENDENCIES - activesupport autotest facets - ice_cube (>= 0.6.4) rspec (>= 2.3) - ruby-debug19 schedule_atts! diff --git a/lib/schedule_atts.rb b/lib/schedule_atts.rb index aa47472..76e1fc1 100644 --- a/lib/schedule_atts.rb +++ b/lib/schedule_atts.rb @@ -19,24 +19,27 @@ def schedule def schedule_attributes=(options) options = options.dup options[:interval] = options[:interval].to_i - options[:start_date] &&= ScheduleAttributes.parse_in_timezone(options[:start_date]) + options[:start_date] &&= ScheduleAttributes.parse_in_timezone(options[:start_date]) # IS: in icecube master, start_date is deprecated in favor of start_time options[:date] &&= ScheduleAttributes.parse_in_timezone(options[:date]) - options[:until_date] &&= ScheduleAttributes.parse_in_timezone(options[:until_date]) + # options[:until_date] &&= ScheduleAttributes.parse_in_timezone(options[:until_date]) + options[:end_time] &&= ScheduleAttributes.parse_in_timezone(options[:end_time]) if options[:ends] == 'eventually' # IS: in icecube master, end_time is deprecated in favor of until_time if options[:repeat].to_i == 0 @schedule = IceCube::Schedule.new(options[:date]) @schedule.add_recurrence_date(options[:date]) else - @schedule = IceCube::Schedule.new(options[:start_date]) + @schedule = IceCube::Schedule.new(options[:start_date], options) rule = case options[:interval_unit] when 'day' IceCube::Rule.daily options[:interval] when 'week' IceCube::Rule.weekly(options[:interval]).day( *IceCube::DAYS.keys.select{|day| options[day].to_i == 1 } ) + when 'month' + IceCube::Rule.monthly options[:interval] end - rule.until(options[:until_date]) if options[:ends] == 'eventually' + rule.until(options[:end_time]) if options[:ends] == 'eventually' @schedule.add_recurrence_rule(rule) end @@ -47,9 +50,11 @@ def schedule_attributes=(options) def schedule_attributes atts = {} - if rule = schedule.rrules.first + s = schedule_yaml ? IceCube::Schedule.from_yaml(schedule_yaml) : schedule + + if rule = s.rrules.last atts[:repeat] = 1 - atts[:start_date] = schedule.start_date.to_date + atts[:start_date] = s.start_date.to_date atts[:date] = Date.today # for populating the other part of the form rule_hash = rule.to_hash @@ -63,17 +68,20 @@ def schedule_attributes rule_hash[:validations][:day].each do |day_idx| atts[ DAY_NAMES[day_idx] ] = 1 end + when IceCube::MonthlyRule + atts[:interval_unit] = 'month' end if rule.until_date atts[:until_date] = rule.until_date.to_date + atts[:end_time] = rule.until_date.to_date atts[:ends] = 'eventually' else atts[:ends] = 'never' end else atts[:repeat] = 0 - atts[:date] = schedule.start_date.to_date + atts[:date] = s.start_date.to_date atts[:start_date] = Date.today # for populating the other part of the form end diff --git a/lib/schedule_atts/version.rb b/lib/schedule_atts/version.rb index a5916bd..05cca37 100644 --- a/lib/schedule_atts/version.rb +++ b/lib/schedule_atts/version.rb @@ -1,3 +1,3 @@ module ScheduleAtts - VERSION = "0.0.1" + VERSION = "0.0.2" end diff --git a/schedule_atts.gemspec b/schedule_atts.gemspec index 365682f..e11c867 100644 --- a/schedule_atts.gemspec +++ b/schedule_atts.gemspec @@ -4,11 +4,11 @@ require "schedule_atts/version" Gem::Specification.new do |s| s.name = "schedule_atts" - s.version = ScheduleAtts::VERSION + s.version = "0.0.2" s.platform = Gem::Platform::RUBY - s.authors = ["Mike Nicholaides"] - s.email = ["mike@ablegray.com"] - s.homepage = "http://ablegray.com" + s.authors = ["Mike Nicholaides, but then people at Kapost"] + s.email = ["mike@ablegray.com / dev@kapost.com"] + s.homepage = "http://ablegray.com / kapost.com" s.summary = %q{Provides form attributes setting a recurring schedule.} s.description = %q{Provides form attributes setting a recurring schedule.} diff --git a/spec/schedule_atts_spec.rb b/spec/schedule_atts_spec.rb index 6f506ba..3d713cc 100644 --- a/spec/schedule_atts_spec.rb +++ b/spec/schedule_atts_spec.rb @@ -38,7 +38,7 @@ end context "given :interval_unit=>day & :ends=>eventually & :until_date" do - let(:schedule_attributes){ { :repeat => '1', :start_date => '1-1-1985', :interval_unit => 'day', :interval => '3', :until_date => '29-12-1985', :ends => 'eventually' } } + let(:schedule_attributes){ { :repeat => '1', :start_date => '1-1-1985', :interval_unit => 'day', :interval => '3', :end_time => '29-12-1985', :ends => 'eventually' } } its(:start_date){ should == Date.new(1985, 1, 1).to_time } its(:rrules){ should == [ IceCube::Rule.daily(3).until(Date.new(1985, 12, 29).to_time) ] } it{ subject.first(3).should == [Date.civil(1985, 1, 1), Date.civil(1985, 1, 4), Date.civil(1985, 1, 7)].map(&:to_time) } @@ -99,9 +99,10 @@ before do schedule.add_recurrence_rule(IceCube::Rule.daily(4).until((Date.today+10).to_time)) end - it{ should == OpenStruct.new(:repeat => 1, :start_date => Date.tomorrow, :interval_unit => 'day', :interval => 4, :ends => 'eventually', :until_date => Date.today+10, :date => Date.today) } + it{ should == OpenStruct.new(:repeat => 1, :start_date => Date.tomorrow, :interval_unit => 'day', :interval => 4, :ends => 'eventually', :until_date => Date.today+10, :date => Date.today, :end_time => Date.today+10) } its(:start_date){ should be_a(Date) } its(:until_date){ should be_a(Date) } + its(:ends){ should eql("eventually") } end context "when it repeats weekly" do