Skip to content

Instantly share code, notes, and snippets.

@ainame
Created December 30, 2011 10:35
Show Gist options
  • Select an option

  • Save ainame/1539220 to your computer and use it in GitHub Desktop.

Select an option

Save ainame/1539220 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
#
# ぼくのかんがえた最強のWeb API利用のためのモジュール
# モジュール名適当
# かなーりゆるい設計
#
module AnythingResource
class Procedure < Proc
# 手続きを記述するための
# AccessorとActionerの基底クラス
end
class Accessor
# 入力
# 必ずAnythingAPI::Responseを返す
end
class Actioner
#出力
end
end
module AnythingResource
class Response
include Actioner
# Accessorによって得た結果
# Actionerの操作が適用できる
end
end
module AnythingResource
class Source
# 既存のWebAPIモジュールをラップするためのクラス
# の基底クラス
end
class Twitter < ActiveAPI::Source
end
end
module AnythingResource
module Event
# 非同期処理がしたいと時の
# イベントを書くための基底モジュール
end
end
# 実行例
# めっちゃ擬似コード
require 'anything_resource'
require 'anything_twitter'
# AccessとActionを統べる手続きを記述するためのインスタンス
# ここの初期化の書き方はどうするのがいいかわからない
proc = AnythingResource.new(
AnythingResource::Twitter
)
# 記述の仕方のイメージとしてはjQueryっぽい感じだけどaccessとactionに渡す手続きは,
# AnythingResource::Procedureクラスを継承したクラスで定義してあげて
# そのインスタンスを引数で渡す.それを配布できるようにしてあげる予定.
search_rice_ball = proc.before( Proc.new{ AnythingResource::Twitter.activate() } ) # 実態はactionだが引数は受け取れない?
.access( Proc.new{ AnythingResource::Twitter.search("おにぎり") } ) # これだけ特別.newで指定したモジュールのメソッドを実行
.action( Proc.new{|x| p x } ) # AnythingResource::Responseを引数に受け取る
.after ( Proc.new{|x| AnythingResource::Actioner.store_to_mongo(x) } ) # actionと同じ.mongoDBに保存などを実装
search_rice_ball.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment