Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 5 additions & 25 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,12 @@ branches:
only:
- master
rvm:
- 1.9.3
- 2.0
- 2.1.10
- 2.2.6
- 2.3.3
- 2.4.0
- 2.3.7
- 2.4.4
- 2.5.1
- ruby-head
env:
- RAILS_VERSION='~> 3.2'
- RAILS_VERSION='~> 4.2'
- RAILS_VERSION='~> 5.0'
matrix:
exclude:

# Rails 5 only runs on ruby 2.3 and up
- rvm: 1.9.3
env: RAILS_VERSION='~> 5.0'
- rvm: 2.0
env: RAILS_VERSION='~> 5.0'
- rvm: 2.1.10
env: RAILS_VERSION='~> 5.0'
- rvm: 2.2.6
env: RAILS_VERSION='~> 5.0'

# Rails 3 no longer runs on ruby 2.4 and up
- rvm: 2.4.0
env: RAILS_VERSION='~> 3.2'
- rvm: ruby-head
env: RAILS_VERSION='~> 3.2'
- RAILS_VERSION='~> 5.1'
- RAILS_VERSION='~> 5.2'
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

* [ENHANCEMENT] Drop old versions of Ruby and Ruby on Rails

## 0.16.3 / 2018-07-23

* [FEATURE] Added support for parsing RDATE from iCal format
Expand Down
8 changes: 1 addition & 7 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
source 'https://rubygems.org'
gemspec

