Skip to content

Commit adaa598

Browse files
committed
Docs and metadata
1 parent 877acb9 commit adaa598

9 files changed

Lines changed: 57 additions & 38 deletions

File tree

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ representative at an online or offline event.
6060

6161
Instances of abusive, harassing, or otherwise unacceptable behavior may be
6262
reported to the community leaders responsible for enforcement at
63-
[INSERT CONTACT METHOD].
63+
bonjour@codeureusesenliberte.fr.
6464
All complaints will be reviewed and investigated promptly and fairly.
6565

6666
All community leaders are obligated to respect the privacy and security of the

README.md

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
# SiretFormatValidator
1+
_TODO: add badges_
22

3-
TODO: Delete this and the text below, and describe your gem
3+
# siret_validator
44

5-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/siret_validator`. To experiment with that code, run `bin/console` for an interactive prompt.
5+
This gem provides a Rails validator for french [SIRET numbers](https://entreprendre.service-public.fr/vosdroits/F32135?lang=en).
66

7-
## Installation
7+
## Features
8+
9+
* Validate the SIRET format (14 digits),
10+
* Validate the checksum of regular SIRETs (with luhn sum),
11+
* Validate the checksum of La Poste SIRETs (with the alternative checksum formula),
12+
* Clear localized error messages,
13+
* Ad-hoc error messages support.
814

9-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
15+
## Installation
1016

1117
Install the gem and add to the application's Gemfile by executing:
1218

@@ -20,19 +26,49 @@ If bundler is not being used to manage dependencies, install the gem by executin
2026
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
2127
```
2228

29+
Alternatively, you can vendor the gem by just copy-pasting the `lib/siret_validator.rb` file into your `app/validators` directory.
30+
2331
## Usage
2432

25-
TODO: Write usage instructions here
33+
### With ActiveRecord
34+
35+
```ruby
36+
class TaxesFilling < ApplicationRecord
37+
validates :company_siret, siret: true
38+
end
39+
```
40+
41+
### With ActiveModel
42+
43+
```ruby
44+
class TaxesFilling
45+
include ActiveModel::Validations
46+
47+
attr_accessor :company_siret
48+
validates :company_siret, siret: true
49+
end
50+
```
51+
52+
## I18n
53+
54+
By default, the siret validator may emit two different error messages:
55+
56+
* `:wrong_siret_format` – when the value is not an 14-digits string.
57+
58+
_The message is localized using a custom `:wrong_siret_format` i18n key. French and English locales are bundled with the gem._
59+
* `:invalid` – when the SIRET checksum is invalid.
60+
61+
_The message is localized using the standard Rails `:invalid` i18n key._
2662

2763
## Development
2864

29-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
65+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
3066

31-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `siret_validator.gemspec`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
3268

3369
## Contributing
3470

35-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/siret_validator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/siret_validator/blob/main/CODE_OF_CONDUCT.md).
71+
Bug reports and pull requests are welcome on GitHub at https://github.com/CodeursenLiberte/siret_validator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/CodeursenLiberte/siret_validator/blob/main/CODE_OF_CONDUCT.md).
3672

3773
## License
3874

README_fr.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_TODO_

bin/console

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/locale/en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
en:
22
errors:
33
messages:
4-
wrong_siret_format: must be a number of exactly 14 digits
4+
wrong_siret_format: is the wrong length (should be 14 digits)

lib/locale/fr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fr:
22
errors:
33
messages:
4-
wrong_siret_format: doit être un numéro d’exactement 14 chiffres
4+
wrong_siret_format: ne fait pas la bonne longueur (doit comporter 14 chiffres)

sig/siret_validator.rbs

Lines changed: 0 additions & 4 deletions
This file was deleted.

siret_validator.gemspec

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22

33
Gem::Specification.new do |spec|
44
spec.name = "siret_validator"
5-
spec.version = "0.1"
5+
spec.version = "0.1.0"
66
spec.authors = ["Pierre de La Morinerie"]
7-
spec.email = ["kemenaran@gmail.com"]
7+
spec.email = ["pierre@codeureusesenliberte.fr"]
88

9-
spec.summary = "TODO: Write a short summary, because RubyGems requires one."
10-
spec.description = "TODO: Write a longer description or delete this line."
11-
spec.homepage = "TODO: Put your gem's website or public repo URL here."
9+
spec.summary = "A Rails validator for french SIRET numbers"
10+
spec.homepage = "https://github.com/CodeursenLiberte/siret_validator"
1211
spec.license = "MIT"
1312
spec.required_ruby_version = ">= 3.1.0"
1413

15-
spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
16-
1714
spec.metadata["homepage_uri"] = spec.homepage
18-
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
19-
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
15+
spec.metadata["source_code_uri"] = "https://github.com/CodeursenLiberte/siret_validator"
16+
spec.metadata["changelog_uri"] = "https://github.com/CodeursenLiberte/siret_validator/blob/main/CHANGELOG.md"
2017

2118
# Specify which files should be added to the gem when it is released.
2219
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.

test/test_siret_validator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ def test_validate_siret_localized_message
7070
c = Company.new(siret: "foo")
7171

7272
with_locale(:en) do
73-
assert_equal c.tap(&:validate).errors[:siret], ["must be a number of exactly 14 digits"]
73+
assert_equal c.tap(&:validate).errors[:siret], ["is the wrong length (should be 14 digits)"]
7474
end
7575

7676
with_locale(:fr) do
77-
assert_equal c.tap(&:validate).errors[:siret], ["doit être un numéro d’exactement 14 chiffres"]
77+
assert_equal c.tap(&:validate).errors[:siret], ["ne fait pas la bonne longueur (doit comporter 14 chiffres)"]
7878
end
7979
end
8080

0 commit comments

Comments
 (0)