-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract features from Steam which could benefit to other Locomotive gems
- Loading branch information
Showing
12 changed files
with
191 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--colour | ||
--backtrace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require_relative 'core_ext/hash' | ||
require_relative 'core_ext/string' | ||
require_relative 'core_ext/boolean/true' | ||
require_relative 'core_ext/boolean/false' | ||
require_relative 'core_ext/kernel' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class FalseClass | ||
def to_bool() self ; end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class TrueClass | ||
def to_bool() self ; end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Big thanks to Tim Ruffles (https://github.com/timruffles) | ||
# https://gist.github.com/timruffles/2780508 | ||
module HashConverter | ||
class << self | ||
|
||
def to_underscore(hash) | ||
convert(hash, :underscore) | ||
end | ||
|
||
def to_string(hash) | ||
convert(hash, :to_s) | ||
end | ||
|
||
def to_sym(hash) | ||
convert(hash, :to_sym) | ||
end | ||
|
||
# FIXME: not sure it will be ever needed | ||
# def to_camel_case hash | ||
# convert hash, :camelize, :lower | ||
# end | ||
|
||
def convert(obj, *method) | ||
case obj | ||
when Hash | ||
obj.inject({}) do |h, (k,v)| | ||
v = convert(v, *method) | ||
h[k.send(*method)] = v | ||
h | ||
end | ||
when Array | ||
obj.map { |m| convert(m, *method) } | ||
else | ||
obj | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Kernel | ||
|
||
def require_relative_all(paths, sub = nil) | ||
main_path = File.dirname(caller.first.sub(/:\d+$/, '')) | ||
main_path = File.join(main_path, sub) if sub | ||
|
||
[*paths].each do |path| | ||
Dir[File.join(main_path, path, '*.rb')].each { |file| require file } | ||
end | ||
end | ||
|
||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
unless String.public_instance_methods.include?(:to_bool) | ||
class String | ||
|
||
def to_bool | ||
return true if self == true || self =~ (/(true|t|yes|y|1)$/i) | ||
return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i) | ||
|
||
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"") | ||
end | ||
|
||
end | ||
end | ||
|
||
unless String.public_instance_methods.include?(:permalink) | ||
require 'stringex' | ||
|
||
class String | ||
|
||
def permalink(underscore = false) | ||
# if the slug includes one "_" at least, we consider that the "_" is used instead of "-". | ||
_permalink = if !self.index('_').nil? | ||
self.to_url(replace_whitespace_with: '_') | ||
else | ||
self.to_url | ||
end | ||
|
||
underscore ? _permalink.underscore : _permalink | ||
end | ||
|
||
def permalink!(underscore = false) | ||
replace(self.permalink(underscore)) | ||
end | ||
|
||
alias :parameterize! :permalink! | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'spec_helper' | ||
|
||
describe String do | ||
|
||
describe '#permalink!' do | ||
|
||
let(:string) { 'foo bar' } | ||
|
||
before { string.permalink! } | ||
|
||
it { expect(string).to eq 'foo-bar' } | ||
|
||
end | ||
|
||
describe '#to_bool' do | ||
|
||
subject { string.to_bool } | ||
|
||
describe 'true values' do | ||
|
||
%w(true t yes y 1).each do |val| | ||
let(:string) { val } | ||
it { is_expected.to eq true } | ||
end | ||
|
||
end | ||
|
||
describe 'false values' do | ||
|
||
(%w(false f no n 0) + ['']).each do |val| | ||
let(:string) { val } | ||
it { is_expected.to eq false } | ||
end | ||
|
||
end | ||
|
||
describe 'no truthy or falsy' do | ||
let(:string) { 'foo' } | ||
it { expect { subject }.to raise_error(%(invalid value for Boolean: "foo")) } | ||
end | ||
|
||
end | ||
|
||
end |