require 'activerecord' ActiveRecord::Base # autoload all modules class MyClass def save; end def save!; end def new_record?; true; end include ActiveRecord::Validations attr_accessor :attr validates_length_of :attr, :minimum => 4 end
require 'activerecord' ActiveRecord::Base # autoload all modules class MyClass def save; end def save!; end def new_record?; true; end include ActiveRecord::Validations attr_accessor :attr validates_length_of :attr, :minimum => 4 end What? ActiveRecord::Base # autoload all modules
require 'activerecord' ActiveRecord::Base # autoload all modules class MyClass def save; end def save!; end def new_record?; true; end include ActiveRecord::Validations attr_accessor :attr validates_length_of :attr, :minimum => 4 end def save; end def save!; end LOL
require 'activerecord' ActiveRecord::Base # autoload all modules class MyClass def save; end def save!; end def new_record?; true; end include ActiveRecord::Validations attr_accessor :attr validates_length_of :attr, :minimum => 4 end def new_record?; true; end trolling
require 'activerecord' ActiveRecord::Base # autoload all modules class MyClass def save; end def save!; end def new_record?; true; end include ActiveRecord::Validations attr_accessor :attr validates_length_of :attr, :minimum => 4 end include ActiveRecord::Validations attr_accessor :attr validates_length_of :attr, :minimum => 4 there we go!
require 'activerecord' ActiveRecord::Base # autoload all modules class MyClass def save; end def save!; end def new_record?; true; end include ActiveRecord::Validations attr_accessor :attr validates_length_of :attr, :minimum => 4 end ActiveRecord::Base # autoload all modules def save; end def save!; end def new_record?; true; end
require 'activerecord' ActiveRecord::Base # autoload all modules class MyClass def save; end def save!; end def new_record?; true; end include ActiveRecord::Validations attr_accessor :attr validates_length_of :attr, :minimum => 4 end include ActiveRecord::Validations attr_accessor :attr validates_length_of :attr, :minimum => 4
require 'activerecord' ActiveRecord::Base # autoload all modules class MyClass def save; end def save!; end def new_record?; true; end include ActiveRecord::Validations attr_accessor :attr validates_length_of :attr, :minimum => 4 end
module ActiveRecord class Base extend ActiveModel::Naming # Uses ActiveModel::Translation extend Translation # Uses ActiveModel::MassAssignmentSecurity include AttributeAssignment include ActiveModel::Conversion # Uses ActiveModel::Validations include Validations # Uses ActiveModel::AttributeMethods include AttributeMethods # Uses ActiveModel::Callbacks include Callbacks include ActiveModel::Observing include ActiveModel::SecurePassword # Uses ActiveModel::Serialization include Serialization # ... end end
module ActiveResource class Base extend ActiveModel::Naming # Uses ActiveModel::Observing include Observing # Uses ActiveModel::Validations include Validations include ActiveModel::Conversion include ActiveModel::Serializers::JSON include ActiveModel::Serializers::Xml # ... end end
class Report include ActiveModel::Validations attr_accessor :name validates_presence_of :name end Active Model include ActiveModel::Validations validates_presence_of :name
class ReportValidator < ActiveModel::Validator def validate(report) if report.name.blank? report.errors.add :name, :blank end # More validations... end end Active Record
class ReportValidator < ActiveModel::Validator def validate(report) if report.name.blank? report.errors.add :name, :blank end # More validations... end end Active Record ReportValidator < ActiveModel::Validator def validate(report)
class Report include ActiveModel::Validations validates_with ReportValidator attr_accessor :name end Active Model include ActiveModel::Validations validates_with ReportValidator
class Report include ActiveModel::Validations attr_accessor :name # validates_presence_of :name validates :name, presence: true end Active Model include ActiveModel::Validations validates :name, presence: true
class Report include ActiveModel::Validations attr_accessor :no_name validates :no_name, absence: true end include ActiveModel::Validations validates :no_name, absence: true Active Model
class AbsenceValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) if value.present? record.errors.add attribute, :absence end end end Active Model
class AbsenceValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) if value.present? record.errors.add attribute, :absence end end end AbsenceValidator Active Model
class AbsenceValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) if value.present? record.errors.add attribute, :absence end end end AbsenceValidator Active Model AbsenceValidator < ActiveModel::EachValidator def validate_each(record, attribute, value)
class Report extend ActiveModel::Callbacks define_model_callbacks :save before_save { puts "it works before" } after_save { puts "it works after as well" } def save run_callbacks :save do puts "saving..." end end end Active Model
class Report extend ActiveModel::Callbacks define_model_callbacks :save before_save { puts "it works before" } after_save { puts "it works after as well" } def save run_callbacks :save do puts "saving..." end end end extend ActiveModel::Callbacks define_model_callbacks :save before_save { puts "it works before" } after_save { puts "it works after as well" } run_callbacks :save do puts "saving..." end Active Model
class Report extend ActiveModel::Naming include ActiveModel::Serializers::JSON attr_accessor :name def attributes { name: name } end end Active Model include ActiveModel::Serializers::JSON def attributes { name: name } end
class Report extend ActiveModel::Naming include ActiveModel::Serializers::Xml attr_accessor :name def attributes { name: name } end end include ActiveModel::Serializers::Xml def attributes { name: name } end Active Model
class Report include ActiveModel::AttributeMethods attribute_method_suffix '?' define_attribute_methods [:name] attr_accessor :name private def attribute?(attr) send(attr).present? end end Active Model
class Report include ActiveModel::AttributeMethods attribute_method_suffix '?' define_attribute_methods [:name] attr_accessor :name private def attribute?(attr) send(attr).present? end end include ActiveModel::AttributeMethods attribute_method_suffix '?' define_attribute_methods [:name] def attribute?(attr) send(attr).present? end Active Model
class Report include ActiveModel::AttributeMethods attribute_method_prefix 'clear_' define_attribute_methods [:name] attr_accessor :name private def clear_attribute(attr) send "#{attr}=", nil end end Active Model
class Report include ActiveModel::AttributeMethods attribute_method_prefix 'clear_' define_attribute_methods [:name] attr_accessor :name private def clear_attribute(attr) send "#{attr}=", nil end end Active Model include ActiveModel::AttributeMethods attribute_method_prefix 'clear_' define_attribute_methods [:name] def clear_attribute(attr) send "#{attr}=", nil end
module ActiveModel::Lint::Tests def test_to_key; end def test_to_param; end def test_to_partial_path; end def test_valid?; end def test_persisted?; end def test_model_naming; end def test_errors_aref; end def test_errors_full_messages; end end
module ActiveModel::Lint::Tests def test_to_key; end def test_to_param; end def test_to_partial_path; end def test_valid?; end def test_persisted?; end def test_model_naming; end def test_errors_aref; end def test_errors_full_messages; end end to_key to_param to_partial_path valid? persisted? model_naming errors_aref errors_full_messages
module ActiveModel::Lint::Tests def test_to_key; end def test_to_param; end def test_to_partial_path; end def test_valid?; end def test_persisted?; end def test_model_naming; end def test_errors_aref; end def test_errors_full_messages; end end to_key to_param to_partial_path valid? persisted? model_naming errors_aref errors_full_messages Naming
module ActiveModel::Lint::Tests def test_to_key; end def test_to_param; end def test_to_partial_path; end def test_valid?; end def test_persisted?; end def test_model_naming; end def test_errors_aref; end def test_errors_full_messages; end end to_key to_param to_partial_path valid? persisted? model_naming errors_aref errors_full_messages Conversion
module ActiveModel::Lint::Tests def test_to_key; end def test_to_param; end def test_to_partial_path; end def test_valid?; end def test_persisted?; end def test_model_naming; end def test_errors_aref; end def test_errors_full_messages; end end to_key to_param to_partial_path valid? persisted? model_naming errors_aref errors_full_messages Implementar
module ActiveModel::Lint::Tests def test_to_key; end def test_to_param; end def test_to_partial_path; end def test_valid?; end def test_persisted?; end def test_model_naming; end def test_errors_aref; end def test_errors_full_messages; end end to_key to_param to_partial_path valid? persisted? model_naming errors_aref errors_full_messages Validations
require 'minitest/autorun' class OmglolTest < MiniTest::Unit::TestCase include ActiveModel::Lint::Tests def setup @model = Omglol.new end end include ActiveModel::Lint::Tests def setup @model = Omglol.new end
require 'active_model' class Omglol extend ActiveModel::Naming include ActiveModel::Conversion include ActiveModel::Validations def persisted?; false; end end
require 'active_model' class Omglol extend ActiveModel::Naming include ActiveModel::Conversion include ActiveModel::Validations def persisted?; false; end end extend ActiveModel::Naming include ActiveModel::Conversion include ActiveModel::Validations def persisted?; false; end
module ActiveModel::Lint::Tests def test_to_key; end def test_to_param; end def test_to_partial_path; end def test_valid?; end def test_persisted?; end def test_model_naming; end def test_errors_aref; end def test_errors_full_messages; end end to_key to_param to_partial_path valid? persisted? model_naming errors_aref errors_full_messages
module ActiveModel::Lint::Tests def test_to_key; end def test_to_param; end def test_to_partial_path; end def test_valid?; end def test_persisted?; end def test_model_naming; end def test_errors_aref; end def test_errors_full_messages; end end to_key to_param to_partial_path valid? persisted? model_naming errors_aref errors_full_messages Validations?
module ActiveModel::Lint::Tests def test_to_key; end def test_to_param; end def test_to_partial_path; end def test_valid?; end def test_persisted?; end def test_model_naming; end def test_errors_aref; end def test_errors_full_messages; end end RAILS 4 to_key to_param to_partial_path valid? persisted? model_naming errors_aref errors_full_messages
require 'minitest/autorun' class OmglolTest < MiniTest::Unit::TestCase include ActiveModel::Lint::Tests def setup @model = Omglol.new end end RAILS 4 include ActiveModel::Lint::Tests def setup @model = Omglol.new end
require 'active_model' class Omglol extend ActiveModel::Naming include ActiveModel::Conversion def persisted?; false; end def errors; Hash.new([]); end end RAILS 4
require 'active_model' class Omglol extend ActiveModel::Naming include ActiveModel::Conversion def persisted?; false; end def errors; Hash.new([]); end end RAILS 4 def errors; Hash.new([]); end
require 'active_model' class Omglol extend ActiveModel::Naming include ActiveModel::Conversion def persisted?; false; end def errors; Hash.new([]); end end RAILS 4 extend ActiveModel::Naming include ActiveModel::Conversion def persisted?; false; end def errors; Hash.new([]); end def errors; Hash.new([]); end
require 'active_model' class Omglol extend ActiveModel::Naming include ActiveModel::Conversion def persisted?; false; end def errors; Hash.new([]); end end RAILS 4
require 'active_model' class Omglol extend ActiveModel::Naming include ActiveModel::Conversion def persisted?; false; end def errors; Hash.new([]); end end RAILS 4 extend ActiveModel::Naming include ActiveModel::Conversion def persisted?; false; end def errors; Hash.new([]); end
module Model def self.included(base) #:nodoc: base.class_eval do extend ActiveModel::Naming extend ActiveModel::Translation include ActiveModel::Validations include ActiveModel::Conversion end end def initialize(params={}) params.each do |attr, value| self.public_send("#{attr}=", value) end if params end def persisted? false end end RAILS 4
module Model def self.included(base) #:nodoc: base.class_eval do extend ActiveModel::Naming extend ActiveModel::Translation include ActiveModel::Validations include ActiveModel::Conversion end end def initialize(params={}) params.each do |attr, value| self.public_send("#{attr}=", value) end if params end def persisted? false end end RAILS 4 extend ActiveModel::Naming extend ActiveModel::Translation include ActiveModel::Validations include ActiveModel::Conversion def persisted? false end
Active Model Attribute Methods Callbacks Dirty Mass Assignment Secure Password Observing Serialization Validations Validator Model Conversion Naming Translation Lint