This repository has been archived by the owner on Feb 23, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
85 changed files
with
1,203 additions
and
938 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
・できるだけ基本データ型をラップする | ||
・受け入れ側は寛容に! | ||
・既存クラスのテストを書く | ||
|
||
・ユーザー登録処理をBDDで実装する | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Pinto | ||
class Characters | ||
def initialize(characters) | ||
unless characters.respond_to? :to_a | ||
raise TypeError.new('characters must respond to #to_a') | ||
end | ||
|
||
@characters = characters.to_a | ||
end | ||
|
||
def to_a | ||
return @characters | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,36 @@ | ||
# lib/pinto/config.rb | ||
module Pinto | ||
class Config | ||
def self.load(key) | ||
unless key.is_a? Pinto::Type::ConfigKey | ||
raise ArgumentError.new('key must be Pinto::Type::ConfigKey') | ||
end | ||
def self.load(config_key) | ||
config_key = Pinto::Config::Key.new(config_key) | ||
|
||
config = YAML.load_file('config/main.yml') | ||
if config[key.to_s].nil? | ||
raise ArgumentError.new('non-existent key was given') | ||
if config[config_key.to_s].nil? | ||
raise ArgumentError.new('non-existent config_key was given') | ||
end | ||
|
||
return config[config_key.to_s] | ||
end | ||
|
||
def self.uri_templates | ||
uri_templates = Pinto::URI::Templates.new | ||
self.load('uri_templates').each do |controller_name, uri_template| | ||
uri_templates.add(controller_name, uri_template) | ||
end | ||
return uri_templates | ||
end | ||
|
||
def self.openid_providers | ||
openid_providers = Pinto::OpenID::Providers.new | ||
self.load('openid_providers').each do |openid_provider| | ||
openid_providers.add(openid_provider) | ||
end | ||
return openid_providers | ||
end | ||
|
||
def self.valid_openid_provider?(openid_provider) | ||
openid_provider = Pinto::OpenID::Provider.new(openid_provider) | ||
|
||
return config[key.to_s] | ||
return self.openid_providers.include?(openid_provider) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Pinto | ||
class Config | ||
class Key | ||
def initialize(config_key) | ||
unless config_key.respond_to? :to_s | ||
raise TypeError.new('config_key must respond to #to_s') | ||
end | ||
|
||
@config_key = config_key.to_s | ||
end | ||
|
||
def to_s | ||
return @config_key | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module Pinto | ||
module Controller | ||
module Base | ||
def run(request) | ||
request = Pinto::HTTP::Request.new(request) | ||
|
||
if request.get? || request.head? | ||
method = 'get_action' | ||
elsif request.post? | ||
method = 'post_action' | ||
elsif request.put? | ||
method = 'put_action' | ||
elsif request.delete? | ||
method = 'delete_action' | ||
elsif request.options? | ||
method = 'options_action' | ||
end | ||
|
||
if self.methods.include? method | ||
return self.method(method).call(request) | ||
end | ||
|
||
return Pinto::Controller::Private::Error.run( | ||
request, | ||
405, | ||
Pinto::Translator.new(request.uri_parameters.locale_code)._( | ||
'Requested HTTP method is invalid for this resource' | ||
) | ||
) | ||
end | ||
|
||
def options_action(request) | ||
request = Pinto::HTTP::Request.new(request) | ||
|
||
allowed_methods = [] | ||
if self.methods.include? 'get_action' | ||
allowed_methods.push('GET') | ||
allowed_methods.push('HEAD') | ||
end | ||
if self.methods.include? 'post_action' | ||
allowed_methods.push('POST') | ||
end | ||
if self.methods.include? 'put_action' | ||
allowed_methods.push('PUT') | ||
end | ||
if self.methods.include? 'delete_action' | ||
allowed_methods.push('DELETE') | ||
end | ||
allowed_methods.push('OPTIONS') | ||
|
||
response = Pinto::HTTP::Response.new | ||
response.status_code = 200 | ||
response.allow = allowed_methods.join(', ') | ||
response.body = view.render | ||
return response | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Pinto | ||
module Controller | ||
class Error | ||
def self.run(request, status_code, message = '') | ||
request = Pinto::HTTP::Request.new(request) | ||
status_code = Pinto::HTTP::StatusCode.new(status_code) | ||
message = Pinto::Error::Message.new(message) | ||
|
||
response = Pinto::HTTP::Response.new | ||
response.status_code = status_code | ||
response.content_type = 'text/plain' | ||
response.body = message | ||
return response | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.