0.0
No commit activity in last 3 years
No release in over 3 years
Make Model as much as readable
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.8
~> 10.0
 Project Readme

ReadableModel

This gem doesn't do any logical opertaion. Just make the MVC - Model as much as readable. This library adds the model template as per the rails style guide. https://github.com/bbatsov/rails-style-guide#activerecord

Installation

Add this line to your application's Gemfile:

gem 'readable_model'

And then execute:

$ bundle

Or install it yourself as:

$ gem install readable_model

Usage

rails generate scaffold scaffold_name

or

rails generate model model_name

Now check your model file

Before readable_model template

class User < ActiveRecord::Base
  include UrlHelper
  serialize :template
  belongs_to :country

  alias_attribute :subject, :title

  has_one :photo
  has_many :authentications, dependent: :destroy, inverse_of: :user
  has_many :items, dependent: :destroy, counter_cache: true

  self.table_name = "admin_users"
  validates :email, presence: true
  validates :username, presence: true

  before_save :cook
  after_create :update_item
  validates :username, uniqueness: { case_sensitive: false }

  COLORS = ['red', 'green', 'blue']
  attr_accessor :date
  @@per_page = 10
  scope :blocked, -> { where(active: false }
  delegate :name, :address, to: :order, prefix: :order
  serialize :rule_options

  def role
    role_type.inquiry
  end
end

After readable_model template

class User < ActiveRecord::Base
  include UrlHelper

  # Default Scope
  default_scope { where(active: true) }

  # Configurations
  self.table_name = "admin_users"
  COLORS = ['red', 'green', 'blue']
  @@per_page = 10

  # Attributes
  attr_accessor :date
  alias_attribute :subject, :title
  delegate :name, :address, to: :order, prefix: :order
  serialize :template

  # Associations
  has_one :photo
  has_many :authentications, dependent: :destroy, inverse_of: :user
  has_many :items, dependent: :destroy, counter_cache: true
  belongs_to :country

  # Validations
  validates :email, presence: true
  validates :username, presence: true
  validates :username, uniqueness: { case_sensitive: false }

  # Callbacks
  before_save :cook
  after_create :update_item

  # Scopes
  scope :blocked, -> { where(active: false }

  def role
    role_type.inquiry
  end
end