Focused crawls are collections of frequently-updated webcrawl data from narrow (as opposed to broad or wide) web crawls, often focused on a single domain or subdomain.
require"pp"# Create new instance using ActiveRecord's default connection.kv=GitHub::KV.new{ActiveRecord::Base.connection}# Get a key.ppkv.get("foo")#<GitHub::Result:0x3fd88cd3ea9c value: nil># Set a key.kv.set("foo","bar")# nil# Get the key again.ppkv.get("foo")#<GitHub::Result:0x3fe810d06e4c value: "bar"># Get multiple keys at once.ppkv.mget(["foo","bar"])#<GitHub::Result:0x3fccccd1b57c value: ["bar", nil]># Check for existence of a key.ppkv.exists("foo")#<GitHub::Result:0x3fd4ae55ce8c value: true># Check for existence of key that does not exist.ppkv.exists("bar")#<GitHub::Result:0x3fd4ae55c554 value: false># Check for existence of multiple keys at once.ppkv.mexists(["foo","bar"])#<GitHub::Result:0x3ff1e98e18e8 value: [true, false]># Set a key's value if the key does not already exist.ppkv.setnx("foo","bar")# false# Delete a key.ppkv.del("bar")# nil# Delete multiple keys at once.ppkv.mdel(["foo","bar"])# nil
GitHub::SQL
# Select, insert, update, delete or whatever you need...GitHub::SQL.results<<-SQL SELECT * FROM example_key_valuesSQLGitHub::SQL.run<<-SQL,key: "foo",value: "bar" INSERT INTO example_key_values (`key`, `value`) VALUES (:key, :value)SQLGitHub::SQL.value<<-SQL,key: "foo" SELECT value FROM example_key_values WHERE `key` = :keySQL# Or slowly build up a query based on conditionals...sql=GitHub::SQL.new<<-SQL SELECT `value` FROM example_key_valuesSQLkey=ENV["KEY"]unlesskey.nil?sql.add<<-SQL,key: key WHERE `key` = :key SQLendlimit=ENV["LIMIT"]unlesslimit.nil?sql.add<<-SQL,limit: limit.to_i ORDER BY `key` ASC LIMIT :limit SQLendpsql.results
GitHub::Result
defdo_something1enddefdo_something_that_errorsraise"noooooppppeeeee"endresult=GitHub::Result.new{do_something}presult.ok?# => truepresult.value!# =>1result=GitHub::Result.new{do_something_that_errors}presult.ok?# => falsepresult.value{"default when error happens"}# => "default when error happens"beginresult.value!# raises exception because error happenedrescue=>errorpresult.errorperrorend# Outputs Step 1, 2, 3result=GitHub::Result.new{GitHub::Result.new{puts"Step 1: success!"}}.then{ |value|
GitHub::Result.new{puts"Step 2: success!"}}.then{ |value|
GitHub::Result.new{puts"Step 3: success!"}}presult.ok?# => true# Outputs Step 1, 2 and stops.result=GitHub::Result.new{GitHub::Result.new{puts"Step 1: success!"}}.then{ |value|
GitHub::Result.new{puts"Step 2: failed!"raise}}.then{ |value|
GitHub::Result.new{puts"Step 3: should not get here because previous step failed!"}}presult.ok?# => false