1
0
Fork 0

Add model Address

This commit is contained in:
Alex Kotov 2021-03-10 16:26:28 +05:00
parent e4c1739fd9
commit 307a1bedfa
4 changed files with 58 additions and 1 deletions

27
app/models/address.rb Normal file
View file

@ -0,0 +1,27 @@
class Address < ApplicationRecord
scope :added_to_wallet, -> { where added_to_wallet: true }
scope :to_update_op_return, lambda {
added_to_wallet.where(
Address.arel_table[:op_return_updated_at].eq(nil)
.or(Address.arel_table[:op_return_updated_at].lt(1.hour.ago)),
)
}
validates :value, presence: true, uniqueness: true
def update_op_return?
added_to_wallet? && (
op_return_updated_at == nil ||
op_return_updated_at < 1.hour.ago
)
end
def add_to_wallet
AddAddressToWallet.perform_later self unless added_to_wallet?
end
def update_op_return
UpdateAddressOpReturn.perform_later self if update_op_return?
end
end

View file

@ -0,0 +1,13 @@
class CreateAddresses < ActiveRecord::Migration[6.1]
def change
create_table :addresses do |t|
t.timestamps
t.string :value, null: false
t.boolean :added_to_wallet, null: false, default: false
t.string :op_return_value
t.datetime :op_return_updated_at
end
add_index :addresses, :value, unique: true
end
end

12
db/schema.rb generated
View file

@ -10,7 +10,17 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_03_10_102531) do
ActiveRecord::Schema.define(version: 2021_03_10_111839) do
create_table "addresses", force: :cascade do |t|
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "value", null: false
t.boolean "added_to_wallet", default: false, null: false
t.string "op_return_value"
t.datetime "op_return_updated_at"
t.index ["value"], name: "index_addresses_on_value", unique: true
end
create_table "followships", force: :cascade do |t|
t.datetime "created_at", precision: 6, null: false

View file

@ -0,0 +1,7 @@
require "test_helper"
class AddressTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end