flex_trans 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/flex_trans.gemspec +41 -0
- data/lib/flex_trans.rb +6 -0
- data/lib/flex_trans/mapper.rb +46 -0
- data/lib/flex_trans/pool.rb +14 -0
- data/lib/flex_trans/struct.rb +36 -0
- data/lib/flex_trans/version.rb +3 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ec16a269e9a60d98a126b4a7b53ab3d5450892cb860ca15e158278438bc666d0
|
4
|
+
data.tar.gz: 71d97b17d05d4b39997de297fc02787d5a41366e4ef8b77d1957d205dbbfa579
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3e388b665fec7744eac246479eaf58915457f754f468e4dc1328a57556184d82cca573a3c357cfb33bf896eb3d6720a5cd816b16e84895fcb9196e0d5e16625f
|
7
|
+
data.tar.gz: 4bc8bef22882a9e3d4d5f79cfed168273fd30f042b14ca0849c0ad90d8bd8c8d6488c8d60c2093f28c0fc119b66f1887e036d1422011df5361da99f28797a06f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# FlexTrans
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/flex_trans`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'flex_trans'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install flex_trans
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/flex_trans.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "flex_trans"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/flex_trans.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "flex_trans/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "flex_trans"
|
8
|
+
spec.version = FlexTrans::VERSION
|
9
|
+
spec.authors = ["Akira SUENAMI"]
|
10
|
+
spec.email = ["a.suenami@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Flexible object pool with Ruby.}
|
13
|
+
spec.description = %q{You can implement the lightweight, flexible, and simple object pool by flex_trans. This library is one of solutions for impedance mismatch.}
|
14
|
+
spec.homepage = "https://github.com/a-suenami/flex_trans"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
20
|
+
|
21
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
22
|
+
spec.metadata["source_code_uri"] = "https://github.com/a-suenami/flex_trans"
|
23
|
+
spec.metadata["changelog_uri"] = "https://github.com/a-suenami/flex_trans/README.md"
|
24
|
+
else
|
25
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
26
|
+
"public gem pushes."
|
27
|
+
end
|
28
|
+
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
31
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
end
|
34
|
+
spec.bindir = "exe"
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ["lib"]
|
37
|
+
|
38
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
39
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
40
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
41
|
+
end
|
data/lib/flex_trans.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'flex_trans/struct'
|
2
|
+
|
3
|
+
module FlexTrans
|
4
|
+
class Mapper
|
5
|
+
class << self
|
6
|
+
def mapping_attributes(*mapping_attributes)
|
7
|
+
new(mapping_attributes: mapping_attributes)
|
8
|
+
end
|
9
|
+
|
10
|
+
def mapping_type(mapping_type)
|
11
|
+
new(mapping_type: mapping_type)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(mapping_attributes: [], mapping_type: nil)
|
16
|
+
@mapping_attributes = mapping_attributes
|
17
|
+
@mapping_type = mapping_type
|
18
|
+
end
|
19
|
+
|
20
|
+
def mapping_attributes(*mapping_attributes)
|
21
|
+
new_attribues = (@mapping_attributes + mapping_attributes).uniq
|
22
|
+
self.class.new(mapping_attributes: new_attribues, mapping_type: @mapping_type)
|
23
|
+
end
|
24
|
+
|
25
|
+
def mapping_type(mapping_type)
|
26
|
+
self.class.new(mapping_attributes: @mapping_attributes, mapping_type: mapping_type)
|
27
|
+
end
|
28
|
+
|
29
|
+
def map(relation, limit: nil)
|
30
|
+
# Just fake it
|
31
|
+
[current_mapping_type.new(id: 1, name: 'Akira Suenami')]
|
32
|
+
|
33
|
+
# relation.limit(limit).pluck(attributes).map do |record|
|
34
|
+
# mapping_type.new(record)
|
35
|
+
# end
|
36
|
+
end
|
37
|
+
|
38
|
+
def current_mapping_type
|
39
|
+
@mapping_type || FlexTrans::Struct.new(*current_mapping_attributes)
|
40
|
+
end
|
41
|
+
|
42
|
+
def current_mapping_attributes
|
43
|
+
@mapping_attributes
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module FlexTrans
|
2
|
+
module Struct
|
3
|
+
def self.new(*args, &block)
|
4
|
+
klass = Class.new do
|
5
|
+
@@attributes = []
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def set_attrributes(*attributes)
|
9
|
+
@@attributes ||= []
|
10
|
+
@@attributes.concat(attributes)
|
11
|
+
attr_reader(*attributes)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
set_attrributes(*args)
|
16
|
+
|
17
|
+
def initialize(attributes)
|
18
|
+
shortage_attributes = @@attributes - attributes.keys
|
19
|
+
if shortage_attributes.any?
|
20
|
+
raise ArgumentError, "Some attributes doesn't given: #{shortage_attributes}"
|
21
|
+
end
|
22
|
+
|
23
|
+
attributes.each do |name, value|
|
24
|
+
instance_variable_set(:"@#{name}", value)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if block_given?
|
30
|
+
klass.class_eval(&block)
|
31
|
+
end
|
32
|
+
|
33
|
+
klass
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flex_trans
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Akira SUENAMI
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: You can implement the lightweight, flexible, and simple object pool by
|
56
|
+
flex_trans. This library is one of solutions for impedance mismatch.
|
57
|
+
email:
|
58
|
+
- a.suenami@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- flex_trans.gemspec
|
72
|
+
- lib/flex_trans.rb
|
73
|
+
- lib/flex_trans/mapper.rb
|
74
|
+
- lib/flex_trans/pool.rb
|
75
|
+
- lib/flex_trans/struct.rb
|
76
|
+
- lib/flex_trans/version.rb
|
77
|
+
homepage: https://github.com/a-suenami/flex_trans
|
78
|
+
licenses: []
|
79
|
+
metadata:
|
80
|
+
allowed_push_host: https://rubygems.org/
|
81
|
+
homepage_uri: https://github.com/a-suenami/flex_trans
|
82
|
+
source_code_uri: https://github.com/a-suenami/flex_trans
|
83
|
+
changelog_uri: https://github.com/a-suenami/flex_trans/README.md
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.7.6
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Flexible object pool with Ruby.
|
104
|
+
test_files: []
|