Class: BrNfe::ActiveModelBase

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, BrNfe::ActiveModel::Associations
Defined in:
lib/br_nfe/active_model_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) {|_self| ... } ⇒ ActiveModelBase

Returns a new instance of ActiveModelBase.

Yields:

  • (_self)

Yield Parameters:



16
17
18
19
20
# File 'lib/br_nfe/active_model_base.rb', line 16

def initialize(attributes = {})
	attributes = default_values.merge!(attributes)
	assign_attributes(attributes)
	yield self if block_given?
end

Instance Attribute Details

#referenceObject

Utilizado para referenciar o objeto que utiliza a informação. Setado automaticamnete no has_one e has_many; Exemplo:

~$ endereco = Endereco.new
~$ pessoa = Pessoa.new(endereco: endereco)
~$ endereco.reference
~$ => pessoa


14
15
16
# File 'lib/br_nfe/active_model_base.rb', line 14

def reference
  @reference
end

Instance Method Details

#assign_attributes(attributes) ⇒ Object



22
23
24
25
26
27
# File 'lib/br_nfe/active_model_base.rb', line 22

def assign_attributes(attributes)
	attributes ||= {}
	attributes.each do |name, value|
		send("#{name}=", value)
	end
end

#default_valuesObject



29
30
31
# File 'lib/br_nfe/active_model_base.rb', line 29

def default_values
	{}
end