Better settings coupling with spec coverage
This commit is contained in:
+15
-6
@@ -1,13 +1,19 @@
|
||||
class Employee
|
||||
include SimplyStored::Couch
|
||||
include ActiveModel::SerializerSupport
|
||||
attr_reader :settings
|
||||
DEFAULT_SETTINGS = {
|
||||
'manager' => false,
|
||||
'active' => true,
|
||||
'color' => '#3a87ad'
|
||||
}
|
||||
attr_accessor *DEFAULT_SETTINGS.keys
|
||||
attr_reader :settings
|
||||
DEFAULT_SETTINGS.each do |attribute, default_value|
|
||||
define_method(attribute) { settings.public_send attribute }
|
||||
define_method("#{attribute}=") { |value| settings.set attribute, value }
|
||||
if default_value == true or default_value == false # boolean
|
||||
define_method(:"#{attribute}?"){ public_send attribute }
|
||||
end
|
||||
end
|
||||
|
||||
view :by_confirmation_token, key: :confirmation_token # devise confirmable
|
||||
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :confirmable
|
||||
@@ -35,10 +41,13 @@ class Employee
|
||||
|
||||
def enrich_with_settings(settings)
|
||||
@settings = settings
|
||||
settings.settings.each do |attribute, value|
|
||||
public_send "#{attribute}=", value
|
||||
end
|
||||
settings
|
||||
end
|
||||
alias_method :settings=, :enrich_with_settings
|
||||
|
||||
alias_method :orig_save, :save
|
||||
def save(*args)
|
||||
settings.persist!
|
||||
orig_save(*args)
|
||||
end
|
||||
|
||||
def settings
|
||||
|
||||
Reference in New Issue
Block a user