lib/soulless/model.rb in soulless-0.6.0 vs lib/soulless/model.rb in soulless-1.0.0
- old
+ new
@@ -1,76 +1,37 @@
module Soulless
- module Model
- def self.included(base)
- base.class_eval do
- extend ActiveModel::Naming
- extend ActiveModel::Translation
- extend ActiveModel::Callbacks
- include ActiveModel::Conversion
- include ActiveModel::Dirty
- include ActiveModel::Validations
+ class Model
+ extend ActiveModel::Callbacks
+ extend ActiveModel::Naming
+ extend ActiveModel::Translation
- class << self
- def i18n_scope
- :soulless
- end
- end
+ extend Soulless::Inheritance
- define_model_callbacks :validation, :save
+ include ActiveModel::AttributeMethods
+ include ActiveModel::Dirty
+ include ActiveModel::SecurePassword
+ include ActiveModel::Serialization
+ include ActiveModel::Validations
- def initialize(params = {})
- init_accessors(attribute_set.map { |a| a.name })
- super
- init_dirty
- end
+ include Soulless::Dirty
+ include Soulless::Validations
- def persisted?
- false
- end
+ include Virtus.model
- def valid_with_callbacks?
- run_callbacks :validation do
- valid_without_callbacks?
- end
- end
+ prepend Soulless::Attributes
+ prepend Soulless::Callbacks
- alias_method_chain :valid?, :callbacks
+ def initialize(params = {})
+ super
- def save
- if valid?
- run_callbacks :save do
- persist!
- changes_applied
- true
- end
- else
- false
- end
- end
+ apply_changes
+ end
- def assign_attributes(attributes)
- deep_update(self, attributes)
- end
+ def i18n_scope
+ :soulless
+ end
- def update_attributes(attributes)
- assign_attributes(attributes)
- save
- end
-
- private
- def persist!
- raise 'Method persist! not defined...'
- end
-
- def deep_update(object, attributes)
- attributes.each do |key, value|
- if value.kind_of?(Hash)
- deep_update(object.send(key), value)
- else
- object.send("#{key}=", value)
- end
- end
- end
- end
+ def persisted?
+ false
end
end
end