Active record Query methods for simple class

I have created class using Active Model,it is working as expected ,but am having few requirements

  1. I want to use all method for that class.

  2. Same way i want to use some query methods like where method for that class.

  3. I want to create ActiveRecord::Relation so that i can do method chaining.

See my class:

require 'active_model'
require 'active_record'

class Message
 include ActiveModel::Validations
 include ActiveModel::Conversion
 extend ActiveModel::Naming

 attr_accessor :name, :email, :content

 validates_presence_of :name
 validates_length_of :content, :maximum => 500

 def initialize(attributes = {})
  attributes.each do |name, value|
   send("#{name}=", value)
  end
 end

 def persisted?
   false
 end
end

 m = Message.new(:email => "test",:name => "test")
 puts m.name   #=> test
 puts m.class  #=> Message
 puts m.valid? #=> true

 Message.all
 Message.where(:name => "test")

some more methods:

 where
 limit
 having
 group
 select
 order
 uniq

Could you please help me to achieve this or give some guide lines.

I have created class using Active Model,it is working as expected ,but am having few requirements

  1. I want to use all method for that class.

  2. Same way i want to use some query methods like where method for that class.

  3. I want to create ActiveRecord::Relation so that i can do method chaining.

See my class:

require 'active_model'
require 'active_record'


class Message
 include ActiveModel::Validations
 include ActiveModel::Conversion
 extend ActiveModel::Naming

 attr_accessor :name, :email, :content

 validates_presence_of :name
 validates_length_of :content, :maximum => 500

 def initialize(attributes = {})
  attributes.each do |name, value|
   send("#{name}=", value)
  end
 end

 def persisted?
   false
 end
end


 m = Message.new(:email => "test",:name => "test")
 puts [m.name](http://m.name)   #=> test
 puts m.class  #=> Message
 puts m.valid? #=> true

 Message.all
 Message.where(:name => "test")

some more methods:

 where
 limit
 having
 group
 select
 order
 uniq

Could you please help me to achieve this or give some guide lines.

For more details see link: active-record-query-methods-for-simple-class