gyomu_ruby 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -2
- data/HISTORY.md +11 -0
- data/README.md +1 -0
- data/Rakefile +9 -0
- data/gyomu_ruby.gemspec +5 -0
- data/lib/gyomu_ruby.rb +1 -0
- data/lib/gyomu_ruby/amazon_web_service/file_bucket.rb +74 -0
- data/lib/gyomu_ruby/core_ext/integer.rb +1 -0
- data/lib/gyomu_ruby/core_ext/integer/round.rb +9 -0
- data/lib/gyomu_ruby/core_ext/time.rb +0 -1
- data/lib/gyomu_ruby/core_ext/time/biz_year.rb +1 -2
- data/lib/gyomu_ruby/forgery/forgeries/ja_name.rb +4 -4
- data/lib/gyomu_ruby/ordinary_system_development.rb +1 -1
- data/lib/gyomu_ruby/version.rb +1 -1
- data/spec/core_ext/integer_spec.rb +18 -0
- data/spec/core_ext/time_spec.rb +24 -0
- data/spec/spec_helper.rb +1 -0
- metadata +50 -7
data/Gemfile
CHANGED
data/HISTORY.md
ADDED
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# GyomuRuby
|
data/Rakefile
CHANGED
data/gyomu_ruby.gemspec
CHANGED
@@ -16,4 +16,9 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency("activesupport", [">= 3.0"])
|
21
|
+
s.add_dependency("aws-s3", [">= 0"])
|
22
|
+
|
23
|
+
s.add_development_dependency "rspec", [">= 2.0"]
|
19
24
|
end
|
data/lib/gyomu_ruby.rb
CHANGED
@@ -0,0 +1,74 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
module GyomuRuby
|
5
|
+
module AmazonWebService
|
6
|
+
class FileBucket
|
7
|
+
attr_accessor :backend
|
8
|
+
|
9
|
+
extend Forwardable
|
10
|
+
def_delegators :backend, *%w[bucket get delete]
|
11
|
+
|
12
|
+
def initialize(bucket = 'bucket')
|
13
|
+
@backend = Rails.env.production? || Rails.env.staging? ? RichMan.new(bucket) : PoorMan.new(bucket)
|
14
|
+
end
|
15
|
+
|
16
|
+
def put(io)
|
17
|
+
"#{Time.now.strftime('%Y%m%d%H%M')}_#{SecureRandom.hex(5)}".tap do |key|
|
18
|
+
@backend.put(key, io)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class PoorMan
|
23
|
+
require 'fileutils'
|
24
|
+
|
25
|
+
attr_reader :bucket
|
26
|
+
|
27
|
+
def initialize(bucket)
|
28
|
+
@bucket = bucket
|
29
|
+
path = Rails.root.join('tmp', @bucket)
|
30
|
+
FileUtils.mkdir_p path unless FileTest.exist? path
|
31
|
+
end
|
32
|
+
|
33
|
+
def put(key, io)
|
34
|
+
File.open(Rails.root.join('tmp', @bucket, key), 'w:BINARY') {|f| f.write(io.read)}
|
35
|
+
end
|
36
|
+
|
37
|
+
def get(key)
|
38
|
+
File.open(Rails.root.join('tmp', @bucket, key), 'r:BINARY') {|f| f.read }
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete(key)
|
42
|
+
!!FileUtils.rm_r(Rails.root.join('tmp', @bucket, key))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class RichMan
|
47
|
+
require 'aws/s3'
|
48
|
+
|
49
|
+
attr_reader :bucket
|
50
|
+
|
51
|
+
def initialize(bucket)
|
52
|
+
@bucket = bucket
|
53
|
+
::AWS::S3::Bucket.find(@bucket)
|
54
|
+
rescue ::AWS::S3::NoSuchBucket
|
55
|
+
::AWS::S3::Bucket.create(@bucket)
|
56
|
+
end
|
57
|
+
|
58
|
+
def put(key, io)
|
59
|
+
::AWS::S3::S3Object.store(key, io, @bucket)
|
60
|
+
end
|
61
|
+
|
62
|
+
def get(key)
|
63
|
+
::AWS::S3::S3Object.value(key, @bucket) rescue nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def delete(key)
|
67
|
+
::AWS::S3::S3Object.delete(key, @bucket) rescue false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
AWS = AmazonWebService
|
74
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'gyomu_ruby/core_ext/integer/round'
|
@@ -5,7 +5,7 @@ module GyomuRuby
|
|
5
5
|
module BizYear
|
6
6
|
def biz_year(boundary_mon = 4, boundary_day = 1)
|
7
7
|
now = self
|
8
|
-
if (now.month < boundary_mon) || (now.month ==
|
8
|
+
if (now.month < boundary_mon) || (now.month == boundary_mon && now.day < boundary_day)
|
9
9
|
now.year - 1
|
10
10
|
else
|
11
11
|
now.year
|
@@ -24,4 +24,3 @@ module GyomuRuby
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
@@ -19,7 +19,7 @@ class Forgery::JaName < Forgery
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.last_name_with_kana
|
22
|
-
dictionaries[:ja_last_names].
|
22
|
+
dictionaries[:ja_last_names].sample
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.first_name
|
@@ -27,14 +27,14 @@ class Forgery::JaName < Forgery
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.first_name_with_kana
|
30
|
-
[dictionaries[:ja_male_first_names], dictionaries[:ja_female_first_names]].
|
30
|
+
[dictionaries[:ja_male_first_names], dictionaries[:ja_female_first_names]].sample.sample
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.male_first_name_with_kana
|
34
|
-
dictionaries[:ja_male_first_names].
|
34
|
+
dictionaries[:ja_male_first_names].sample
|
35
35
|
end
|
36
36
|
|
37
37
|
def self.female_first_name_with_kana
|
38
|
-
dictionaries[:ja_female_first_names].
|
38
|
+
dictionaries[:ja_female_first_names].sample
|
39
39
|
end
|
40
40
|
end
|
data/lib/gyomu_ruby/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gyomu_ruby/core_ext/integer'
|
3
|
+
|
4
|
+
describe Integer, 'gyomu_ruby extentions' do
|
5
|
+
describe '#ceil' do
|
6
|
+
it { 101.ceil(50).should == 150 }
|
7
|
+
it { 151.ceil(50).should == 200 }
|
8
|
+
it { 121.ceil(3).should == 123 }
|
9
|
+
it { 123.ceil(3).should == 123 }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#floor' do
|
13
|
+
it { 101.floor(50).should == 100 }
|
14
|
+
it { 151.floor(50).should == 150 }
|
15
|
+
it { 121.floor(3).should == 120 }
|
16
|
+
it { 123.floor(3).should == 123 }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gyomu_ruby/core_ext/time'
|
3
|
+
|
4
|
+
describe Time, 'gyomu_ruby extentions' do
|
5
|
+
describe '#biz_year' do
|
6
|
+
context 'default boundary' do
|
7
|
+
specify { Time.local(2011, 4, 1).biz_year.should == 2011 }
|
8
|
+
specify { Time.local(2011,12,31).biz_year.should == 2011 }
|
9
|
+
specify { Time.local(2012, 1, 1).biz_year.should == 2011 }
|
10
|
+
specify { Time.local(2012, 3,31).biz_year.should == 2011 }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'custom boundary at 4/2' do
|
14
|
+
specify { Time.local(2011, 4, 1).biz_year(4, 2).should == 2010 }
|
15
|
+
specify { Time.local(2011, 4, 2).biz_year(4, 2).should == 2011 }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'custom boundary at 3/31' do
|
19
|
+
specify { Time.local(2011, 3,30).biz_year(3, 31).should == 2010 }
|
20
|
+
specify { Time.local(2011, 3,31).biz_year(3, 31).should == 2011 }
|
21
|
+
specify { Time.local(2011, 4, 1).biz_year(3, 31).should == 2011 }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gyomu_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,41 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
|
14
|
-
|
12
|
+
date: 2012-02-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: &70139244869760 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70139244869760
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: aws-s3
|
27
|
+
requirement: &70139244867040 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70139244867040
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70139241111060 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2.0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70139241111060
|
15
47
|
description: GyomuRuby
|
16
48
|
email:
|
17
49
|
- rubyagile@qwik.tky.esm.co.jp
|
@@ -21,9 +53,14 @@ extra_rdoc_files: []
|
|
21
53
|
files:
|
22
54
|
- .gitignore
|
23
55
|
- Gemfile
|
56
|
+
- HISTORY.md
|
57
|
+
- README.md
|
24
58
|
- Rakefile
|
25
59
|
- gyomu_ruby.gemspec
|
26
60
|
- lib/gyomu_ruby.rb
|
61
|
+
- lib/gyomu_ruby/amazon_web_service/file_bucket.rb
|
62
|
+
- lib/gyomu_ruby/core_ext/integer.rb
|
63
|
+
- lib/gyomu_ruby/core_ext/integer/round.rb
|
27
64
|
- lib/gyomu_ruby/core_ext/time.rb
|
28
65
|
- lib/gyomu_ruby/core_ext/time/biz_year.rb
|
29
66
|
- lib/gyomu_ruby/forgery/dictionaries/ja_female_first_names
|
@@ -37,7 +74,9 @@ files:
|
|
37
74
|
- lib/gyomu_ruby/version.rb
|
38
75
|
- masters/ext_tel_numbers.csv
|
39
76
|
- masters/prefectures.csv
|
40
|
-
|
77
|
+
- spec/core_ext/integer_spec.rb
|
78
|
+
- spec/core_ext/time_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
41
80
|
homepage: http://www.esm.co.jp/
|
42
81
|
licenses: []
|
43
82
|
post_install_message:
|
@@ -58,8 +97,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
97
|
version: '0'
|
59
98
|
requirements: []
|
60
99
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.
|
100
|
+
rubygems_version: 1.8.15
|
62
101
|
signing_key:
|
63
102
|
specification_version: 3
|
64
103
|
summary: GyomuRuby
|
65
|
-
test_files:
|
104
|
+
test_files:
|
105
|
+
- spec/core_ext/integer_spec.rb
|
106
|
+
- spec/core_ext/time_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
has_rdoc:
|