-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
26 changed files
with
738 additions
and
4 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
service_name: travis-pro |
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.vscode | ||
.idea | ||
.DS_Store | ||
coverage |
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 @@ | ||
--require spec_helper |
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,7 @@ | ||
language: ruby | ||
before_install: | ||
- gem install bundler | ||
rvm: | ||
- 2.6.3 | ||
script: | ||
- bundle exec rspec |
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,7 @@ | ||
source 'https://gems.ruby-china.com/' | ||
|
||
group :development, :test do | ||
gem 'rspec' | ||
gem 'simplecov' | ||
gem 'coveralls' | ||
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,51 @@ | ||
GEM | ||
remote: https://gems.ruby-china.com/ | ||
specs: | ||
coveralls (0.7.2) | ||
multi_json (~> 1.3) | ||
rest-client (= 1.6.7) | ||
simplecov (>= 0.7) | ||
term-ansicolor (= 1.2.2) | ||
thor (= 0.18.1) | ||
diff-lcs (1.3) | ||
docile (1.3.2) | ||
json (2.2.0) | ||
mime-types (3.3) | ||
mime-types-data (~> 3.2015) | ||
mime-types-data (3.2019.1009) | ||
multi_json (1.14.1) | ||
rest-client (1.6.7) | ||
mime-types (>= 1.16) | ||
rspec (3.9.0) | ||
rspec-core (~> 3.9.0) | ||
rspec-expectations (~> 3.9.0) | ||
rspec-mocks (~> 3.9.0) | ||
rspec-core (3.9.0) | ||
rspec-support (~> 3.9.0) | ||
rspec-expectations (3.9.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.9.0) | ||
rspec-mocks (3.9.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.9.0) | ||
rspec-support (3.9.0) | ||
simplecov (0.17.1) | ||
docile (~> 1.1) | ||
json (>= 1.8, < 3) | ||
simplecov-html (~> 0.10.0) | ||
simplecov-html (0.10.2) | ||
term-ansicolor (1.2.2) | ||
tins (~> 0.8) | ||
thor (0.18.1) | ||
tins (0.13.2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
coveralls | ||
rspec | ||
simplecov | ||
|
||
BUNDLED WITH | ||
2.0.2 |
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,3 +1,9 @@ | ||
# client-data-adapter | ||
|
||
## TODO | ||
[![Build Status](https://travis-ci.org/jinghua000/client-data-adapter.svg?branch=master)](https://travis-ci.org/jinghua000/client-data-adapter) | ||
[![Gem Version](https://badge.fury.io/rb/client-data-adapter.svg)](https://rubygems.org/gems/client-data-adapter) | ||
[![Coverage Status](https://coveralls.io/repos/github/jinghua000/client-data-adapter/badge.svg?branch=master)](https://coveralls.io/github/jinghua000/client-data-adapter?branch=master) | ||
|
||
## Introduction | ||
|
||
TODO |
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,3 @@ | ||
task :test do | ||
p 123 | ||
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,2 @@ | ||
gem build client-data-adapter.gemspec | ||
gem install client-data-adapter-0.0.1.gem |
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,84 @@ | ||
require_relative '../lib/client-data-adapter' | ||
require_relative 'book_shelf' | ||
require_relative 'category' | ||
|
||
class Book | ||
|
||
include ClientDataAdapter | ||
|
||
define_adapter do | ||
|
||
link_one :book_shelf | ||
link_many :categories | ||
|
||
adapter do | ||
{ | ||
id: id, | ||
title: title, | ||
} | ||
end | ||
|
||
with :full_title do | ||
"<#{title}>" | ||
end | ||
|
||
with :my_awesome_title do | ||
"my_awesome_title" | ||
end | ||
|
||
with :pass1 do |*args| | ||
args << 'pass1' | ||
end | ||
|
||
with :pass2 do |*args| | ||
args << 'pass2' | ||
end | ||
|
||
with :id do | ||
return id if true | ||
# :nocov: | ||
raise 'CODE WILL NOT REACH HERE.' | ||
# :nocov: | ||
end | ||
|
||
end | ||
|
||
attr_accessor :id, :title, :book_shelf_id | ||
|
||
def initialize(**opt) | ||
|
||
self.id = opt[:id] | ||
self.title = opt[:title] | ||
self.book_shelf_id = opt[:book_shelf_id] | ||
|
||
end | ||
|
||
def self.demo | ||
new( | ||
id: 1, | ||
title: 'My Book', | ||
book_shelf_id: 1, | ||
) | ||
end | ||
|
||
def my_title | ||
'my title' | ||
end | ||
|
||
def my_awesome_title | ||
'no no no' | ||
end | ||
|
||
def sub_title(sub) | ||
"#{title}-#{sub}" | ||
end | ||
|
||
def book_shelf | ||
BookShelf.demo | ||
end | ||
|
||
def categories | ||
[Category.new(id: 1, cat: 'one'), Category.new(id: 2, cat: 'two')] | ||
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,46 @@ | ||
require_relative 'library' | ||
|
||
class BookShelf | ||
|
||
include ClientDataAdapter | ||
|
||
define_adapter do | ||
|
||
link_one :library | ||
|
||
adapter do | ||
{ | ||
id: id, | ||
desc: desc, | ||
} | ||
end | ||
|
||
with :other_desc do | ||
'other desc' | ||
end | ||
|
||
end | ||
|
||
attr_accessor :id, :desc, :library_id | ||
|
||
def initialize(**opt) | ||
|
||
self.id = opt[:id] | ||
self.desc = opt[:desc] | ||
self.library_id = opt[:library_id] | ||
|
||
end | ||
|
||
def self.demo | ||
new( | ||
id: 1, | ||
desc: 'my book shelf', | ||
library_id: 1, | ||
) | ||
end | ||
|
||
def library | ||
Library.demo | ||
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,29 @@ | ||
class Category | ||
|
||
include ClientDataAdapter | ||
|
||
define_adapter do | ||
|
||
adapter do | ||
{ | ||
id: id, | ||
cat: cat, | ||
} | ||
end | ||
|
||
end | ||
|
||
attr_accessor :id, :cat | ||
|
||
def initialize(**opt) | ||
|
||
self.id = opt[:id] | ||
self.cat = opt[:cat] | ||
|
||
end | ||
|
||
def summary | ||
'summary' | ||
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,36 @@ | ||
class Library | ||
|
||
include ClientDataAdapter | ||
|
||
define_adapter do | ||
|
||
adapter do | ||
{ | ||
id: id, | ||
size: size, | ||
} | ||
end | ||
|
||
with :welcome do | ||
'welcome' | ||
end | ||
|
||
end | ||
|
||
attr_accessor :id, :size, :city_id | ||
|
||
def initialize(**opt) | ||
|
||
self.id = opt[:id] | ||
self.size = opt[:size] | ||
|
||
end | ||
|
||
def self.demo | ||
new( | ||
id: 1, | ||
size: 'small' | ||
) | ||
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,7 +1,11 @@ | ||
require_relative 'client-data-adapter/class_methods' | ||
require_relative 'client-data-adapter/instance_methods' | ||
|
||
module ClientDataAdapter | ||
|
||
def self.demo | ||
'hello' | ||
def self.included(base) | ||
base.include(ClientDataAdapter::InstanceMethods) | ||
base.extend(ClientDataAdapter::ClassMethods) | ||
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,18 @@ | ||
require_relative 'config' | ||
require_relative 'wrapper' | ||
|
||
module ClientDataAdapter | ||
module ClassMethods | ||
|
||
def define_adapter(&block) | ||
|
||
const_set(ADAPTER_WRAPPER, Class.new(Wrapper)) | ||
|
||
define_method :adapter_wrapper do | ||
@__adapter_wrapper__ ||= self.class.const_get(ADAPTER_WRAPPER).new(self, &block) | ||
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,6 @@ | ||
module ClientDataAdapter | ||
|
||
ADAPTER_WRAPPER = :AdapterWrapper | ||
ADAPTER = :adapter | ||
|
||
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,41 @@ | ||
require_relative 'util' | ||
|
||
module ClientDataAdapter | ||
module InstanceMethods | ||
|
||
def adapter(*args) | ||
|
||
length = args.length | ||
|
||
if length == 0 | ||
adapter_wrapper.__adapter__ | ||
else | ||
adapter_wrapper.__adapter__.merge( | ||
|
||
*args.map do |arg| | ||
if [String, Symbol].include?(arg.class) | ||
__merge_to_adapter__(arg.to_sym, nil) | ||
elsif arg.is_a?(Hash) | ||
arg.map(&method(:__merge_to_adapter__)) | ||
else | ||
raise '[ERROR] Not available arguments type.' | ||
end | ||
end.flatten, | ||
|
||
) | ||
end | ||
end | ||
|
||
private | ||
|
||
def __merge_to_adapter__(key, params) | ||
{}.tap do |hah| | ||
hah["#{key}".to_sym] = | ||
adapter_wrapper.respond_to?(key) ? | ||
adapter_wrapper.public_send(key, *params) : | ||
public_send(key, *params) | ||
end | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.