Add model Address
This commit is contained in:
parent
e4c1739fd9
commit
307a1bedfa
4 changed files with 58 additions and 1 deletions
27
app/models/address.rb
Normal file
27
app/models/address.rb
Normal 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
|
13
db/migrate/20210310111839_create_addresses.rb
Normal file
13
db/migrate/20210310111839_create_addresses.rb
Normal 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
12
db/schema.rb
generated
|
@ -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
|
||||
|
|
7
test/models/address_test.rb
Normal file
7
test/models/address_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class AddressTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Reference in a new issue