All Projects → pcriv → statics

pcriv / statics

Licence: MIT license
Base class and modules for YAML backed static models.

Programming Languages

ruby
36898 projects - #4 most used programming language
shell
77523 projects

Labels

Projects that are alternatives of or similar to statics

zf-dependency-injection
Advanced dependency injection for laminas framework
Stars: ✭ 17 (-58.54%)
Mutual labels:  yaml
obp-apis
OpenBankingProject.ch Community APIs
Stars: ✭ 18 (-56.1%)
Mutual labels:  yaml
AUCR
Analyst Unknown Cyber Range - a micro web service framework
Stars: ✭ 24 (-41.46%)
Mutual labels:  yaml
eslint-plugin-yml
This ESLint plugin provides linting rules for YAML.
Stars: ✭ 40 (-2.44%)
Mutual labels:  yaml
coqpit
Simple but maybe too simple config management through python data classes. We use it for machine learning.
Stars: ✭ 67 (+63.41%)
Mutual labels:  yaml
icingaweb2-module-fileshipper
Provide CSV, JSON, XML and YAML files as an Import Source for the Icinga Director and optionally ship hand-crafted additional Icinga2 config files
Stars: ✭ 25 (-39.02%)
Mutual labels:  yaml
representable
Maps representation documents from and to Ruby objects. Includes JSON, XML and YAML support, plain properties and compositions.
Stars: ✭ 689 (+1580.49%)
Mutual labels:  yaml
pipeline
Spline is a tool that is capable of running locally as well as part of well known pipelines like Jenkins (Jenkinsfile), Travis CI (.travis.yml) or similar ones.
Stars: ✭ 29 (-29.27%)
Mutual labels:  yaml
paerser
No description or website provided.
Stars: ✭ 38 (-7.32%)
Mutual labels:  yaml
HsYAML
YAML 1.2 implementation in pure Haskell
Stars: ✭ 50 (+21.95%)
Mutual labels:  yaml
gen-cisco
🧨 Generates Cisco scripts based on YAML files
Stars: ✭ 29 (-29.27%)
Mutual labels:  yaml
Prinder
Free Pull Request reminder for Github. Has configurations to post reminders to Slack and email along with jinja templating
Stars: ✭ 21 (-48.78%)
Mutual labels:  yaml
go-config
Configuration file loader for Go
Stars: ✭ 27 (-34.15%)
Mutual labels:  yaml
zettelgeist
A less-is-more (distributed) notetaking application. Designed specifically for those who prefer working with the command line and want to do crazy indexing, analysis, and transformation of notes. Aimed at but not limited to scholarly research projects.
Stars: ✭ 25 (-39.02%)
Mutual labels:  yaml
elk
🦌 Minimalist yaml based task runner
Stars: ✭ 43 (+4.88%)
Mutual labels:  yaml
gitlabform
🏗 Specialized "configuration as a code" tool for GitLab
Stars: ✭ 332 (+709.76%)
Mutual labels:  yaml
kahoy
Simple Kubernetes raw manifests deployment tool
Stars: ✭ 33 (-19.51%)
Mutual labels:  yaml
dynamic.yaml
DEPRECATED: YAML-based data transformations
Stars: ✭ 14 (-65.85%)
Mutual labels:  yaml
ryaml
Python yaml library using Rust
Stars: ✭ 14 (-65.85%)
Mutual labels:  yaml
consulator
Import and synchronize your Consul KV data from JSON and YAML
Stars: ✭ 27 (-34.15%)
Mutual labels:  yaml

Statics

Gem Depfu Inline docs Maintainability Test Coverage

Base class and modules for static models.

Links:

Requirements

  1. Ruby 2.5.0

Installation

To install, run:

gem install statics

Or add the following to your Gemfile:

gem "statics"

Usage

Setting the data path:

Statics.configure do |config|
  config.data_path = "data/"
end

Defining a static model:

class Post < Statics::Model
  filename "posts"

  attribute :title, Types::Strict::String
end
# data/posts.yml
---
post1:
  title: "Post 1"

post2:
  title: "Post 2"
Post.all
#=> #<Statics::Collection records=[#<Post key=:post1 title="Post 1">, #<Post key=:post2 title="Post 2">]>
Post.where(title: "Post 1")
#=> #<Statics::Collection records=[#<Post key=:post1 title="Post 1">]>
Post.where_not(title: "Post 1")
#=> #<Statics::Collection records=[#<Post key=:post2 title="Post 2">]>
Post.find_by(key: :post1)
#=> #<Post key=:post1 title="Post 1">
Post[:post1]
#=> #<Post key=:post1 title="Post 1">
Post.pluck(:title)
#=> ["Post 1", "Post 2"]
post = Post.first
#=> #<Post key=:post1 title="Post 1">
post.key
#=> :post1
post.title
#=> "Post 1"
post.attributes
#=> {:title=>"Post 1", :key=>:post1}

Defining translatable attributes:

class Post < Statics::Model
  include Statics::Translatable

  filename "posts"

  attribute :title, Types::Strict::String
  translatable_attribute :body
end
# data/posts.yml
---
post1:
  title: "Post 1"
  body:
    en: "Hello!"
    nl: "Hallo!"

post2:
  title: "Post 2"
  body:
    en: "Bye!"
    nl: "Doei!"
post = Post.first
# when I18n.locale is :en
post.body #=> "Hello!"
post.body(locale: :nl) #=> "Hallo!"

Defining omittable attributes with defaults:

class Post < Statics::Model
  include Statics::Translatable

  filename "posts"

  attribute :title, Types::Strict::String
  # With default
  attribute? :author, Types::Strict::String.default("Unknown")
  # Without default
  # attribute? :author, Types::Strict::String
end
# data/posts.yml
---
post1:
  title: "Post 1"
  author: "Rick Sanchez"

post2:
  title: "Post 2"
post1 = Post.first
post1.author #=> "Rick Sanchez"
post2 = Post.last
post2.author #=> "Unknown"

Check dry-types for documentation about the built-in types.

Caveats

If you have dates in your yaml-files, use the following format for them to be handled properly: YYYY-MM-DD

Tests

To test, run:

bundle exec rspec spec/

Versioning

Read Semantic Versioning for details. Briefly, it means:

  • Major (X.y.z) - Incremented for any backwards incompatible public API changes.
  • Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
  • Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.

License

Copyright 2018 Pablo Crivella. Read LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].