Skip to content

Commit 1653b81

Browse files
committed
Fix initial issues identified by standard
1 parent 3aa995d commit 1653b81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1690
-2021
lines changed

.standard_todo.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Auto generated files with errors to ignore.
2+
# Remove from this list as you refactor files.
3+
---
4+
ignore:
5+
- lib/ice_cube/parsers/yaml_parser.rb:
6+
- Security/YAMLLoad
7+
- lib/ice_cube/rule.rb:
8+
- Security/YAMLLoad
9+
- spec/examples/serialization_spec.rb:
10+
- Security/YAMLLoad
11+
- spec/examples/to_yaml_spec.rb:
12+
- Security/YAMLLoad

Gemfile

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22
gemspec
33

44
compatible_rails_versions = [
5-
'>= 3.0.0',
6-
('<5' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2'))
5+
">= 3.0.0",
6+
("<5" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2.2"))
77
].compact
88

9-
gem 'activesupport', (ENV['RAILS_VERSION'] || compatible_rails_versions), require: false
10-
gem 'i18n', require: false
11-
gem 'tzinfo', require: false # only needed explicitly for RAILS_VERSION=3
9+
gem "activesupport", (ENV["RAILS_VERSION"] || compatible_rails_versions), require: false
10+
gem "i18n", require: false
11+
gem "tzinfo", require: false # only needed explicitly for RAILS_VERSION=3

Rakefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ require "rspec/core/rake_task"
22
require "bundler/gem_tasks"
33

44
RSpec::Core::RakeTask.new(:spec)
5-
task :build => :spec
6-
task :default => :spec
5+
task build: :spec
6+
task default: :spec

ice_cube.gemspec

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
# encoding: utf-8
2-
lib = File.expand_path('../lib', __FILE__)
1+
lib = File.expand_path("../lib", __FILE__)
32
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4-
require 'ice_cube/version'
3+
require "ice_cube/version"
54

65
Gem::Specification.new do |s|
7-
s.name = 'ice_cube'
8-
s.summary = 'Ruby Date Recurrence Library'
9-
s.description = 'ice_cube is a recurring date library for Ruby. It allows for quick, programatic expansion of recurring date rules.'
10-
s.author = 'John Crepezzi'
11-
s.email = '[email protected]'
12-
s.homepage = 'http://seejohnrun.github.com/ice_cube/'
13-
s.license = 'MIT'
6+
s.name = "ice_cube"
7+
s.summary = "Ruby Date Recurrence Library"
8+
s.description = "ice_cube is a recurring date library for Ruby. It allows for quick, programatic expansion of recurring date rules."
9+
s.author = "John Crepezzi"
10+
s.email = "[email protected]"
11+
s.homepage = "http://seejohnrun.github.com/ice_cube/"
12+
s.license = "MIT"
1413

15-
s.version = IceCube::VERSION
16-
s.platform = Gem::Platform::RUBY
17-
s.files = Dir['lib/**/*.rb', 'config/**/*.yml']
18-
s.test_files = Dir.glob('spec/*.rb')
19-
s.require_paths = ['lib']
14+
s.version = IceCube::VERSION
15+
s.platform = Gem::Platform::RUBY
16+
s.files = Dir["lib/**/*.rb", "config/**/*.yml"]
17+
s.test_files = Dir.glob("spec/*.rb")
18+
s.require_paths = ["lib"]
2019

21-
s.add_development_dependency('rake')
22-
s.add_development_dependency('rspec', '> 3')
20+
s.add_development_dependency("rake")
21+
s.add_development_dependency("rspec", "> 3")
2322
s.add_development_dependency("standard")
2423
end

lib/ice_cube.rb

+51-52
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,70 @@
1-
require 'date'
2-
require 'ice_cube/deprecated'
1+
require "date"
2+
require "ice_cube/deprecated"
33

44
module IceCube
5+
autoload :VERSION, "ice_cube/version"
56

6-
autoload :VERSION, 'ice_cube/version'
7+
autoload :TimeUtil, "ice_cube/time_util"
8+
autoload :FlexibleHash, "ice_cube/flexible_hash"
9+
autoload :I18n, "ice_cube/i18n"
710

8-
autoload :TimeUtil, 'ice_cube/time_util'
9-
autoload :FlexibleHash, 'ice_cube/flexible_hash'
10-
autoload :I18n, 'ice_cube/i18n'
11+
autoload :Rule, "ice_cube/rule"
12+
autoload :Schedule, "ice_cube/schedule"
13+
autoload :Occurrence, "ice_cube/occurrence"
1114

12-
autoload :Rule, 'ice_cube/rule'
13-
autoload :Schedule, 'ice_cube/schedule'
14-
autoload :Occurrence, 'ice_cube/occurrence'
15+
autoload :IcalBuilder, "ice_cube/builders/ical_builder"
16+
autoload :HashBuilder, "ice_cube/builders/hash_builder"
17+
autoload :StringBuilder, "ice_cube/builders/string_builder"
1518

16-
autoload :IcalBuilder, 'ice_cube/builders/ical_builder'
17-
autoload :HashBuilder, 'ice_cube/builders/hash_builder'
18-
autoload :StringBuilder, 'ice_cube/builders/string_builder'
19+
autoload :HashParser, "ice_cube/parsers/hash_parser"
20+
autoload :YamlParser, "ice_cube/parsers/yaml_parser"
21+
autoload :IcalParser, "ice_cube/parsers/ical_parser"
1922

20-
autoload :HashParser, 'ice_cube/parsers/hash_parser'
21-
autoload :YamlParser, 'ice_cube/parsers/yaml_parser'
22-
autoload :IcalParser, 'ice_cube/parsers/ical_parser'
23+
autoload :CountExceeded, "ice_cube/errors/count_exceeded"
24+
autoload :UntilExceeded, "ice_cube/errors/until_exceeded"
2325

24-
autoload :CountExceeded, 'ice_cube/errors/count_exceeded'
25-
autoload :UntilExceeded, 'ice_cube/errors/until_exceeded'
26+
autoload :ValidatedRule, "ice_cube/validated_rule"
27+
autoload :SingleOccurrenceRule, "ice_cube/single_occurrence_rule"
2628

27-
autoload :ValidatedRule, 'ice_cube/validated_rule'
28-
autoload :SingleOccurrenceRule, 'ice_cube/single_occurrence_rule'
29-
30-
autoload :SecondlyRule, 'ice_cube/rules/secondly_rule'
31-
autoload :MinutelyRule, 'ice_cube/rules/minutely_rule'
32-
autoload :HourlyRule, 'ice_cube/rules/hourly_rule'
33-
autoload :DailyRule, 'ice_cube/rules/daily_rule'
34-
autoload :WeeklyRule, 'ice_cube/rules/weekly_rule'
35-
autoload :MonthlyRule, 'ice_cube/rules/monthly_rule'
36-
autoload :YearlyRule, 'ice_cube/rules/yearly_rule'
29+
autoload :SecondlyRule, "ice_cube/rules/secondly_rule"
30+
autoload :MinutelyRule, "ice_cube/rules/minutely_rule"
31+
autoload :HourlyRule, "ice_cube/rules/hourly_rule"
32+
autoload :DailyRule, "ice_cube/rules/daily_rule"
33+
autoload :WeeklyRule, "ice_cube/rules/weekly_rule"
34+
autoload :MonthlyRule, "ice_cube/rules/monthly_rule"
35+
autoload :YearlyRule, "ice_cube/rules/yearly_rule"
3736

3837
module Validations
39-
autoload :FixedValue, 'ice_cube/validations/fixed_value'
40-
autoload :ScheduleLock, 'ice_cube/validations/schedule_lock'
41-
42-
autoload :Count, 'ice_cube/validations/count'
43-
autoload :Until, 'ice_cube/validations/until'
44-
45-
autoload :SecondlyInterval, 'ice_cube/validations/secondly_interval'
46-
autoload :MinutelyInterval, 'ice_cube/validations/minutely_interval'
47-
autoload :DailyInterval, 'ice_cube/validations/daily_interval'
48-
autoload :WeeklyInterval, 'ice_cube/validations/weekly_interval'
49-
autoload :MonthlyInterval, 'ice_cube/validations/monthly_interval'
50-
autoload :YearlyInterval, 'ice_cube/validations/yearly_interval'
51-
autoload :HourlyInterval, 'ice_cube/validations/hourly_interval'
52-
53-
autoload :HourOfDay, 'ice_cube/validations/hour_of_day'
54-
autoload :MonthOfYear, 'ice_cube/validations/month_of_year'
55-
autoload :MinuteOfHour, 'ice_cube/validations/minute_of_hour'
56-
autoload :SecondOfMinute, 'ice_cube/validations/second_of_minute'
57-
autoload :DayOfMonth, 'ice_cube/validations/day_of_month'
58-
autoload :DayOfWeek, 'ice_cube/validations/day_of_week'
59-
autoload :Day, 'ice_cube/validations/day'
60-
autoload :DayOfYear, 'ice_cube/validations/day_of_year'
38+
autoload :FixedValue, "ice_cube/validations/fixed_value"
39+
autoload :ScheduleLock, "ice_cube/validations/schedule_lock"
40+
41+
autoload :Count, "ice_cube/validations/count"
42+
autoload :Until, "ice_cube/validations/until"
43+
44+
autoload :SecondlyInterval, "ice_cube/validations/secondly_interval"
45+
autoload :MinutelyInterval, "ice_cube/validations/minutely_interval"
46+
autoload :DailyInterval, "ice_cube/validations/daily_interval"
47+
autoload :WeeklyInterval, "ice_cube/validations/weekly_interval"
48+
autoload :MonthlyInterval, "ice_cube/validations/monthly_interval"
49+
autoload :YearlyInterval, "ice_cube/validations/yearly_interval"
50+
autoload :HourlyInterval, "ice_cube/validations/hourly_interval"
51+
52+
autoload :HourOfDay, "ice_cube/validations/hour_of_day"
53+
autoload :MonthOfYear, "ice_cube/validations/month_of_year"
54+
autoload :MinuteOfHour, "ice_cube/validations/minute_of_hour"
55+
autoload :SecondOfMinute, "ice_cube/validations/second_of_minute"
56+
autoload :DayOfMonth, "ice_cube/validations/day_of_month"
57+
autoload :DayOfWeek, "ice_cube/validations/day_of_week"
58+
autoload :Day, "ice_cube/validations/day"
59+
autoload :DayOfYear, "ice_cube/validations/day_of_year"
6160
end
6261

6362
# Define some useful constants
6463
ONE_SECOND = 1
6564
ONE_MINUTE = ONE_SECOND * 60
66-
ONE_HOUR = ONE_MINUTE * 60
67-
ONE_DAY = ONE_HOUR * 24
68-
ONE_WEEK = ONE_DAY * 7
65+
ONE_HOUR = ONE_MINUTE * 60
66+
ONE_DAY = ONE_HOUR * 24
67+
ONE_WEEK = ONE_DAY * 7
6968

7069
# Defines the format used by IceCube when printing out Schedule#to_s.
7170
# Defaults to '%B %e, %Y'

lib/ice_cube/builders/hash_builder.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
module IceCube
2-
32
class HashBuilder
4-
53
def initialize(rule = nil)
6-
@hash = { :validations => {}, :rule_type => rule.class.name }
4+
@hash = {validations: {}, rule_type: rule.class.name}
75
end
86

97
def validations
@@ -21,7 +19,5 @@ def validations_array(type)
2119
def to_hash
2220
@hash
2321
end
24-
2522
end
26-
2723
end

lib/ice_cube/builders/ical_builder.rb

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module IceCube
2-
32
class IcalBuilder
4-
5-
ICAL_DAYS = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA']
3+
ICAL_DAYS = ["SU", "MO", "TU", "WE", "TH", "FR", "SA"]
64

75
def initialize
86
@hash = {}
@@ -19,41 +17,41 @@ def [](key)
1917
# Build for a single rule entry
2018
def to_s
2119
arr = []
22-
if freq = @hash.delete('FREQ')
23-
arr << "FREQ=#{freq.join(',')}"
20+
if (freq = @hash.delete("FREQ"))
21+
arr << "FREQ=#{freq.join(",")}"
2422
end
2523
arr.concat(@hash.map do |key, value|
2624
if value.is_a?(Array)
27-
"#{key}=#{value.join(',')}"
25+
"#{key}=#{value.join(",")}"
2826
end
2927
end.compact)
30-
arr.join(';')
28+
arr.join(";")
3129
end
3230

3331
def self.ical_utc_format(time)
3432
time = time.dup.utc
35-
IceCube::I18n.l(time, format: '%Y%m%dT%H%M%SZ') # utc time
33+
IceCube::I18n.l(time, format: "%Y%m%dT%H%M%SZ") # utc time
3634
end
3735

3836
def self.ical_format(time, force_utc)
3937
time = time.dup.utc if force_utc
4038
if time.utc?
41-
":#{IceCube::I18n.l(time, format: '%Y%m%dT%H%M%SZ')}" # utc time
39+
":#{IceCube::I18n.l(time, format: "%Y%m%dT%H%M%SZ")}" # utc time
4240
else
43-
";TZID=#{IceCube::I18n.l(time, format: '%Z:%Y%m%dT%H%M%S')}" # local time specified
41+
";TZID=#{IceCube::I18n.l(time, format: "%Z:%Y%m%dT%H%M%S")}" # local time specified
4442
end
4543
end
4644

4745
def self.ical_duration(duration)
48-
hours = duration / 3600; duration %= 3600
49-
minutes = duration / 60; duration %= 60
50-
repr = ''
46+
hours = duration / 3600
47+
duration %= 3600
48+
minutes = duration / 60
49+
duration %= 60
50+
repr = ""
5151
repr << "#{hours}H" if hours > 0
5252
repr << "#{minutes}M" if minutes > 0
5353
repr << "#{duration}S" if duration > 0
5454
"PT#{repr}"
5555
end
56-
5756
end
58-
5957
end
+9-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
module IceCube
2-
32
class StringBuilder
4-
53
attr_writer :base
64

75
def initialize
@@ -13,15 +11,15 @@ def piece(type, prefix = nil, suffix = nil)
1311
end
1412

1513
def to_s
16-
string = @base || ''
14+
string = @base || ""
1715
@types.each do |type, segments|
18-
if f = self.class.formatter(type)
16+
if (f = self.class.formatter(type))
1917
current = f.call(segments)
2018
else
2119
next if segments.empty?
2220
current = self.class.sentence(segments)
2321
end
24-
f = IceCube::I18n.t('ice_cube.string.format')[type] ? type : 'default'
22+
f = IceCube::I18n.t("ice_cube.string.format")[type] ? type : "default"
2523
string = IceCube::I18n.t("ice_cube.string.format.#{f}", rest: string, current: current)
2624
end
2725
string
@@ -37,14 +35,13 @@ def self.register_formatter(type, &formatter)
3735
end
3836

3937
module Helpers
40-
4138
# influenced by ActiveSupport's to_sentence
4239
def sentence(array)
4340
case array.length
44-
when 0 ; ''
45-
when 1 ; array[0].to_s
46-
when 2 ; "#{array[0]}#{IceCube::I18n.t('ice_cube.array.two_words_connector')}#{array[1]}"
47-
else ; "#{array[0...-1].join(IceCube::I18n.t('ice_cube.array.words_connector'))}#{IceCube::I18n.t('ice_cube.array.last_word_connector')}#{array[-1]}"
41+
when 0 then ""
42+
when 1 then array[0].to_s
43+
when 2 then "#{array[0]}#{IceCube::I18n.t("ice_cube.array.two_words_connector")}#{array[1]}"
44+
else; "#{array[0...-1].join(IceCube::I18n.t("ice_cube.array.words_connector"))}#{IceCube::I18n.t("ice_cube.array.last_word_connector")}#{array[-1]}"
4845
end
4946
end
5047

@@ -53,7 +50,7 @@ def nice_number(number)
5350
end
5451

5552
def ordinalize(number)
56-
IceCube::I18n.t('ice_cube.integer.ordinal', number: number, ordinal: ordinal(number))
53+
IceCube::I18n.t("ice_cube.integer.ordinal", number: number, ordinal: ordinal(number))
5754
end
5855

5956
def literal_ordinal(number)
@@ -63,14 +60,11 @@ def literal_ordinal(number)
6360
def ordinal(number)
6461
ord = IceCube::I18n.t("ice_cube.integer.ordinals")[number] ||
6562
IceCube::I18n.t("ice_cube.integer.ordinals")[number % 10] ||
66-
IceCube::I18n.t('ice_cube.integer.ordinals')[:default]
63+
IceCube::I18n.t("ice_cube.integer.ordinals")[:default]
6764
number >= 0 ? ord : IceCube::I18n.t("ice_cube.integer.negative", ordinal: ord)
6865
end
69-
7066
end
7167

7268
extend Helpers
73-
7469
end
75-
7670
end

lib/ice_cube/deprecated.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
module IceCube
22
module Deprecated
3-
43
# Define a deprecated alias for a method
54
# @param [Symbol] name - name of method to define
65
# @param [Symbol] replacement - name of method to replace (alias)
76
def deprecated_alias(name, replacement)
87
# Create a wrapped version
98
define_method(name) do |*args, &block|
10-
warn "IceCube: #{self.class}##{name} is deprecated (use #{replacement})", caller[0]
9+
warn "IceCube: #{self.class}##{name} is deprecated (use #{replacement})", caller(1..1).first
1110
send replacement, *args, &block
1211
end
1312
end
@@ -21,15 +20,15 @@ def deprecated(name, replacement)
2120
alias_method old_name, name
2221
# And replace it with a wrapped version
2322
define_method(name) do |*args, &block|
24-
warn "IceCube: #{self.class}##{name} is deprecated (use #{replacement})", caller[0]
23+
warn "IceCube: #{self.class}##{name} is deprecated (use #{replacement})", caller(1..1).first
2524
send old_name, *args, &block
2625
end
2726
end
2827

2928
def self.schedule_options(schedule, options)
3029
if options[:start_date_override]
3130
warn "IceCube: :start_date_override option is deprecated " \
32-
"(use a block: `{|s| s.start_time = override }`)", caller[0]
31+
"(use a block: `{|s| s.start_time = override }`)", caller(1..1).first
3332
schedule.start_time = options[:start_date_override]
3433
end
3534
end

lib/ice_cube/errors/count_exceeded.rb

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
module IceCube
2-
32
# An exception for when a count on a Rule is passed
43
class CountExceeded < StopIteration
54
end
6-
75
end

0 commit comments

Comments
 (0)