Module: EasyTalk::Model
- Defined in:
- lib/easy_talk/model.rb
Overview
The ‘Model` module is a mixin that provides functionality for defining and accessing the schema of a model.
It includes methods for defining the schema, retrieving the schema definition, and generating the JSON schema for the model.
Example usage:
class Person
include EasyTalk::Model
define_schema do
property :name, String, description: 'The person\'s name'
property :age, Integer, description: 'The person\'s age'
end
end
Person.json_schema #=> returns the JSON schema for Person
jim = Person.new(name: 'Jim', age: 30)
jim.valid? #=> returns true
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/easy_talk/model.rb', line 36 def self.included(base) base.include ActiveModel::API # Include ActiveModel::API in the class including EasyTalk::Model base.include ActiveModel::Validations base.extend ActiveModel::Callbacks base.extend(ClassMethods) base.include(InstanceMethods) end |