{"id":19009934,"url":"https://github.com/editorconfig/editorconfig-core-ruby","last_synced_at":"2025-04-22T22:51:52.188Z","repository":{"id":32060562,"uuid":"35632344","full_name":"editorconfig/editorconfig-core-ruby","owner":"editorconfig","description":"Clone of EditorConfig core written in Ruby","archived":false,"fork":false,"pushed_at":"2025-04-21T07:27:16.000Z","size":57,"stargazers_count":28,"open_issues_count":1,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-21T08:33:45.943Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/editorconfig.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-14T19:32:16.000Z","updated_at":"2025-04-21T07:27:20.000Z","dependencies_parsed_at":"2022-09-19T10:01:13.780Z","dependency_job_id":null,"html_url":"https://github.com/editorconfig/editorconfig-core-ruby","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editorconfig%2Feditorconfig-core-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editorconfig%2Feditorconfig-core-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editorconfig%2Feditorconfig-core-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editorconfig%2Feditorconfig-core-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/editorconfig","download_url":"https://codeload.github.com/editorconfig/editorconfig-core-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250337933,"owners_count":21414102,"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":[],"created_at":"2024-11-08T19:09:19.228Z","updated_at":"2025-04-22T22:51:52.181Z","avatar_url":"https://github.com/editorconfig.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EditorConfig Ruby Core\n[![Build Status](https://travis-ci.org/editorconfig/editorconfig-core-ruby.svg?branch=master)](https://travis-ci.org/editorconfig/editorconfig-core-ruby)\n\nEditorConfig Ruby Core provides the same functionality as the [EditorConfig C Core](https://github.com/editorconfig/editorconfig-core-c) and [EditorConfig Python Core](https://github.com/editorconfig/editorconfig-core-py) libraries.\n\n## EditorConfig Project\n\nEditorConfig makes it easy to maintain the correct coding style when switching between different text editors and between different projects. The EditorConfig project maintains a file format and plugins for various text editors which allow this file format to be read and used by those editors. For information on the file format and supported text editors, see the [EditorConfig website](https://editorconfig.org).\n\n## Installation\n\nWith RubyGems:\n\n``` sh\n$ gem install editorconfig\n```\n\n## Usage\n\nLoading library module.\n\n``` ruby\nrequire 'editor_config'\nEditorConfig.parse(File.read(\".editorconfig\"))\n```\n\nA command line binary is also provided.\n\n```\n$ editorconfig main.c\ncharset=utf-8\ninsert_final_newline=true\nend_of_line=lf\ntab_width=8\n```\n\n### Load\n\n**File System**\n\nAn flattened config can be loaded from the file system with:\n\n``` ruby\nfilename = \"~/Project/foo/lib/foo.rb\"\nconfig = EditorConfig.load_file(filename)\n\n# config: hash of properties and values\n{\n  \"charset\" =\u003e \"utf-8\",\n  \"indent_style\" =\u003e \"space\",\n  \"end_of_line\" =\u003e \"lf\",\n  \"insert_final_newline\" =\u003e \"true\"\n}\n```\n\nThis API walks up the directory hierarchy gathering all `.editorconfig` files until it reaches a config that defines `root = true`.\n\n**Custom Loader**\n\nA custom loader can be provided to read files from another source rather than the file system.\n\nFor an example, you might load files directly from a git repository.\n\n``` ruby\ntree_sha, filename = \"348b1ea52f897f313d62c56c2ba785a41f654861\", \"lib/foo.rb\"\n\nconfig = EditorConfig.load(filename) do |config_path|\n  if blob_sha = `git ls-tree #{tree_sha} #{config_path}`.split(\" \")[2]\n    `git cat-file blob #{blob_sha}`\n  end\nend\n```\n\n### Parse\n\nA low-level API for parsing an individual `.editorconfig` file.\n\nA `[config, root]` tuple is returned. The `root` bit is set if a top-level `root = true` is seen. The `config` value is a two dimensional hash mapping section names to property names and values.\n\n``` ruby\ndata = File.read(\".editorconfig\")\nconfig, root = EditorConfig.parse(data)\n\n# root: if top-most root = true flag is set\ntrue\n\n# config: hash of sections and properties\n{\n  \"*\" =\u003e {\n    \"end_of_line\" =\u003e \"lf\",\n    \"insert_final_newline\" =\u003e \"true\"\n  },\n  \"*.{js,py}\" =\u003e {\n    \"charset\" =\u003e \"utf-8\"\n  }\n}\n```\n\n\n## Testing\n\n[Cmake](http://www.cmake.org) is required to run the test suite. On OSX, just `brew install cmake`.\n\nThen run the tests with:\n\n``` sh\n$ rake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feditorconfig%2Feditorconfig-core-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feditorconfig%2Feditorconfig-core-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feditorconfig%2Feditorconfig-core-ruby/lists"}