module Signable::Concerns::Model
Public Class Methods
new(attributes = {})
click to toggle source
# File lib/signable/concerns/model.rb, line 8 def initialize(attributes = {}) @attributes = HashWithIndifferentAccess.new self.attributes = attributes end
Public Instance Methods
attributes=(attributes = {})
click to toggle source
# File lib/signable/concerns/model.rb, line 13 def attributes=(attributes = {}) attributes.each do |key, value| if column = find_column(key) @attributes[column.name] = value elsif embed = find_embed(key) values = value.map { |hash| embed.embed_class.new(hash) } @attributes[embed.name] = values end end end
form_data()
click to toggle source
# File lib/signable/concerns/model.rb, line 24 def form_data hash = HashWithIndifferentAccess.new @attributes.each do |key, value| next if key == :id if (column = self.find_column(key)) hash[column.name_with_prefix] = value elsif (embed = self.find_embed(key)) hash[embed.name_with_prefix] = value.map(&:form_data) end end hash end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/signable/concerns/model.rb, line 40 def method_missing(method, *args, &block) get_method = method.to_s.gsub('=', '') object = find_column(get_method) || find_embed(get_method) if object if get_method.to_sym == method @attributes[object.name] else @attributes[object.name] = args.first end else super end end
valid?()
click to toggle source
# File lib/signable/concerns/model.rb, line 54 def valid? required_column.all? do |column| @attributes[column.name].present? end end