{"id":15406763,"url":"https://github.com/dannyben/configly","last_synced_at":"2025-03-01T12:33:08.408Z","repository":{"id":62556133,"uuid":"215009652","full_name":"DannyBen/configly","owner":"DannyBen","description":"Lightweight Hash object with dot notation access for multi-YAML configuration","archived":false,"fork":false,"pushed_at":"2023-07-30T09:28:01.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-06T05:19:34.070Z","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/DannyBen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-14T10:04:45.000Z","updated_at":"2023-05-12T17:54:39.000Z","dependencies_parsed_at":"2023-01-23T03:25:13.028Z","dependency_job_id":null,"html_url":"https://github.com/DannyBen/configly","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/DannyBen%2Fconfigly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fconfigly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fconfigly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fconfigly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DannyBen","download_url":"https://codeload.github.com/DannyBen/configly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":220053582,"owners_count":16588691,"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-10-01T16:25:16.026Z","updated_at":"2024-10-17T12:22:41.986Z","avatar_url":"https://github.com/DannyBen.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Configly - Minimal Settings Library\n==================================================\n\n[![Gem Version](https://badge.fury.io/rb/configly.svg)](https://badge.fury.io/rb/configly)\n[![Build Status](https://github.com/DannyBen/configly/workflows/Test/badge.svg)](https://github.com/DannyBen/configly/actions?query=workflow%3ATest)\n[![Maintainability](https://api.codeclimate.com/v1/badges/a8c4977315f307979f30/maintainability)](https://codeclimate.com/github/DannyBen/configly/maintainability)\n\nConfigly is a lightweight ruby Hash object with dot notation access.\n\nIt is designed for loading and using YAML configuration files.\n\n---\n\nInstallation\n--------------------------------------------------\n\n    $ gem install configly\n\n\nUsage\n--------------------------------------------------\n\n### Initialization\n\nInitialize a Configly object from Hash:\n\n```ruby\n# Initialize from hash\nrequire 'configly'\nhash = {server: {host: 'localhost', port: 3000}}\nconfigly = hash.to_configly\n```\n\nor by loading one or more YAML files:\n\n```ruby\n# Initialize by merging in YAML files\nconfig = Configly.new\nconfig \u003c\u003c 'spec/fixtures/settings.yml'\nputs config.imported.settings.also\n#=\u003e work\n```\n\nYou can append additional YAML files by using either `#\u003c\u003c` or `#load`. \nThe '.yml' extension is optional.\n\nIn addition, you may load YAML files to nested keys:\n\n```ruby\n# Loading nested YAMLs\nconfig = Configly.new\nconfig \u003c\u003c 'spec/fixtures/settings'\n\np config.imported.settings\n#=\u003e {:also=\u003e\"work\"}\n\nconfig.nested.settings.load 'spec/fixtures/settings'\n\np config.nested.settings\n#=\u003e {:imported=\u003e{:settings=\u003e{:also=\u003e\"work\"}}}\n```\n\nConfigly objects inherit from Hash:\n\n```ruby\nputs configly.is_a? Configly  #=\u003e true\nputs configly.is_a? Hash      #=\u003e true\n```\n\n### Dot notation read access\n\nRead values using dot notation:\n\n```ruby\n# Dot notation access\nputs configly.server.host\n#=\u003e localhost\n```\n\nReading nonexistent deep values will not raise an error:\n\n```ruby\n# Deep dot notation access\np configly.some.deeply.nested_value\n#=\u003e {}\n```\n\nTo check if a key exists, use `?`\n\n```ruby\n# Check if a key exists\np configly.some.deeply.nested_value?\n#=\u003e false\n\np configly.server.port?\n#=\u003e true\n```\n\nTo get the value or `nil` if it does not exist, use `!`:\n\n\n```ruby\n# Get value or nil\np configly.some.deeply.nested_value!\n#=\u003e nil\n\np configly.server.port!\n#=\u003e 3000\n```\n\n\n### Dot notation write access\n\nWriting values is just as easy:\n\n```ruby\n# Dot notation write access\nconfigly.production.server.port = 4000\nputs configly.production.server.port\n#=\u003e 4000\n```\n\nArrays with hashes as values, will also work (as the nested hashes will be\ncoerced into Configly objects):\n\n```ruby\n# Arrays of hashes\nconfigly.servers = [\n  { host: 'prod1.example.com', port: 3000 },\n  { host: 'prod2.example.com', port: 4000 },\n]\n\nputs configly.servers.first.host\n#=\u003e prod1.example.com\n\nputs configly.servers.first.is_a? Configly\n#=\u003e true\n```\n\n### Array-like access\n\nConfigly allows read/write access using the usual array/hash syntax `#[]` using\neither a string a symbol key:\n\n```ruby\n# Array access\nputs configly.server.port     #=\u003e 3000\nputs configly.server[:port]   #=\u003e 3000\nputs configly.server['port']  #=\u003e 3000\n\nconfigly.server[:port] = 4000\nputs configly.server.port     #=\u003e 4000\n```\n\n\nLimitations\n--------------------------------------------------\n\nDue to the fact that Configly is inheriting from Hash, and using \n`method_missing` to allow dot notation access, your settings hashes cannot\nuse keys that are defined as methods in the Hash object. \n\nWhen this case is identified, a `KeyError` will be raised.\n\n```ruby\n# Reserved keys\nconfigly.api.key = '53cr3t'\n#=\u003e #\u003cKeyError: Reserved key: key\u003e\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannyben%2Fconfigly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdannyben%2Fconfigly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannyben%2Fconfigly/lists"}