{"id":16102364,"url":"https://github.com/sshaw/transform_legacy_attribute_methods","last_synced_at":"2025-08-16T16:32:46.800Z","repository":{"id":767563,"uuid":"448869","full_name":"sshaw/transform_legacy_attribute_methods","owner":"sshaw","description":"A Rails plugin that allows you to transform your ActiveRecord model's \"legacy\" attribute methods into attribute aliases that can be used in dynamic finders and attribute hashes.  ","archived":false,"fork":false,"pushed_at":"2010-05-05T08:27:33.000Z","size":92,"stargazers_count":5,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-01T18:45:08.347Z","etag":null,"topics":["activerecord","database","legacy","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sshaw.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-12-25T10:20:58.000Z","updated_at":"2018-01-13T16:59:34.000Z","dependencies_parsed_at":"2022-08-16T10:50:17.717Z","dependency_job_id":null,"html_url":"https://github.com/sshaw/transform_legacy_attribute_methods","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Ftransform_legacy_attribute_methods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Ftransform_legacy_attribute_methods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Ftransform_legacy_attribute_methods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Ftransform_legacy_attribute_methods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sshaw","download_url":"https://codeload.github.com/sshaw/transform_legacy_attribute_methods/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229805746,"owners_count":18126902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","database","legacy","ruby"],"created_at":"2024-10-09T18:53:39.903Z","updated_at":"2024-12-17T00:42:57.736Z","avatar_url":"https://github.com/sshaw.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"========================\ntransform_legacy_attribute_methods \n========================\n\nA Rails plugin that allows you to transform your ActiveRecord model's \"legacy\" column names \ninto conventional attribute aliases and query methods that can then be used in dynamic \nfinders and attribute hashes. \n\nUsefull when you want to follow Rails' naming conventions but your database doesn't.\n\n========================\nExamples\n========================\n\t\nYour table definitions:\n\n     create table Person (\n       FirstName varchar(32),\n       LastName varchar(32),\n       Birthday date\n     )\n\n    create table bills (\n      bill_from varchar(32),\n      bill_amount decimal(2,2),\n      bill_late tinyint\n    )\n\nYour model:\n\n    class Person \u003c ActiveRecord::Base\n      set_table_name 'Person'\n      transform_legacy_attribute_methods #use default = TransformLegacyAttributeMethods.transformer\n    end\n  \n    class Bill\u003c ActiveRecord::Base\n      transform_legacy_attribute_methods(:skip =\u003e 'bill_late')  { |name| name.sub /^bill_/, '' } \n    end\n   \nYour code:\n\n     person = Person.new( :first_name =\u003e 'Mac', :last_name =\u003e 'Dre' )\n     bill = person.bills.build( :from =\u003e 'Coco County', :amount =\u003e 35_000.45 ) \n\n     person = Person.find_by_first_name_and_last_name('Viviane',  'Castro')\n\n     bill=Bill.new\n     bill.attributes = {\n       :from =\u003e 'Whole Foods',\n       :amount =\u003e 300,\n       :bill_late =\u003e true       \n     }\n\n     s = bill.amount_before_type_cast\n     bill.pay! if bill.amount?\n\n========================\nUsage\n========================\n\nclass YourModel \u003c ActiveRecord::Base\n  transform_legacy_attribute_methods(*args, \u0026block)\nend\n\ntransform_legacy_attribute_methods requires a transformer to convert your column names. \nA transformer is either a method of the String class -given via a Symbol or String, or a Proc. \n\nTransformation gives you the following accessors: \n\n- column= \n- column\n- column?\n- column_before_type_cast\n\nYou can also use column in in dynamic finders and attribute hashes.\n\nA transformer can be specified as the 1st argument or via a block:\n\ntransform_legacy_attribute_methods( :titleize ) \ntransform_legacy_attribute_methods { |column_name| column_name.underscore }\ntransform_legacy_attribute_methods( 'downcase' )\ntransform_legacy_attribute_methods( lambda { |column_name| column_name.chop } )\n\nIf no transformer is provided TransformLegacyAttributeMethods.transformer will be used.\nBy default, this is set to :underscore.\n\nAll other arguments are options. Currently the only option is :skip, which specifies \ncolumn(s) that should not be transformed. :skip can be a String, Symbol, or an Array:\n\ntransform_legacy_attribute_methods( :skip =\u003e %w|columnA columnB columnC| )\ntransform_legacy_attribute_methods( :titleize, :skip =\u003e :some_column )","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshaw%2Ftransform_legacy_attribute_methods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsshaw%2Ftransform_legacy_attribute_methods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshaw%2Ftransform_legacy_attribute_methods/lists"}