Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:

- restore_cache:
keys:
- has_normalized_attributes-dependencies-v1-{{ checksum "has_normalized_attributes.gemspec" }}
- has_normalized_attributes-dependencies-v1-
- has_normalized_attributes-dependencies-v1-{{ checksum "has_normalized_attributes.gemspec" }}
- has_normalized_attributes-dependencies-v1-

- run:
name: Install dependencies
Expand Down Expand Up @@ -65,8 +65,8 @@ jobs:

- restore_cache:
keys:
- has_normalized_attributes-dependencies-v1-{{ checksum "has_normalized_attributes.gemspec" }}
- has_normalized_attributes-dependencies-v1-
- has_normalized_attributes-dependencies-v1-{{ checksum "has_normalized_attributes.gemspec" }}
- has_normalized_attributes-dependencies-v1-

- run:
name: Install dependencies
Expand Down
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
inherit_from:
- https://onehq.com/rubocop3_4.yml
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.4.4
8 changes: 4 additions & 4 deletions .tekton/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version: 0.1.0


dependencies:
- name: ruby-pipelines
alias: delivery
version: "0.2.0-dev.3"
repository: "oci://public.ecr.aws/c7o8r4o5"
- name: ruby-pipelines
alias: delivery
version: "0.2.0-dev.3"
repository: "oci://public.ecr.aws/c7o8r4o5"
16 changes: 8 additions & 8 deletions .tekton/values-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ publish: true
delivery:
rbac:
rolebindings:
- role: edit
subjects:
- kind: Group
name: hq-platform
- role: edit
subjects:
- kind: Group
name: hq-platform

- role: view
subjects:
- kind: Group
name: hq-product
- role: view
subjects:
- kind: Group
name: hq-product
8 changes: 4 additions & 4 deletions .tekton/values-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ publish: false
delivery:
rbac:
rolebindings:
- role: edit
subjects:
- kind: Group
name: hq-product
- role: edit
subjects:
- kind: Group
name: hq-product

4 changes: 2 additions & 2 deletions .tekton/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ git:
# sha:

global:
taskAnnotations:
taskAnnotations:
vault.security.banzaicloud.io/vault-addr: "https://vault.internal.onehq.com"
vault.security.banzaicloud.io/vault-path: "jwt"
vault.security.banzaicloud.io/vault-auth-method: "jwt"
vault.security.banzaicloud.io/vault-tls-secret: "custom-trusted-ca"
vault.security.banzaicloud.io/vault-tls-secret: "custom-trusted-ca"
gem: *gem
rubyVersion: 3.0.2
mountGemDockerfile: true
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# HAS_NORMALIZED_ATTRIBUTES

# Changelog

All notable changes to this project are documented in this file

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Guiding Principles

- Changelogs are for humans, not machines.
- There should be an entry for every single version.
- The same types of changes should be grouped.
- Versions and sections should be linkable.
- The latest version comes first.
- The release date of each version is displayed.
- Mention whether you follow Semantic Versioning.

### Types of changes

- **Added** for new features.
- **Changed** for changes in existing functionality.
- **Deprecated** for soon-to-be removed features.
- **Removed** for now removed features.
- **Fixed** for any bug fixes.
- **Security** in case of vulnerabilities.

## [5.0.0] 2025-12-01

### Added
- Main changelog file created

### Changed
- Ruby version upgrade from 3.0.0 to 3.4.4
- In the gemspec file, allow to be used for Rails versions between 6.1 and 8.1.1.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

# Specify your gem's dependencies in send_grid.gemspec
Expand Down
9 changes: 6 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require 'bundler'
require 'rspec/core/rake_task'
# frozen_string_literal: true

require "bundler"
require "rspec/core/rake_task"

Bundler::GemHelper.install_tasks
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
task default: :spec
60 changes: 35 additions & 25 deletions has_normalized_attributes.gemspec
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true

lib = File.expand_path("../lib/", __FILE__)
$:.unshift lib unless $:.include?(lib)

require "has_normalized_attributes/version"

Gem::Specification.new do |s|
s.name = %q{has_normalized_attributes}
s.version = HasNormalizedAttributes::VERSION

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Kyle Ginavan"]
s.date = %q{2010-05-18}
s.description = %q{has_normalized_attributes is a Ruby on Rails gem that lets you normalize user data for an improved user experience.
It takes the messy user inputed data and normalizes it into a nice clean standard format.}
s.email = %q{kylejginavan@gmail.com}
s.extra_rdoc_files = [
"README.rdoc"
]
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.name = "has_normalized_attributes"
s.version = HasNormalizedAttributes::VERSION
s.authors = ["Kyle Ginavan"]
s.email = ["kylejginavan@gmail.com"]
s.date = "2010-05-18"
s.summary = "Normalize user-provided data before save"
s.description = <<~DESC
has_normalized_attributes is a Ruby on Rails gem that lets you normalize user data
for an improved user experience. It takes messy user input and normalizes it into
a clean, standard format.
DESC
s.homepage = "https://github.com/kylejginavan/has_normalized_attributes"
s.require_paths = ["lib"]
s.rubygems_version = %q{1.5.2}
s.summary = %q{Ruby on Rails gem for normalize data prior to save}
# s.rubyforge_project = "has_normalized_attributes"

