driver 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59a3aa15e02608b6e50a9f9a645ddaa5b9e1cf2c
4
+ data.tar.gz: cc6b150d10e15b62307e73c2d8da36d93a9d60fe
5
+ SHA512:
6
+ metadata.gz: e4f2f0ef025a4deaf5e5764377a87282493f3654ada5dccbd6d80bac416d6ef88b595ae4b904a9ade8985f3561a7e6d556015283f9f5e61a833c6ef393162051
7
+ data.tar.gz: 6f9e2174fa375ac03889906a592448d01b314b79bed15c2eb3e5d271936e85988eef8e6014438ddd05fe6474b821f76d580f95898dc0e062505454f4da857190
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/APIClient.png ADDED
Binary file
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in driver.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'pry', '< 0.10.0'
8
+ gem 'pry-byebug'
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 hiro-su
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # Driver
2
+
3
+ Simple Framework for API Client.
4
+
5
+ Client, Model, APIを分離するアイデアです.
6
+
7
+ ## Usage
8
+ 使用法方は[ダミーアプリケーション](https://github.com/hiro-su/driver/tree/master/spec/dummy)を参照
9
+
10
+ ## Architecture
11
+ ### Client
12
+ - ユーザとのやり取りはすべてこのClient経由で行う。
13
+ - 基本的にはモデルインスタンスを返却する。
14
+ - APIを直接呼び出すことも可能。
15
+
16
+ ### Model
17
+ - APIからデータを取得し、自インスタンスをClientへ返却する。
18
+
19
+ ### API
20
+ - 実際にWebServerのAPIを叩く部分。
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/driver.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "driver"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["hiro-su"]
9
+ spec.email = ["h.sugipon@gmail.com"]
10
+ spec.summary = %q{Simple Framework for API Client.}
11
+ spec.description = %q{Simple Framework for API Client.}
12
+ spec.homepage = "https://github.com/hiro-su/driver"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "activesupport", "~> 4.2.1"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ end
data/lib/driver/api.rb ADDED
@@ -0,0 +1,19 @@
1
+ module Driver
2
+ class API
3
+ class << self
4
+ def const_missing(name)
5
+ name
6
+ end
7
+
8
+ def drive(*modules)
9
+ modules.each_with_index do |m, i|
10
+ api = "#{self}::#{m.to_s.demodulize}"
11
+ autoload m.to_s.demodulize, api.underscore
12
+ modules[i] = api.constantize
13
+ end
14
+
15
+ include *modules
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,33 @@
1
+ module Driver
2
+ class Client
3
+ class << self
4
+ def const_missing(name)
5
+ name
6
+ end
7
+
8
+ def drive(*modules)
9
+ # api
10
+ autoload :API, "#{self}/api".underscore
11
+
12
+ modules.each_with_index do |m, i|
13
+ # client
14
+ autoload m, "#{self}::#{m}".underscore
15
+
16
+ # model
17
+ module_name = self.to_s.sub("::#{self.to_s.demodulize}", '').constantize
18
+ module_name.autoload m, "#{self}::Model::#{m}".underscore
19
+
20
+ modules[i] = "#{self}::#{m}".constantize
21
+ end
22
+
23
+ include *modules
24
+ end
25
+ end
26
+
27
+ attr_reader :api
28
+
29
+ def initialize(api)
30
+ @api = api
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ module Driver
2
+ class Model
3
+ def initialize(api)
4
+ @api = api
5
+ end
6
+ end
7
+ end
data/lib/driver.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "driver/client"
2
+ require "driver/model"
3
+ require "driver/api"
4
+ require "active_support/core_ext/string/inflections"
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Driver do
4
+ let(:client) { Dummy::Client.new('apikey', 'secret') }
5
+
6
+ describe "Dummy Client" do
7
+ it "return Dummy::Client instance" do
8
+ expect(client.class).to eq Dummy::Client
9
+ expect(client.apikey).to eq "apikey"
10
+ expect(client.secret).to eq "secret"
11
+ end
12
+
13
+ it "return Dummy::Client::API instance" do
14
+ expect(client.api.class).to eq Dummy::Client::API
15
+ expect(client.api.create_database("test")).to eq "create_database: test"
16
+ expect(client.api.drop_table("test")).to eq "drop_table: test"
17
+ end
18
+
19
+ it "return Dummy::Database instance" do
20
+ expect(client.db.class).to eq Dummy::Database
21
+ expect(client.db.create("test")).to eq "create_database: test"
22
+ expect(client.db.delete("test")).to eq "drop_table: test"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ $LOAD_PATH << Pathname.new(__FILE__).dirname.join('..', '..', '..', 'lib').expand_path.to_s
5
+ $LOAD_PATH << Pathname.new(__FILE__).dirname.join('..', 'lib').expand_path.to_s
6
+
7
+ require 'dummy'
8
+
9
+ client = Dummy::Client.new('apikey', 'secret')
10
+ puts client.db.create("testdb")
11
+ puts client.db.delete("testdb")
@@ -0,0 +1,9 @@
1
+ module Dummy
2
+ class Client::API
3
+ module Database
4
+ def create_database(name)
5
+ "#{__method__}: #{name}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Dummy
2
+ class Client::API
3
+ module Table
4
+ def drop_table(name)
5
+ "#{__method__}: #{name}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module Dummy
2
+ class Client
3
+ class API < Driver::API
4
+ drive Database, Table
5
+
6
+ def initialize(apikey, secret, options = {})
7
+ @apikey = apikey
8
+ @secret = secret
9
+ @options = options
10
+ end
11
+
12
+ attr_accessor :apikey, :secret, :options
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module Dummy
2
+ class Client
3
+ module Database
4
+ def db
5
+ Dummy::Database.new(@api)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Dummy
2
+ class Database < Driver::Model
3
+ def create(name)
4
+ @api.create_database(name)
5
+ end
6
+
7
+ def delete(name)
8
+ @api.drop_table(name)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module Dummy
2
+ class Client < Driver::Client
3
+ drive Database
4
+
5
+ def initialize(apikey, secret, options = {})
6
+ @apikey = apikey
7
+ @secret = secret
8
+
9
+ @api = API.new(@apikey, @secret)
10
+ end
11
+
12
+ attr_reader :apikey, :secret
13
+ end
14
+ end
@@ -0,0 +1,2 @@
1
+ require "driver"
2
+ require "dummy/client"
@@ -0,0 +1,84 @@
1
+ require "bundler/setup"
2
+ Bundler.require :default
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), %w(.. lib)))
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), %w(dummy lib)))
7
+
8
+ require 'driver'
9
+ require 'dummy'
10
+ require 'rspec'
11
+
12
+ RSpec.configure do |config|
13
+ # rspec-expectations config goes here. You can use an alternate
14
+ # assertion/expectation library such as wrong or the stdlib/minitest
15
+ # assertions if you prefer.
16
+ config.expect_with :rspec do |expectations|
17
+ # This option will default to `true` in RSpec 4. It makes the `description`
18
+ # and `failure_message` of custom matchers include text for helper methods
19
+ # defined using `chain`, e.g.:
20
+ # be_bigger_than(2).and_smaller_than(4).description
21
+ # # => "be bigger than 2 and smaller than 4"
22
+ # ...rather than:
23
+ # # => "be bigger than 2"
24
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
25
+ end
26
+
27
+ # rspec-mocks config goes here. You can use an alternate test double
28
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
29
+ config.mock_with :rspec do |mocks|
30
+ # Prevents you from mocking or stubbing a method that does not exist on
31
+ # a real object. This is generally recommended, and will default to
32
+ # `true` in RSpec 4.
33
+ mocks.verify_partial_doubles = true
34
+ end
35
+
36
+ # The settings below are suggested to provide a good initial experience
37
+ # with RSpec, but feel free to customize to your heart's content.
38
+ =begin
39
+ # These two settings work together to allow you to limit a spec run
40
+ # to individual examples or groups you care about by tagging them with
41
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
42
+ # get run.
43
+ config.filter_run :focus
44
+ config.run_all_when_everything_filtered = true
45
+
46
+ # Limits the available syntax to the non-monkey patched syntax that is
47
+ # recommended. For more details, see:
48
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
49
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
50
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
51
+ config.disable_monkey_patching!
52
+
53
+ # This setting enables warnings. It's recommended, but in some cases may
54
+ # be too noisy due to issues in dependencies.
55
+ config.warnings = true
56
+
57
+ # Many RSpec users commonly either run the entire suite or an individual
58
+ # file, and it's useful to allow more verbose output when running an
59
+ # individual spec file.
60
+ if config.files_to_run.one?
61
+ # Use the documentation formatter for detailed output,
62
+ # unless a formatter has already been configured
63
+ # (e.g. via a command-line flag).
64
+ config.default_formatter = 'doc'
65
+ end
66
+
67
+ # Print the 10 slowest examples and example groups at the
68
+ # end of the spec run, to help surface which specs are running
69
+ # particularly slow.
70
+ config.profile_examples = 10
71
+
72
+ # Run specs in random order to surface order dependencies. If you find an
73
+ # order dependency and want to debug it, you can fix the order by providing
74
+ # the seed, which is printed after each run.
75
+ # --seed 1234
76
+ config.order = :random
77
+
78
+ # Seed global randomization in this process using the `--seed` CLI option.
79
+ # Setting this allows you to use `--seed` to deterministically reproduce
80
+ # test failures related to randomization by passing the same `--seed` value
81
+ # as the one that triggered the failure.
82
+ Kernel.srand config.seed
83
+ =end
84
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: driver
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - hiro-su
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Simple Framework for API Client.
70
+ email:
71
+ - h.sugipon@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - APIClient.png
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - driver.gemspec
84
+ - lib/driver.rb
85
+ - lib/driver/api.rb
86
+ - lib/driver/client.rb
87
+ - lib/driver/model.rb
88
+ - spec/driver_spec.rb
89
+ - spec/dummy/bin/dummy
90
+ - spec/dummy/lib/dummy.rb
91
+ - spec/dummy/lib/dummy/client.rb
92
+ - spec/dummy/lib/dummy/client/api.rb
93
+ - spec/dummy/lib/dummy/client/api/database.rb
94
+ - spec/dummy/lib/dummy/client/api/table.rb
95
+ - spec/dummy/lib/dummy/client/database.rb
96
+ - spec/dummy/lib/dummy/client/model/database.rb
97
+ - spec/spec_helper.rb
98
+ homepage: https://github.com/hiro-su/driver
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.5
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Simple Framework for API Client.
122
+ test_files:
123
+ - spec/driver_spec.rb
124
+ - spec/dummy/bin/dummy
125
+ - spec/dummy/lib/dummy.rb
126
+ - spec/dummy/lib/dummy/client.rb
127
+ - spec/dummy/lib/dummy/client/api.rb
128
+ - spec/dummy/lib/dummy/client/api/database.rb
129
+ - spec/dummy/lib/dummy/client/api/table.rb
130
+ - spec/dummy/lib/dummy/client/database.rb
131
+ - spec/dummy/lib/dummy/client/model/database.rb
132
+ - spec/spec_helper.rb
133
+ has_rdoc: