class Mechanical::Model

Attributes

fields[R]
model[R]
name[R]
options[R]

Public Class Methods

new(name, options = {}) click to toggle source
# File lib/mechanical.rb, line 46
def initialize(name, options = {})
  @name    = name
  @fields  = {}
  @options = options
  @model   = eval %{
    class #{name} < ApplicationRecord
      self.table_name = "mechanical_mechanical_stores"
      def self.model_name; ActiveModel::Name.new(self, nil, "#{name.downcase}"); end

      default_scope -> { where(mechanical_model_type: name) }

      belongs_to :user, optional: true, foreign_key: :mechanical_user_id
      belongs_to :mechanicalable, polymorphic: true, optional: true
    end
    #{name}
  }

  puts "Mechanical init model => #{@model}"
end

Public Instance Methods

add_methods(&block) click to toggle source
# File lib/mechanical.rb, line 70
def add_methods(&block)
  @model.class_eval(&block)
end
field(name, options = {}, &block) click to toggle source
# File lib/mechanical.rb, line 66
def field(name, options = {}, &block)
  @fields[name] = Field.new(self, name, options)
end