s.add_development_dependency "activerecord", ">= 3.1.0"
s.add_development_dependency "byebug"
s.add_development_dependency "database_cleaner"
s.add_development_dependency "rspec_junit_formatter", "~> 0.3", ">= 0.3.0"
s.add_development_dependency "rspec"
s.add_development_dependency "sqlite3"
s.required_ruby_version = ">= 3.4"
s.files = Dir.chdir(__dir__) do
`git ls-files -z`.split("\x0").reject do |f|
f.match?(%r{\A(?:test|spec|features)/}) ||
f.end_with?(".gem")
end
end
s.require_paths = ["lib"]
s.extra_rdoc_files = [ "README.rdoc" ]
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }


s.add_development_dependency "activerecord", "~> 7.2"
s.add_development_dependency "byebug", "~> 12.0"
s.add_development_dependency "database_cleaner", "~> 2.1"
s.add_development_dependency "rspec", "~> 3.13"
s.add_development_dependency "rspec_junit_formatter", "~> 0.6"
s.add_dependency "rubocop", "~> 1.81" # code quality check for sonarqube
s.add_dependency "rubocop-performance", "~> 1.26"
s.add_dependency "rubocop-rails", "~> 2.34"
s.add_development_dependency "sqlite3", "~> 2.9"
end
40 changes: 20 additions & 20 deletions lib/has_normalized_attributes.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# frozen_string_literal: true

module HasNormalizedAttributes
#CONSTANTS - Do not mix these into ActiveRecord!!!
ZIPCODE = /[-.\s)(,]/
PHONE = /[-.\s)(,]|^(0)|^(\+1)/
SSN = /[-.\s)(,]/
TAXID = /[-.\s)(,]/
DOLLAR = /[$,\s]/
NUMBER = /[,\s]/
PERCENT = /[%,\s]/
SPACES = /\s/
# CONSTANTS - Do not mix these into ActiveRecord!!!
ZIPCODE = /[-.\s)(,]/
PHONE = /[-.\s)(,]|^(0)|^(\+1)/
SSN = /[-.\s)(,]/
TAXID = /[-.\s)(,]/
DOLLAR = /[$,\s]/
NUMBER = /[,\s]/
PERCENT = /[%,\s]/
SPACES = /\s/

module CoreExtensions
extend ActiveSupport::Concern

# Prepending a dynamically defined module to add functionality to the current normalize_ methods.
# This is similar to alias_method_chain, but accomplished in a cleaner way using inheritance.
prepend Module.new {
prepend(Module.new do
def self.normalizations(*args)
args.each do |arg|
# Convert outer parentheses into a negative (-) sign on the result of the super method.
Expand All @@ -28,23 +30,23 @@ def self.normalizations(*args)
end

normalizations :number, :dollar
}
end)

#instance methods
# instance methods
def self.normalizations(*args)
args.each do |arg|
define_method "normalize_#{arg}" do
if arg == :strip
self && self.respond_to?(:strip) ? self.strip : self
else
reg_exp = HasNormalizedAttributes.const_get(arg.upcase)
self && is_a?(String) && match(reg_exp) ? gsub(reg_exp,'') : self
self && is_a?(String) && match(reg_exp) ? gsub(reg_exp, "") : self
end
end
end
end

#loading all methods dynamically
# loading all methods dynamically
normalizations :phone, :zipcode, :ssn, :taxid, :dollar, :number, :percent, :spaces, :strip
end

Expand All @@ -53,13 +55,12 @@ module ActiveRecord

module ClassMethods
def has_normalized_attributes(args = {})

if args.blank? || !args.is_a?(Hash)
raise ArgumentError, 'Must define the fields you want to be normalize with has_normalized_attributes :field_one => "phone", :field_two => "zipcode"'
end

args.each do |field, normalization_type|
define_method "#{field.to_s}=" do |value|
define_method "#{field}=" do |value|
if value.present?
normalized_value = value.send("normalize_#{normalization_type.downcase}".to_sym)
else
Expand All @@ -68,15 +69,14 @@ def has_normalized_attributes(args = {})
super normalized_value
end
end

end
end
end
end

#extend these classes - Numeric is a parent class for all of Ruby's numeric types.
# extend these classes - Numeric is a parent class for all of Ruby's numeric types.
[String, Numeric, NilClass].each do |klass|
klass.send(:include, HasNormalizedAttributes::CoreExtensions)
end
#include activerecord
ActiveRecord::Base.send :include, HasNormalizedAttributes::ActiveRecord
# include activerecord
ActiveRecord::Base.include HasNormalizedAttributes::ActiveRecord
6 changes: 4 additions & 2 deletions lib/has_normalized_attributes/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module HasNormalizedAttributes
VERSION = "1.0.2"
end
VERSION = "5.0.0-beta.2"
end
Loading