Sha256: f4df830548c39d57b149922211082232762a635f452743ce8f56fa86a1d21309
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
module Hibachi module Querying include Enumerable # Write the given attrs to config and re-run Chef. def create from_attributes={} model = new from_attributes model.save model end # Find everything from the JSON. def all return fetch if singleton? node[recipe_name].map { |from_params| new from_params } end def each all.each { |model| yield model } end # Find all objects of this type matching the given search # criteria. Uses the all() method to scope calls from within the # proper JSON for this class, and instantiates objects based on # the found information, so you get back an Array of whatever # object this model happens to be. If none, this returns an empty # Array. def where has_attributes={} return fetch if singleton? all.select { |persisted_attr, persisted_val| has_attributes.any? { |search_attr, search_val| persisted_attr == search_attr && persisted_val == search_val } }.map { |from_params| new from_params } end # Find a given model by name, or return `nil`. Aliases to `fetch` if # this model is a singleton. def find by_name="" return fetch if singleton? where(name: by_name).first end # Use all the attributes in this recipe to deploy the model if this # is a Singleton. def fetch model = new node[recipe_name] model.valid? model end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hibachi-0.0.1 | lib/hibachi/querying.rb |