Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
Replacing all ^ and $ in regexes with \A and \z for Rails4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtPreston committed Apr 10, 2014
1 parent 6b95ec3 commit 4ecab6e
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/ib/base_properties.rb
Expand Up @@ -20,7 +20,7 @@ def to_human
# Comparison support
def content_attributes
HashWithIndifferentAccess[attributes.reject do |(attr, _)|
attr.to_s =~ /(_count)$/ ||
attr.to_s =~ /(_count)\z/ ||
[:created_at, :updated_at, :type,
:id, :order_id, :contract_id].include?(attr.to_sym)
end]
Expand Down
12 changes: 6 additions & 6 deletions lib/ib/constants.rb
Expand Up @@ -294,18 +294,18 @@ module IB
PROPS = {:side =>
{:set => proc { |val| # BUY(BOT)/SELL(SLD)/SSHORT/SSHORTX
self[:side] = case val.to_s.upcase
when /SHORT.*X|^X$/
when /SHORT.*X|^X\z/
'X'
when /SHORT|^T$/
when /SHORT|^T\z/
'T'
when /^B/
when /\AB/
'B'
when /^S/
when /\AS/
'S'
end },
:validate =>
{:format =>
{:with => /^buy$|^sell$|^short$|^short_exempt$/,
{:with => /\Abuy$|^sell$|^short$|^short_exempt\z/,
:message => "should be buy/sell/short"}
}
},
Expand All @@ -325,7 +325,7 @@ module IB
},
:validate =>
{:format =>
{:with => /^same$|^open$|^close$|^unknown$/,
{:with => /\Asame$|^open$|^close$|^unknown\z/,
:message => "should be same/open/close/unknown"}
},
}
Expand Down
6 changes: 3 additions & 3 deletions lib/models/ib/bag.rb
Expand Up @@ -11,9 +11,9 @@ class Bag < Contract
# The exception is for a STK legs, which must specify the SMART exchange.
# 2. :symbol => "USD" For combo Contract, this is an arbitrary value (like "USD")

validates_format_of :sec_type, :with => /^bag$/, :message => "should be a bag"
validates_format_of :right, :with => /^none$/, :message => "should be none"
validates_format_of :expiry, :with => /^$/, :message => "should be blank"
validates_format_of :sec_type, :with => /\Abag\z/, :message => "should be a bag"
validates_format_of :right, :with => /\Anone\z/, :message => "should be none"
validates_format_of :expiry, :with => /\A\z/, :message => "should be blank"

def default_attributes
super.merge :sec_type => :bag #,:legs => Array.new,
Expand Down
2 changes: 1 addition & 1 deletion lib/models/ib/combo_leg.rb
Expand Up @@ -36,7 +36,7 @@ class ComboLeg < IB::Model

# Extra validations
validates_numericality_of :ratio, :con_id
validates_format_of :designated_location, :with => /^$/,
validates_format_of :designated_location, :with => /\A\z/,
:message => "should be blank or orders will be rejected"

def default_attributes
Expand Down
6 changes: 3 additions & 3 deletions lib/models/ib/contract.rb
Expand Up @@ -58,7 +58,7 @@ class Contract < IB::Model
val
end
},
:validate => {:format => {:with => /^put$|^call$|^none$/,
:validate => {:format => {:with => /\Aput$|^call$|^none\z/,
:message => "should be put, call or none"}}
}

Expand Down Expand Up @@ -95,13 +95,13 @@ class Contract < IB::Model
validates_inclusion_of :sec_type, :in => CODES[:sec_type].keys,
:message => "should be valid security type"

validates_format_of :expiry, :with => /^\d{6}$|^\d{8}$|^$/,
validates_format_of :expiry, :with => /\A\d{6}$|^\d{8}$|\A\z/,
:message => "should be YYYYMM or YYYYMMDD"

validates_format_of :primary_exchange, :without => /SMART/,
:message => "should not be SMART"

validates_format_of :sec_id_type, :with => /ISIN|SEDOL|CUSIP|RIC|^$/,
validates_format_of :sec_id_type, :with => /ISIN|SEDOL|CUSIP|RIC|\A\z/,
:message => "should be valid security identifier"

validates_numericality_of :multiplier, :strike, :allow_nil => true
Expand Down
2 changes: 1 addition & 1 deletion lib/models/ib/contract_detail.rb
Expand Up @@ -65,7 +65,7 @@ class ContractDetail < IB::Model
:next_option_partial => :bool # # only if bond has embedded options.

# Extra validations
validates_format_of :time_zone, :with => /^\w{3}$/, :message => 'should be XXX'
validates_format_of :time_zone, :with => /\A\w{3}\z/, :message => 'should be XXX'

serialize :sec_id_list, HashWithIndifferentAccess

Expand Down
6 changes: 3 additions & 3 deletions lib/models/ib/option.rb
Expand Up @@ -4,11 +4,11 @@ module IB
class Option < Contract

validates_numericality_of :strike, :greater_than => 0
validates_format_of :sec_type, :with => /^option$/,
validates_format_of :sec_type, :with => /\Aoption\z/,
:message => "should be an option"
validates_format_of :local_symbol, :with => /^\w+\s*\d{6}[pcPC]\d{8}$|^$/,
validates_format_of :local_symbol, :with => /\A\w+\s*\d{6}[pcPC]\d{8}$|\A\z/,
:message => "invalid OSI code"
validates_format_of :right, :with => /^put$|^call$/,
validates_format_of :right, :with => /\Aput$|^call\z/,
:message => "should be put or call"

# For Options, this is contract's OSI (Option Symbology Initiative) name/code
Expand Down
2 changes: 1 addition & 1 deletion lib/models/ib/order_state.rb
Expand Up @@ -57,7 +57,7 @@ class OrderState < IB::Model
# (simulated orders) or an exchange (native orders) but that currently
# the order is inactive due to system, exchange or other issues.

validates_format_of :status, :without => /^$/, :message => 'must not be empty'
validates_format_of :status, :without => /\A\z/, :message => 'must not be empty'
validates_numericality_of :price, :average_price, :allow_nil => true
validates_numericality_of :local_id, :perm_id, :client_id, :parent_id, :filled,
:remaining, :only_integer => true, :allow_nil => true
Expand Down
2 changes: 1 addition & 1 deletion misc/ib_ticker/ohlc.rb
Expand Up @@ -153,7 +153,7 @@ def printCSV(*values, &b)
else
a= self.to_s(*values, &b)
end
a +self[ :volume ].to_s+$/
a +self[ :volume ].to_s+\z/
end


Expand Down
4 changes: 2 additions & 2 deletions rails_spec/dummy/config/initializers/inflections.rb
Expand Up @@ -3,8 +3,8 @@
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.plural /\A(ox)\z/i, '\1en'
# inflect.singular /\A(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
Expand Down

0 comments on commit 4ecab6e

Please sign in to comment.