Skip to content

Commit 562e266

Browse files
committed
remove active_support, setup rust
1 parent 2f4e734 commit 562e266

File tree

6 files changed

+117
-6
lines changed

6 files changed

+117
-6
lines changed

Cargo.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "turbo_blank"
3+
version = "0.1.0"
4+
authors = ["Godfrey Chan <[email protected]>"]
5+
6+
[lib]
7+
8+
crate-type = ["staticlib"]
9+
10+
[dependencies]
11+
Inflector = "0.3.1"
12+
13+
libc = "*"
14+
15+
[dependencies.libcruby-sys]
16+
17+
path = "../../crates/libcruby-sys"
18+
19+
[dependencies.helix]
20+
21+
path = "../.."
22+
23+
[profile.release]
24+
25+
lto = true

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ source 'https://rubygems.org'
33

44
# Specify your gem's dependencies in authorizable.gemspec
55
gemspec
6+
7+
gem 'helix_runtime', path: '../../ruby'

Rakefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# frozen_string_literal: true
22
require 'bundler/gem_tasks'
3+
require 'rake/clean'
4+
require 'rake/testtask'
5+
require 'bundler/setup'
36

47
# rubocop config copied from AMS
58
begin
@@ -47,3 +50,33 @@ task default: [:test, :rubocop]
4750

4851
desc 'CI test task'
4952
task ci: [:default]
53+
54+
directory 'target'
55+
directory 'lib/turbo_blank'
56+
57+
task :cargo_build do
58+
sh 'cargo build --release'
59+
end
60+
CLEAN.include('target')
61+
62+
file 'lib/case_transform/native.bundle' => ['lib/case_transform', :cargo_build] do
63+
sh 'gcc -Wl,-force_load,target/release/libcase_transform.a --shared -Wl,-undefined,dynamic_lookup -o lib/case_transform/native.bundle'
64+
end
65+
CLOBBER.include('lib/case_transform/native.bundle')
66+
67+
task irb: 'lib/case_transform/native.bundle' do
68+
exec 'irb -Ilib -rcase_transform'
69+
end
70+
71+
task benchmark: 'lib/case_transform/native.bundle' do
72+
exec 'ruby -Ilib benchmark.rb'
73+
end
74+
75+
# Rake::TestTask.new(:test) do |t|
76+
# t.libs << "test"
77+
# t.libs << "lib"
78+
# t.test_files = FileList['test/**/*_test.rb']
79+
# end
80+
#
81+
# task :test => "lib/case_transform/native.bundle"
82+
# task :default => :test

case_transform.gemspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ Gem::Specification.new do |s|
2525

2626
s.required_ruby_version = '>= 2.0'
2727

28-
s.add_runtime_dependency 'activesupport'
29-
3028
s.add_development_dependency 'rake'
3129

30+
# Rust
31+
s.add_runtime_dependency 'helix_runtime'
32+
3233
# Quality Control
3334
s.add_development_dependency 'rubocop'
3435
s.add_development_dependency 'codeclimate-test-reporter'

lib/case_transform.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
require 'case_transform/version'
66

7+
require 'helix_runtime'
8+
9+
RubyString = String
10+
require 'case_transform/native'
11+
712
module CaseTransform
813
module_function
914

@@ -16,7 +21,7 @@ def camel(value)
1621
when Array then value.map { |item| camel(item) }
1722
when Hash then value.deep_transform_keys! { |key| camel(key) }
1823
when Symbol then camel(value.to_s).to_sym
19-
when String then value.underscore.camelize
24+
when String then value.to_snake_case.to_class_case
2025
else value
2126
end
2227
end
@@ -30,7 +35,7 @@ def camel_lower(value)
3035
when Array then value.map { |item| camel_lower(item) }
3136
when Hash then value.deep_transform_keys! { |key| camel_lower(key) }
3237
when Symbol then camel_lower(value.to_s).to_sym
33-
when String then value.underscore.camelize(:lower)
38+
when String then value.to_snake_case.to_camel_case
3439
else value
3540
end
3641
end
@@ -45,7 +50,7 @@ def dash(value)
4550
when Array then value.map { |item| dash(item) }
4651
when Hash then value.deep_transform_keys! { |key| dash(key) }
4752
when Symbol then dash(value.to_s).to_sym
48-
when String then value.underscore.dasherize
53+
when String then value.to_snake_case.to_kebab_case
4954
else value
5055
end
5156
end
@@ -60,7 +65,7 @@ def underscore(value)
6065
when Array then value.map { |item| underscore(item) }
6166
when Hash then value.deep_transform_keys! { |key| underscore(key) }
6267
when Symbol then underscore(value.to_s).to_sym
63-
when String then value.underscore
68+
when String then value.to_snake_case
6469
else value
6570
end
6671
end

src/lib.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#[macro_use]
2+
extern crate helix;
3+
extern crate inflector;
4+
5+
// dash: kebab-case
6+
use inflector::cases::kebabcase::to_kebab_case;
7+
// underscore: snake_case
8+
use inflector::cases::snakecase::to_snake_case;
9+
// camel_lower: camelCase
10+
use inflector::cases::camelcase::to_camel_case;
11+
// camel: ClassCase (PascalCase)
12+
use inflector::cases::classcase::to_class_case;
13+
14+
// let camel_case_string: String = "some_string".to_string().to_camel_case();
15+
16+
declare_types! {
17+
reopen class RubyString {
18+
def to_snake_case(self) -> String {
19+
to_snake_case(self.to_string());
20+
}
21+
22+
def to_camel_case(self) -> String {
23+
to_camel_case(self.to_string());
24+
}
25+
26+
def to_class_case(self) -> String {
27+
to_class_case(self.to_string());
28+
}
29+
30+
def to_kebab_case(self) -> String {
31+
to_kebab_case(self.to_string());
32+
}
33+
}
34+
}
35+
36+
// Delete me:
37+
38+
// use helix::{UncheckedValue, ToRust};
39+
//
40+
// impl ToString for RubyString {
41+
// fn to_string(&self) -> String {
42+
// let checked = self.0.to_checked().unwrap();
43+
// checked.to_rust()
44+
// }
45+
// }

0 commit comments

Comments
 (0)