diff --git a/lib/bulldoze_renamer/string_inflector.rb b/lib/bulldoze_renamer/string_inflector.rb index 55ea9c0..6b647fa 100644 --- a/lib/bulldoze_renamer/string_inflector.rb +++ b/lib/bulldoze_renamer/string_inflector.rb @@ -8,11 +8,11 @@ class StringDoesNotInflectToItselfError < ArgumentError; end extend Forwardable def self.active_support_inflections - [:underscore, :camelize] + [:underscore] end def self.inflections - active_support_inflections + [:dasherize, :upcase, :js_camelize] + active_support_inflections + [:camelize, :dasherize, :upcase, :js_camelize] end def_delegators ActiveSupport::Inflector, *StringInflector.active_support_inflections @@ -26,7 +26,13 @@ def upcase(w) underscore(w).upcase end + def camelize(w) + # Wrapping AR camelize because it would return 'dr-who' as 'Dr-who', we want 'DrWho' + ActiveSupport::Inflector.camelize(underscore(w)) + end + def dasherize(w) + # Wrapping AR dasherize because it would return 'DrWho' as 'DrWho', we want 'dr-who' ActiveSupport::Inflector.dasherize(underscore(w)) end diff --git a/spec/bulldoze_renamer/string_inflector_spec.rb b/spec/bulldoze_renamer/string_inflector_spec.rb index f8bca72..0b74470 100644 --- a/spec/bulldoze_renamer/string_inflector_spec.rb +++ b/spec/bulldoze_renamer/string_inflector_spec.rb @@ -15,6 +15,21 @@ expect(BulldozeRenamer::StringInflector.new('dr_who', 'roger_rabbit').mappings).to eq(expected_mappings) end + it "has all mappings for dasherized strings" do + expected_mappings = { + current_inflection: :dasherize, + target_inflection: :dasherize, + inflections: { + underscore: { current: "dr_who", target: "roger_rabbit" }, + camelize: { current: "DrWho", target: "RogerRabbit" }, + dasherize: { current: "dr-who", target: "roger-rabbit" }, + upcase: { current: "DR_WHO", target: "ROGER_RABBIT" }, + js_camelize: {current: "drWho", target: "rogerRabbit"} + } + } + expect(BulldozeRenamer::StringInflector.new('dr-who', 'roger-rabbit').mappings).to eq(expected_mappings) + end + it "omits duplicate mappings for simple strings" do expected_mappings = { current_inflection: :camelize,