compatible_rails_versions = [
'>= 3.0.0',
('<5' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2'))
].compact

gem 'activesupport', (ENV['RAILS_VERSION'] || compatible_rails_versions), require: false
gem 'activesupport', (ENV['RAILS_VERSION'] || '>= 4.2'), require: false
gem 'i18n', require: false
gem 'tzinfo', require: false # only needed explicitly for RAILS_VERSION=3
3 changes: 0 additions & 3 deletions ice_cube.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'ice_cube/version'
Expand All @@ -15,9 +14,7 @@ Gem::Specification.new do |s|
s.version = IceCube::VERSION
s.platform = Gem::Platform::RUBY
s.files = Dir['lib/**/*.rb', 'config/**/*.yml']
s.test_files = Dir.glob('spec/*.rb')
s.require_paths = ['lib']
s.has_rdoc = true

s.add_development_dependency('rake')
s.add_development_dependency('rspec', '> 3')
Expand Down
6 changes: 1 addition & 5 deletions lib/ice_cube/builders/hash_builder.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module IceCube

class HashBuilder

def initialize(rule = nil)
@hash = { :validations => {}, :rule_type => rule.class.name }
@hash = { validations: {}, rule_type: rule.class.name }
end

def validations
Expand All @@ -21,7 +19,5 @@ def validations_array(type)
def to_hash
@hash
end

end

end
10 changes: 2 additions & 8 deletions lib/ice_cube/builders/ical_builder.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module IceCube

class IcalBuilder

ICAL_DAYS = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA']
ICAL_DAYS = %w[SU MO TU WE TH FR SA].freeze

def initialize
@hash = {}
Expand All @@ -23,9 +21,7 @@ def to_s
arr << "FREQ=#{freq.join(',')}"
end
arr.concat(@hash.map do |key, value|
if value.is_a?(Array)
"#{key}=#{value.join(',')}"
end
"#{key}=#{value.join(',')}" if value.is_a?(Array)
end.compact)
arr.join(';')
end
Expand Down Expand Up @@ -53,7 +49,5 @@ def self.ical_duration(duration)
repr << "#{duration}S" if duration > 0
"PT#{repr}"
end

end

end
19 changes: 8 additions & 11 deletions lib/ice_cube/builders/string_builder.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module IceCube

class StringBuilder

attr_writer :base

def initialize
Expand Down Expand Up @@ -37,14 +35,17 @@ def self.register_formatter(type, &formatter)
end

module Helpers

# influenced by ActiveSupport's to_sentence
def sentence(array)
case array.length
when 0 ; ''
when 1 ; array[0].to_s
when 2 ; "#{array[0]}#{IceCube::I18n.t('ice_cube.array.two_words_connector')}#{array[1]}"
else ; "#{array[0...-1].join(IceCube::I18n.t('ice_cube.array.words_connector'))}#{IceCube::I18n.t('ice_cube.array.last_word_connector')}#{array[-1]}"
when 0
''
when 1
array[0].to_s
when 2
"#{array[0]}#{IceCube::I18n.t('ice_cube.array.two_words_connector')}#{array[1]}"
else
"#{array[0...-1].join(IceCube::I18n.t('ice_cube.array.words_connector'))}#{IceCube::I18n.t('ice_cube.array.last_word_connector')}#{array[-1]}"
end
end

Expand All @@ -66,11 +67,7 @@ def ordinal(number)
IceCube::I18n.t('ice_cube.integer.ordinals')[:default]
number >= 0 ? ord : IceCube::I18n.t("ice_cube.integer.negative", ordinal: ord)
end

end

extend Helpers

end

end
1 change: 0 additions & 1 deletion lib/ice_cube/deprecated.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module IceCube
module Deprecated

# Define a deprecated alias for a method
# @param [Symbol] name - name of method to define
# @param [Symbol] replacement - name of method to replace (alias)
Expand Down
2 changes: 0 additions & 2 deletions lib/ice_cube/errors/count_exceeded.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module IceCube

# An exception for when a count on a Rule is passed
class CountExceeded < StopIteration
end

end
2 changes: 0 additions & 2 deletions lib/ice_cube/errors/until_exceeded.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module IceCube

# An exception for when an until date on a Rule is passed
class UntilExceeded < StopIteration
end

end
8 changes: 2 additions & 6 deletions lib/ice_cube/flexible_hash.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
require 'delegate'

module IceCube

# Find keys by symbol or string without symbolizing user input
# Due to the serialization format of ice_cube, this limited implementation
# is entirely sufficient

class FlexibleHash < SimpleDelegator

def [](key)
key = _match_key(key)
super
Expand All @@ -26,15 +23,14 @@ def delete(key)
private

def _match_key(key)
return key if __getobj__.has_key? key
return key if __getobj__.key? key

if Symbol == key.class
__getobj__.keys.detect { |k| return k if k == key.to_s }
elsif String == key.class
__getobj__.keys.detect { |k| return k if k.to_s == key }
end
key
end

end

end
1 change: 0 additions & 1 deletion lib/ice_cube/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module IceCube
module I18n

LOCALES_PATH = File.expand_path(File.join('..', '..', '..', 'config', 'locales'), __FILE__)

def self.t(*args)
Expand Down
22 changes: 10 additions & 12 deletions lib/ice_cube/input_alignment.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module IceCube
class InputAlignment

def initialize(rule, value, rule_part)
@rule = rule
@value = value
Expand All @@ -9,8 +8,8 @@ def initialize(rule, value, rule_part)

attr_reader :rule, :value, :rule_part

def verify(freq, options={}, &block)
@rule.validations[:interval] or return
def verify(freq, options = {}, &block)
@rule.validations[:interval] || return

case @rule
when DailyRule
Expand All @@ -29,20 +28,20 @@ def interval_validation
end

def interval_value
@interval_value ||= (rule_part == :interval) ? value : interval_validation.interval
@interval_value ||= rule_part == :interval ? value : interval_validation.interval
end

def fixed_validations
@fixed_validations ||= @rule.validations.values.flatten.select { |v|
@fixed_validations ||= @rule.validations.values.flatten.select do |v|
interval_type = (v.type == :wday ? :day : v.type)
v.class < Validations::FixedValue &&
interval_type == rule.base_interval_validation.type
}
end
end

def verify_freq_alignment(freq)
interval_validation.type == freq or return
(last_validation = fixed_validations.min_by(&:value)) or return
(interval_validation.type == freq) || return
(last_validation = fixed_validations.min_by(&:value)) || return

alignment = (value - last_validation.value) % interval_validation.interval
return if alignment.zero?
Expand Down Expand Up @@ -74,16 +73,15 @@ def verify_wday_alignment(freq)
return if interval_value == 1

if freq == :wday
return if (interval_value % 7).zero?
return if Array(@rule.validations[:day]).empty?
return if (interval_value % 7).zero? || Array(@rule.validations[:day]).empty?

message = "day can only be used with multiples of interval(7)"
else
(fixed_validation = fixed_validations.first) or return
(fixed_validation = fixed_validations.first) || return
message = "#{fixed_validation.key} can only be used with interval(1)"
end

yield ArgumentError.new(message)
end

end
end
2 changes: 2 additions & 0 deletions lib/ice_cube/null_i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ def self.t(key, options = {})
end
else
return base unless base.include?('%{')

base % options
end
end

def self.l(date_or_time, options = {})
return date_or_time.strftime(options[:format]) if options[:format]

date_or_time.strftime(t('ice_cube.date.formats.default'))
end

Expand Down
9 changes: 4 additions & 5 deletions lib/ice_cube/occurrence.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'delegate'

module IceCube

# Wraps start_time and end_time in a single concept concerning the duration.
# This delegates to the enclosed start_time so it behaves like a normal Time
# in almost all situations, however:
Expand Down Expand Up @@ -30,7 +29,7 @@ def self.name
alias first start_time
alias last end_time

def initialize(start_time, end_time=nil)
def initialize(start_time, end_time = nil)
@start_time = start_time
@end_time = end_time || start_time
__setobj__ @start_time
Expand All @@ -47,7 +46,7 @@ def <=>(other)
def is_a?(klass)
klass == ::Time || super
end
alias_method :kind_of?, :is_a?
alias kind_of? is_a?

def intersects?(other)
return cover?(other) unless other.is_a?(Occurrence) || other.is_a?(Range)
Expand All @@ -63,7 +62,7 @@ def intersects?(other)
def cover?(other)
to_range.cover?(other)
end
alias_method :include?, :cover?
alias include? cover?

def comparable_time
start_time
Expand All @@ -85,7 +84,7 @@ def to_time
# Optional format argument (e.g. :long, :short) supports Rails
# time formats and is only used when ActiveSupport is available.
#
def to_s(format=nil)
def to_s(format = nil)
if format && to_time.public_method(:to_s).arity != 0
t0, t1 = start_time.to_s(format), end_time.to_s(format)
else
Expand Down
Loading