-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
99 additions
and
74 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
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
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,50 @@ | ||
# frozen_string_literal: true | ||
|
||
module Ioki | ||
# These are methods which are adapted from ActiveSupport | ||
module Support | ||
# activesupport/lib/active_support/core_ext/string/inflections.rb | ||
# But it doesn't support uppercase_first_letter argument and inflections | ||
def camelize(term) | ||
string = term.to_s.sub(/^[a-z\d]*/) { |match| match.capitalize! || match } | ||
string.gsub!(%r{(?:_|(/))([a-z\d]*)}i) do | ||
word = Regexp.last_match(2) | ||
substituted = word.capitalize! || word | ||
Regexp.last_match(1) ? "::#{substituted}" : substituted | ||
end | ||
string | ||
end | ||
|
||
# activesupport/lib/active_support/core_ext/object/blank.rb | ||
def blank?(value) | ||
value.respond_to?(:empty?) ? !!value.empty? : !value | ||
end | ||
|
||
module_function :camelize, :blank? | ||
|
||
module ModuleMixins | ||
# activesupport/lib/active_support/core_ext/module/introspection.rb | ||
def module_parent_name | ||
if defined?(@parent_name) | ||
@parent_name | ||
else | ||
parent_name = name =~ /::[^:]+\z/ ? -Regexp.last_match.pre_match : nil | ||
@parent_name = parent_name unless frozen? | ||
parent_name | ||
end | ||
end | ||
|
||
# activesupport/lib/active_support/core_ext/module/introspection.rb | ||
def module_parent | ||
module_parent_name ? Object.const_get(module_parent_name) : Object | ||
end | ||
|
||
# activesupport/lib/active_support/core_ext/class/subclasses.rb | ||
def descendants | ||
ObjectSpace.each_object(singleton_class).reject do |k| | ||
k.singleton_class? || k == self | ||
end | ||
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
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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Ioki::Support do | ||
describe 'camelize' do | ||
it 'works for lowercase strings' do | ||
expect(described_class.camelize('task')).to eq('Task') | ||
end | ||
|
||
it 'works for underscored strings' do | ||
expect(described_class.camelize('task_list')).to eq('TaskList') | ||
end | ||
|
||
it 'works for multiple underscored strings' do | ||
expect(described_class.camelize('driver_vehicle_connection')).to eq('DriverVehicleConnection') | ||
end | ||
|
||
it 'works for empty strings' do | ||
expect(described_class.camelize('')).to eq('') | ||
end | ||
|
||
it 'works for nil' do | ||
expect(described_class.camelize(nil)).to eq('') | ||
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