Class: Hibachi::Model

Inherits:
Object
  • Object
show all
Extended by:
Querying
Includes:
ActiveModel::Model, Persistence, Provisioning, Recipe
Defined in:
lib/hibachi/model.rb

Overview

A Rails model backend for describing machine configuration and exposing such configuration to manipulation by the end user. Hibachi::Model is subclassed like an ActiveRecord::Base, you define attributes on the class that map to attributes in each model’s JSON representation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Querying

all, create, each, fetch, find, where

Methods included from Provisioning

#chef, #node

Methods included from Persistence

#destroy, #new_record?, #persisted?, #save, #update_attributes

Methods included from Recipe

#recipe, #recipe_type

Constructor Details

#initialize(from_attrs = {}) ⇒ Model

Set attributes to the main collector before assigning them to methods.



26
27
28
29
# File 'lib/hibachi/model.rb', line 26

def initialize(from_attrs={})
  @attributes = from_attrs
  super
end

Instance Attribute Details

#attributesObject (readonly)

Store all attributes in this Hash.



22
23
24
# File 'lib/hibachi/model.rb', line 22

def attributes
  @attributes
end

Instance Method Details

#to_json(*arguments) ⇒ Object

The JSON representation of each Model object is simply its attributes exposed as JSON.



33
34
35
# File 'lib/hibachi/model.rb', line 33

def to_json(*arguments)
  @json ||= attributes.to_json
end