-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove virtus dependency (#18)
* test: refactor tests to use RSpec verifying doubles * test: autoload before running tests, allow manual focused testing * test: add checks to model interfaces (RED) Tests fail becase they capture a bug in `Document#transaction_date` that failed with NoMethodError `#date`. * fix: bug in transaction date for documents (GREEN) Fixes the bug, but marks the method as to be deprecated * feat: remove dependency with virtus gem Because [virtus](https://github.com/solnic/virtus) gem is officially discontinued. * fix: add .rspec file to make RSpec load spec_helper * chore: remove virtus gem from gemspec file and uninstall it
- Loading branch information
Showing
23 changed files
with
363 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require "virtus" | ||
|
||
module Norma43 | ||
module Models | ||
DEBIT_CODE = 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require "virtus" | ||
|
||
module Norma43 | ||
module Models | ||
class AdditionalCurrency | ||
include Virtus.model | ||
include Mixins::AttributesAssignment | ||
|
||
attr_accessor :data_code, :currency_code, :amount, :free | ||
|
||
attribute :data_code | ||
attribute :currency_code | ||
attribute :amount | ||
attribute :free | ||
def initialize(attributes = EMPTY_ATTRIBUTES) | ||
@data_code, | ||
@currency_code, | ||
@amount, | ||
@free = Hash(attributes).values_at( | ||
:data_code, | ||
:currency_code, | ||
:amount, | ||
:free) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require "virtus" | ||
|
||
module Norma43 | ||
module Models | ||
class AdditionalItem | ||
include Virtus.model | ||
include Mixins::AttributesAssignment | ||
|
||
attr_accessor :data_code, :item_1, :item_2 | ||
|
||
attribute :data_code | ||
attribute :item_1 | ||
attribute :item_2 | ||
def initialize(attributes = EMPTY_ATTRIBUTES) | ||
@data_code, | ||
@item_1, | ||
@item_2 = Hash(attributes).values_at( | ||
:data_code, | ||
:item_1, | ||
:item_2) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module Norma43 | ||
module Models | ||
module Mixins | ||
module AttributesAssignment | ||
EMPTY_ATTRIBUTES = {}.freeze | ||
|
||
def attributes=(new_attributes) | ||
Hash(new_attributes).each do |attr_name, attr_value| | ||
attr_writer_method_name = "#{attr_name}=".to_sym | ||
next unless public_methods(false).include?(attr_writer_method_name) | ||
|
||
public_send(attr_writer_method_name, attr_value) | ||
end | ||
end | ||
|
||
def attributes | ||
instance_variables.map { |ivar_name| | ||
attr_reader_method_name = ivar_name.to_s.delete_prefix("@").to_sym | ||
next unless public_methods(false).include?(attr_reader_method_name) | ||
|
||
attr_value = public_send(attr_reader_method_name) | ||
|
||
[attr_reader_method_name, attr_value] | ||
}.compact.to_h | ||
end | ||
alias_method :to_hash, :attributes # Implicit coercion for `Hash(model)` | ||
alias_method :to_h, :attributes # Explicit coercion | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.