Class: Paramount::Model

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/paramount/model.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = nil, model = nil) ⇒ Model

Returns a new instance of Model.



24
25
26
27
28
# File 'lib/paramount/model.rb', line 24

def initialize(params = nil, model = nil)
  @model= model
  params ||= model.attributes
  super(params)
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



6
7
8
# File 'lib/paramount/model.rb', line 6

def model
  @model
end

Class Method Details

.find(id) ⇒ Object

This ‘factory’ meant for show/edit takes no params and uses the model attributes to seed the virtus attributes usage in controller : BookParam.find(params)



19
20
21
22
# File 'lib/paramount/model.rb', line 19

def self.find(id)
  model = model_class.find(id)
  new(model.attributes, model)
end

.model_classObject

def self.model_name

raise "self.model_name needs to be defined"

end



12
13
14
# File 'lib/paramount/model.rb', line 12

def self.model_class
  @klass ||= model_name.name.constantize
end

Instance Method Details

#idObject



30
31
32
# File 'lib/paramount/model.rb', line 30

def id
  model.id
end

#persisted?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/paramount/model.rb', line 44

def persisted?
  model.new_record? ? false : true
end

#saveObject Also known as: update



34
35
36
37
# File 'lib/paramount/model.rb', line 34

def save
  assign
  model.save
end

#submitObject



40
41
42
# File 'lib/paramount/model.rb', line 40

def submit
  valid? ? persist! : false
end