README.md in umbrellio-sequel-plugins-0.4.0.81 vs README.md in umbrellio-sequel-plugins-0.4.0.107

- old
+ new

@@ -235,9 +235,63 @@ item = Item.first item.price # => #<Money fractional:5000.0 currency:USD> item.get_column_value(:amount) # => 0.5e2 ``` +## MoneyAccessors + +**Important:** requires `money` gem described above. + +Plugin for using money field keys as model properties. + +Enable: + +```ruby +add_runtime_dependency "money" +Sequel::Model.plugin :money_accessors +```` + +Examples of usage: + +##### Money accessor + +```ruby +class Order < Sequel::Model + money_accessor :amount, :currency +end + +order = Order.create(amount: 200, currency: "EUR") +order.amount # => #<Money fractional:20000.0 currency:EUR> +order.currency # => "EUR" + +order.amount = Money.new(150, "RUB") +order.amount # => #<Money fractional:150.0 currency:RUB> +``` + +##### Money setter + +```ruby +class Order < Sequel::Model + money_setter :amount, :currency +end + +order = Order.create(amount: 200, currency: "EUR") +order.amount = Money.new(150, "RUB") +order.currency # => "RUB" +``` + +##### Money getter + +```ruby +class Order < Sequel::Model + money_getter :amount, :currency +end + +order = Order.create(amount: 200, currency: "EUR") +order.amount # => #<Money fractional:20000.0 currency:EUR> +order.currency # => "EUR" +``` + ## StoreAccessors Enable: `Sequel::Model.plugin :store_accessors` Plugin for using jsonb field keys as model properties.