rtfs 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  pkg/*
2
2
  .DS_Store
3
+ *.gem
@@ -0,0 +1,8 @@
1
+ ## 0.1.0 / 2012-04-25
2
+
3
+ * Add WebService interface.
4
+ * Api changed, `RTFS::Client.new` need change as `RTFS::Client.tfs` .
5
+
6
+ ## 0.0.1 / 2011-08-02
7
+
8
+ * Birthday!
@@ -0,0 +1,85 @@
1
+ RTFS
2
+ ====
3
+
4
+ RTFS is a Ruby Client for TFS.
5
+
6
+ [About TFS](http://code.taobao.org/project/view/366/)
7
+
8
+ This is basicly library for TFS access, you can use [carrierwave-tfs](http://github.com/huacnlee/carrierwave-tfs) for Carrierwave.
9
+
10
+ Requirements
11
+ ------------
12
+
13
+ * Linux System (TFS only success build in Linux system.)
14
+ * TFS
15
+
16
+ INSTALL
17
+ -------
18
+
19
+ ```bash
20
+ $ gem install rtfs
21
+ ```
22
+
23
+ Configure
24
+ ---------
25
+
26
+ create this files before using.
27
+
28
+ config/tfs.yml
29
+
30
+ ```yaml
31
+ defaults: &defaults
32
+ host: '127.0.0.1:3100'
33
+ # or use WebService
34
+ host: 'http://127.0.0.1:3900'
35
+ appkey: "......."
36
+
37
+ development:
38
+ <<: *defaults
39
+
40
+ test:
41
+ <<: *defaults
42
+
43
+ production:
44
+ <<: *defaults
45
+ ```
46
+
47
+ config/initialize/tfs.rb
48
+
49
+ ```ruby
50
+ require 'rtfs'
51
+ tfs_config = YAML.load_file("#{Rails.root}/config/tfs.yml")[Rails.env]
52
+ $tfs = RTFS::Client.tfs(tfs_config.merge({:ns_addr => tfs_config['host']}))
53
+ ```
54
+
55
+ :ns_addr include http:// tfs used webservice
56
+
57
+
58
+ Usage
59
+ -----
60
+
61
+ ```ruby
62
+ class UsersController < ApplicationController
63
+ def save
64
+ @user = User.new
65
+ ext = File.extname(params[:Filedata].original_filename)
66
+ file_name = $tfs.put(params[:Filedata].tempfile.path, :ext => ext)
67
+ @user.avatar_path = [file_name,ext].join("")
68
+ end
69
+ end
70
+
71
+
72
+ class User < ActiveRecord::Base
73
+ def avatar_url
74
+ server_id = self.id % 4 + 1
75
+ "http://img#{server_id}.tbcdn.com/#{self.avatar_path}"
76
+ end
77
+ end
78
+ ```
79
+
80
+ Put local file to TFS
81
+
82
+ ```bash
83
+ irb> $tfs.put("~/Downloads/a.jpg")
84
+ T1Ub1XXeFBXXb1upjX
85
+ RTFS
@@ -1,8 +1,6 @@
1
+ # coding: utf-8
1
2
  # TFS Client for Ruby
2
3
  # by nowa<nowazhu@gmail.com> 2011-07-23
3
-
4
- #!/usr/local/bin/ruby
5
-
6
4
  $:.unshift(File.dirname(__FILE__))
7
5
 
8
6
  module RTFS; end
@@ -1,9 +1,10 @@
1
+ # coding: utf-8
1
2
  # Code for client
2
3
  # by nowa<nowazhu@gmail.com> 2011-07-23
3
4
  module RTFS
4
5
 
5
6
  class Client
6
-
7
+
7
8
  # 参数:
8
9
  # :ns_addr TFS 服务器地址,如 127.0.0.1:3100
9
10
  # :tfstool_path tfstool 安装路径,默认 /home/admin/tfs/bin/tfstool
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # meta.rb contains <tt>Top4R::Meta</tt> and related classes that
2
3
  # help define the metadata of the <tt>Top4R</tt> project.
3
4
 
@@ -20,24 +21,24 @@ class RTFS::Meta #:nodoc:
20
21
  s = ryaml.result(binding)
21
22
  YAML.load(s)
22
23
  end
23
-
24
+
24
25
  # Returns RubyGems spec information
25
26
  def spec_info
26
27
  self.pkg_info['spec'] if self.pkg_info
27
28
  end
28
-
29
+
29
30
  # Returns list of project files
30
31
  def project_files
31
32
  @project_files ||= Dir.glob(File.join(@root_dir, 'lib/**/*.rb'))
32
33
  @project_files
33
34
  end
34
-
35
+
35
36
  # Returns list of specification files
36
37
  def spec_files
37
38
  @spec_files ||= Dir.glob(File.join(@root_dir, 'spec/**/*_spec.rb'))
38
39
  @spec_files
39
40
  end
40
-
41
+
41
42
  # Returns RubyGem specification for Top4R project
42
43
  def gem_spec
43
44
  @gem_spec ||= Gem::Specification.new do |spec|
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  module RTFS
2
3
 
3
4
  TFSTOOL_PATH = "/home/admin/tfs/bin/tfstool"
@@ -5,7 +6,7 @@ module RTFS
5
6
 
6
7
  attr_accessor :ns_addr
7
8
  attr_accessor :tfstool_path
8
-
9
+
9
10
  # 参数:
10
11
  # :ns_addr TFS 服务器地址,如 127.0.0.1:3100
11
12
  # :tfstool_path tfstool 安装路径,默认 /home/admin/tfs/bin/tfstool
@@ -13,18 +14,18 @@ module RTFS
13
14
  return nil unless options
14
15
  @ns_addr = options[:ns_addr]
15
16
  @tfstool_path = options[:tfstool_path] ? options[:tfstool_path] : TFSTOOL_PATH
16
- if not File.exist?(@tfstool_path)
17
- puts "[RTFS] debuger: #{@tfstool_path}"
17
+ if not File.exist?(@tfstool_path)
18
+ puts "[RTFS] debuger: #{@tfstool_path}"
18
19
  raise NoTFSToolError.new
19
- end
20
+ end
20
21
  end
21
-
22
+
22
23
  # 获取文件
23
24
  def get(tfs_name, local_file=nil)
24
25
  local_file ||= tfs_name
25
26
  `#{tfstool_cmd} -i "get #{tfs_name} #{local_file}"`
26
27
  end
27
-
28
+
28
29
  # 上传文件
29
30
  # 参数:
30
31
  # file_path 需要上传的文件路径
@@ -36,7 +37,7 @@ module RTFS
36
37
  tfs_name = "NULL"
37
38
  result = `#{tfstool_cmd} -i "put #{file_path} #{tfs_name} #{ext}"`
38
39
  # puts "result: #{result}"
39
- t = nil
40
+ t = nil
40
41
  if result.include?("=> ")
41
42
  result = result.split("=> ").last
42
43
  if result.include?(",")
@@ -45,24 +46,24 @@ module RTFS
45
46
  end
46
47
  t.nil? ? nil : t
47
48
  end
48
-
49
+
49
50
  # 上传文件 并返回完整 url (only for Taobao)
50
51
  def put_and_get_url(file_path, options = {})
51
52
  ext = options[:ext] || File.extname(file_path)
52
53
  t = put(file_path, :ext => ext)
53
54
  t.nil? ? nil : "http://img03.taobaocdn.com/tfscom/#{t}#{ext}"
54
55
  end
55
-
56
+
56
57
  # 删除文件, 不能带扩展名
57
58
  def rm(tfs_name)
58
59
  `#{tfstool_cmd} -i "rm #{tfs_name}"`
59
60
  end
60
-
61
+
61
62
  # 改名, 不能带扩展名
62
63
  def rename(tfs_name, new_name)
63
64
  `#{tfstool_cmd} -i "rename #{tfs_name} #{new_name}"`
64
65
  end
65
-
66
+
66
67
  # 文件信息查看, 不能带扩展名
67
68
  def stat(tfs_name)
68
69
  result = `#{tfstool_cmd} -i "stat #{tfs_name}"`
@@ -73,17 +74,16 @@ module RTFS
73
74
  end
74
75
  stat
75
76
  end
76
-
77
+
77
78
  protected
78
79
  def tfstool_cmd
79
80
  "#{@tfstool_path} -n -s #{@ns_addr}"
80
81
  end
81
82
  end
82
-
83
+
83
84
  class NoTFSToolError < RuntimeError
84
85
  def to_s
85
86
  "You must install tfs from yum or source first!"
86
87
  end
87
88
  end # NoTFSToolError
88
-
89
89
  end
@@ -1,11 +1,12 @@
1
+ # coding: utf-8
1
2
  # Version for RTFS
2
3
  # by nowa<nowazhu@gmail.com> 2011-07-23
3
4
 
4
5
  module RTFS::Version
5
- MAJOR = 0
6
- MINOR = 0
7
- REVISION = 4
8
-
6
+ MAJOR = 0
7
+ MINOR = 1
8
+ REVISION = 1
9
+
9
10
  class << self
10
11
  # Returns X.Y.Z formatted version string
11
12
  def to_version
@@ -1,24 +1,31 @@
1
- # encoding utf-8
1
+ # coding: utf-8
2
2
  require 'rest-client'
3
+ require 'open-uri'
3
4
  require "json"
4
5
 
5
6
  module RTFS
6
7
  class WebService
7
8
 
8
9
  attr_accessor :appkey
9
- attr_accessor :ns_addr
10
+ attr_accessor :ns_addrs
10
11
 
11
12
  def initialize(options)
12
13
  return nil unless options
13
- @ns_addr = options[:ns_addr]
14
- @appkey = options[:appkey]
14
+ # 通过 ns_addr 的地址获取负载均衡的地址
15
+ @ns_addrs ||= open("#{options[:ns_addr]}/tfs.list").read.split("\n")
16
+ @appkey = options[:appkey]
15
17
  end
16
-
18
+
19
+ # 随机取一个 ns_addr 用于访问
20
+ def ns_addr
21
+ @ns_addrs[rand(@ns_addrs.size)]
22
+ end
23
+
17
24
  # 获取文件
18
25
  def get(tfs_name, local_file=nil)
19
26
  RestClient.get(get_url("/v1/#{appkey}/#{tfs_name}"))
20
27
  end
21
-
28
+
22
29
  # 上传文件
23
30
  # 参数:
24
31
  # file_path 需要上传的文件路径
@@ -26,35 +33,34 @@ module RTFS
26
33
  # 返回值
27
34
  # T1lpVcXftHXXaCwpjX
28
35
  def put(file_path, options = {})
29
- ext = options[:ext] || File.extname(file_path)
30
- response = RestClient.post(get_url("/v1/#{appkey}",{:suffix => ext, :simple_name => options[:simple_name] || 0}),File.open(file_path).read, :accept => :json )
31
- json = JSON.parse(response)
32
- json && json["TFS_FILE_NAME"] ? json["TFS_FILE_NAME"] : nil
33
-
36
+ ext = options[:ext] || File.extname(file_path)
37
+ response = RestClient.post(get_url("/v1/#{appkey}",{:suffix => ext, :simple_name => options[:simple_name] || 0}),File.open(file_path).read, :accept => :json )
38
+ json = JSON.parse(response)
39
+ json && json["TFS_FILE_NAME"] ? json["TFS_FILE_NAME"] : nil
34
40
  end
35
-
41
+
36
42
  # 上传文件 并返回完整 url (only for Taobao)
37
43
  def put_and_get_url(file_path, options = {})
38
- ext = options[:ext] || File.extname(file_path)
39
- t = put(file_path, :ext => ext)
40
- t.nil? ? nil : "http://img0#{rand(4)+1}.taobaocdn.com/tfscom/#{t}#{ext}"
44
+ ext = options[:ext] || File.extname(file_path)
45
+ t = put(file_path, :ext => ext)
46
+ t.nil? ? nil : "http://img0#{rand(4)+1}.taobaocdn.com/tfscom/#{t}#{ext}"
41
47
  end
42
-
48
+
43
49
  # 删除文件, 不能带扩展名
44
50
  def rm(tfs_name,options = {})
45
- response = RestClient.delete(get_url("/v1/#{appkey}/#{tfs_name}", options))
46
- response && response.code == 200 ? true : nil
51
+ response = RestClient.delete(get_url("/v1/#{appkey}/#{tfs_name}", options))
52
+ response && response.code == 200 ? true : nil
47
53
  end
48
-
54
+
49
55
  # 改名, 不能带扩展名
50
56
  def rename(tfs_name, new_name)
51
57
  #`#{tfstool_cmd} -i "rename #{tfs_name} #{new_name}"`
52
58
  end
53
-
59
+
54
60
  # 文件信息查看, 不能带扩展名
55
61
  def stat(tfs_name,options = {})
56
- response = RestClient.get(get_url("/v1/#{appkey}/metadata/#{tfs_name}", options))
57
- response && response.code == 200 ? JSON.parse(response) : nil
62
+ response = RestClient.get(get_url("/v1/#{appkey}/metadata/#{tfs_name}", options))
63
+ response && response.code == 200 ? JSON.parse(response) : nil
58
64
  end
59
65
 
60
66
  def client_name
@@ -63,20 +69,18 @@ module RTFS
63
69
 
64
70
  private
65
71
 
66
-
67
72
  def appkey
68
- @appkey
73
+ @appkey
69
74
  end
70
75
 
71
76
  def get_url(url,opts = {})
72
- return url unless opts
73
- url = "#{@ns_addr}#{url}"
74
- params = []
75
- opts.each{|k,v|
76
- params << "#{k}=#{v}"
77
- }
78
- url.include?("?") ? "#{url}&#{params.join("&")}" : "#{url}?#{params.join("&")}"
77
+ return url unless opts
78
+ url = "#{self.ns_addr}#{url}"
79
+ params = []
80
+ opts.each{ |k,v|
81
+ params << "#{k}=#{v}"
82
+ }
83
+ url.include?("?") ? "#{url}&#{params.join("&")}" : "#{url}?#{params.join("&")}"
79
84
  end
80
-
81
85
  end
82
86
  end
@@ -1,6 +1,7 @@
1
- # ʹ��ffi��nice-ffi�����ö�̬���c�ӿ�
2
- # tfsclient c apiĿǰ�в����ƣ�����c�ӿڵķ�װ���ò�����������
3
- # ���Ŀǰ��ʹ�ø�wrapper���ļ��ݴ�
1
+ # coding: utf-8
2
+ # 使用ffi和nice-ffi来调用动态库的c接口
3
+ # tfsclient c api目前尚不完善,基于c接口的封装调用不能满足需求
4
+ # 因此目前不使用该wrapper,文件暂存
4
5
  # by nowa<nowazhu@gmail.com> 2011-07-23
5
6
 
6
7
  module LibC
@@ -14,7 +15,7 @@ module LibC
14
15
  # memory allocators
15
16
  attach_function :malloc, [:size_t], :pointer
16
17
  attach_function :free, [:pointer], :void
17
-
18
+
18
19
  # get a pointer to the free function; used for ZMQ::Message deallocation
19
20
  Free = library.find_symbol('free')
20
21
 
@@ -27,11 +28,11 @@ module LibRTFS
27
28
 
28
29
  libs_dir = "/home/admin/tfs/lib/"
29
30
  pathset = NiceFFI::PathSet::DEFAULT.prepend(libs_dir)
30
-
31
+
31
32
  load_library("tfsclient_c", pathset)
32
33
 
33
34
  attach_function :t_initialize, [:string, :int, :int], :int
34
-
35
+
35
36
  #enum OpenFlag
36
37
  # {
37
38
  # T_READ = 1,
@@ -41,7 +42,7 @@ module LibRTFS
41
42
  # T_NOLEASE = 16,
42
43
  # T_STAT = 32,
43
44
  # T_LARGE = 64
44
- # };
45
+ # };
45
46
  attach_function :t_open, [:string, :string, :string, :int, :string], :int
46
47
  attach_function :t_read, [:int, :pointer, :int], :int
47
48
  attach_function :t_write, [:int, :pointer, :int], :int
@@ -51,13 +52,13 @@ module LibRTFS
51
52
  attach_function :t_fstat, [:int, :pointer, :int], :int
52
53
  attach_function :t_close, [:int, :string, :int], :int
53
54
  attach_function :t_unlink, [:string, :string, :int], :int
54
- end
55
+ end
55
56
 
56
- # �����ⲿ�ִ����������LibRTFS
57
+ # 下面这部分代码仅供测试LibRTFS
57
58
  # LibRTFS.t_initialize("10.232.35.32:3100", 5, 1000)
58
59
  # fd = LibRTFS.t_open("test", ".png", nil, 2, nil)
59
60
  # puts "fd: #{fd}"
60
- #
61
+ #
61
62
  # ori_file = nil
62
63
  # File.open("/home/xifeng/1.png", "r") do |f|
63
64
  # ori_file = f.read
@@ -1,18 +1,19 @@
1
- # Generated: Sun Oct 09 04:07:05 UTC 2011
1
+ # coding: utf-8
2
2
  Gem::Specification.new do |s|
3
- s.name = "rtfs"
4
- s.version = "0.1.0"
5
- s.platform = Gem::Platform::RUBY
6
- s.has_rdoc = true
7
- s.extra_rdoc_files = ["README.markdown","CHANGES","MIT-LICENSE",]
8
- s.summary = "RTFS is a Ruby Client for TFS."
9
- s.author = "Nowa Zhu"
10
- s.email = "nowazhu@gmail.com"
11
- s.homepage = "https://github.com/nowa/rtfs"
3
+ s.name = "rtfs"
4
+ s.version = "0.1.1"
5
+ s.platform = Gem::Platform::RUBY
6
+ s.has_rdoc = true
7
+ s.extra_rdoc_files = ["README.md","CHANGES.md","MIT-LICENSE",]
8
+ s.summary = "RTFS is a Ruby Client for TFS."
9
+ s.author = ["Nowa Zhu","Jason Lee","Cricy"]
10
+ s.email = ["nowazhu@gmail.com","huacnlee@gmail.com","feiyelanghai@gmail.com"]
11
+ s.homepage = "https://github.com/nowa/rtfs"
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.require_paths = ["lib"]
15
+ s.bindir = 'bin'
16
+
12
17
  s.add_dependency("nice-ffi", ">=0.4")
13
18
  s.add_dependency("rest-client", ">=1.6.0")
14
- s.files = `git ls-files`.split("\n")
15
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.require_paths = ["lib"]
17
- s.bindir = 'bin'
18
19
  end
Binary file
Binary file
@@ -0,0 +1,3 @@
1
+ require "rtfs"
2
+
3
+ $tfs = RTFS::Client.tfs(:ns_addr => "http://10.232.4.44:3800", :appkey => '4f8fbb734d4d8')
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+ require "open-uri"
3
+
4
+ describe "Base upload" do
5
+ it "should upload" do
6
+ fname = $tfs.put("spec/a.jpg")
7
+ f = open("http://10.232.4.42/tfscom/#{fname}.jpg")
8
+ f.read.length.should == 6153
9
+
10
+ fname = $tfs.put("spec/b.jpg")
11
+ f = open("http://10.232.4.42/tfscom/#{fname}.jpg")
12
+ f.read.length.should == 114504
13
+ end
14
+ end
metadata CHANGED
@@ -1,19 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nowa Zhu
9
+ - Jason Lee
10
+ - Cricy
9
11
  autorequire:
10
12
  bindir: bin
11
13
  cert_chain: []
12
- date: 2012-04-26 00:00:00.000000000Z
14
+ date: 2012-06-20 00:00:00.000000000 Z
13
15
  dependencies:
14
16
  - !ruby/object:Gem::Dependency
15
17
  name: nice-ffi
16
- requirement: &2168210780 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
17
19
  none: false
18
20
  requirements:
19
21
  - - ! '>='
@@ -21,10 +23,15 @@ dependencies:
21
23
  version: '0.4'
22
24
  type: :runtime
23
25
  prerelease: false
24
- version_requirements: *2168210780
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0.4'
25
32
  - !ruby/object:Gem::Dependency
26
33
  name: rest-client
27
- requirement: &2168210300 !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
28
35
  none: false
29
36
  requirements:
30
37
  - - ! '>='
@@ -32,22 +39,28 @@ dependencies:
32
39
  version: 1.6.0
33
40
  type: :runtime
34
41
  prerelease: false
35
- version_requirements: *2168210300
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.6.0
36
48
  description:
37
- email: nowazhu@gmail.com
49
+ email:
50
+ - nowazhu@gmail.com
51
+ - huacnlee@gmail.com
52
+ - feiyelanghai@gmail.com
38
53
  executables: []
39
54
  extensions: []
40
55
  extra_rdoc_files:
41
- - README.markdown
42
- - CHANGES
56
+ - README.md
57
+ - CHANGES.md
43
58
  - MIT-LICENSE
44
59
  files:
45
60
  - .gitignore
46
- - CHANGES
61
+ - CHANGES.md
47
62
  - MIT-LICENSE
48
- - README.markdown
49
- - Rakefile
50
- - config/templates/github.gemspec.erb
63
+ - README.md
51
64
  - lib/rtfs.rb
52
65
  - lib/rtfs/client.rb
53
66
  - lib/rtfs/meta.rb
@@ -55,10 +68,11 @@ files:
55
68
  - lib/rtfs/version.rb
56
69
  - lib/rtfs/web_service.rb
57
70
  - lib/rtfs/wrapper.rb
58
- - pkg-info.yml
59
71
  - rtfs.gemspec
60
- - spec/spec.opts
61
- - tasks/pkg.rake
72
+ - spec/a.jpg
73
+ - spec/b.jpg
74
+ - spec/spec_helper.rb
75
+ - spec/upload_spec.rb
62
76
  homepage: https://github.com/nowa/rtfs
63
77
  licenses: []
64
78
  post_install_message:
@@ -79,9 +93,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
93
  version: '0'
80
94
  requirements: []
81
95
  rubyforge_project:
82
- rubygems_version: 1.8.10
96
+ rubygems_version: 1.8.24
83
97
  signing_key:
84
98
  specification_version: 3
85
99
  summary: RTFS is a Ruby Client for TFS.
86
100
  test_files:
87
- - spec/spec.opts
101
+ - spec/a.jpg
102
+ - spec/b.jpg
103
+ - spec/spec_helper.rb
104
+ - spec/upload_spec.rb
data/CHANGES DELETED
@@ -1,9 +0,0 @@
1
- === 0.1.0 / 2012-04-25
2
-
3
- * ����webservice��ʽ
4
- * Client.new��ʽ�ij�Client.tfs
5
-
6
- === 0.0.1 / 2011-08-02
7
-
8
- * Birthday!
9
- * �˰汾�ǵ���tfstoolʵ���ļ���tfs�IJ�������������Ӧ�õ���tfsclient��̬���c�ӿ�ʵ��
@@ -1,126 +0,0 @@
1
- RTFS
2
- ====
3
-
4
- RTFS is a Ruby Client for TFS.
5
-
6
- [About TFS](http://code.taobao.org/project/view/366/)
7
-
8
- Requirements
9
- ------------
10
-
11
- * Linux System (TFS only success build in Linux system.)
12
- * TFS
13
-
14
- Configure
15
- ---------
16
-
17
- create this files before using.
18
-
19
- config/tfs.yml
20
-
21
- defaults: &defaults
22
- host: '127.0.0.1:3100'
23
- appkey: "......."
24
-
25
- development:
26
- <<: *defaults
27
-
28
- test:
29
- <<: *defaults
30
-
31
- production:
32
- <<: *defaults
33
-
34
- config/initialize/tfs.rb
35
-
36
- require 'rtfs'
37
- tfs_config = YAML.load_file("#{Rails.root}/config/tfs.yml")[Rails.env]
38
- $tfs = RTFS::Client.tfs(tfs_config.merge({:ns_addr => tfs_config['host']}))
39
-
40
- :ns_addr include http:// tfs used webservice
41
-
42
- Configure without TFS install
43
- -----------------------------
44
-
45
- If you development environment is Mac, or your developemnt environment not install TFS, you need use this file to hack upload file as FileSystem.
46
-
47
- lib/fake_tfs.rb
48
-
49
- module FakeTfs
50
- class Client
51
- def initialize(options = {})
52
- @ns_addr = options[:ns_addr] || "uploads/tfs/"
53
- if @ns_addr[0] != "/"
54
- @ns_addr = [Rails.root,"public",@ns_addr].join("/")
55
- end
56
- end
57
-
58
- def put_file(file_path, options = {})
59
- ext = options[:ext] || File.extname(file_path)
60
- ext = ".jpg" if ext.blank?
61
- file_name = [Digest::SHA1.hexdigest(file_path),ext].join("")
62
-
63
- new_path = [@ns_addr,file_name].join("/")
64
-
65
- FileUtils.cp(file_path, new_path)
66
- File.basename(new_path)
67
- end
68
-
69
- def rm_file(file_id)
70
- puts "FakeTFS: removing #{file_id}\n"
71
- Dir.glob(File.join(@ns_addr, "#{file_id}.*"))[0]
72
- end
73
- end
74
- end
75
-
76
-
77
- config/tfs.yml
78
-
79
- defaults: &defaults
80
- host: 'uploads/tfs/'
81
-
82
- development:
83
- <<: *defaults
84
-
85
- test:
86
- <<: *defaults
87
-
88
- production:
89
- <<: *defaults
90
- host: '127.0.0.1:3100'
91
-
92
- config/initialize/tfs.rb
93
-
94
- tfs_config = YAML.load_file("#{Rails.root}/config/tfs.yml")[Rails.env]
95
- if Rails.env == "development"
96
- $tfs = FakeTfs::Client.new(:ns_addr => tfs_config['host'])
97
- else
98
- require 'rtfs'
99
- $tfs = RTFS::Client.tfs(tfs_config.merge({:ns_addr => tfs_config['host']}))
100
- end
101
-
102
-
103
- Usage
104
- -----
105
-
106
- class UsersController < ApplicationController
107
- def save
108
- @user = User.new
109
- ext = File.extname(params[:Filedata].original_filename)
110
- file_name = $tfs.put(params[:Filedata].tempfile.path, :ext => ext)
111
- @user.avatar_path = [file_name,ext].join("")
112
- end
113
- end
114
-
115
-
116
- class User < ActiveRecord::Base
117
- def avatar_url
118
- server_id = self.id % 4 + 1
119
- "http://img#{server_id}.tbcdn.com/#{self.avatar_path}"
120
- end
121
- end
122
-
123
- Put local file to TFS
124
-
125
- $ $tfs.put("~/Downloads/a.jpg")
126
- T1Ub1XXeFBXXb1upjX
data/Rakefile DELETED
@@ -1,11 +0,0 @@
1
- $:.unshift('lib')
2
-
3
- require 'rubygems'
4
- gem('rspec')
5
-
6
- ROOT_DIR = File.join(File.dirname(__FILE__))
7
-
8
- require 'rake'
9
- require 'rtfs'
10
-
11
- import('tasks/pkg.rake')
@@ -1,18 +0,0 @@
1
- # Generated: <%= Time.now.utc.to_s %>
2
- Gem::Specification.new do |s|
3
- s.name = "<%= spec['name'] %>"
4
- s.version = "<%= spec['version'] %>"
5
- s.platform = Gem::Platform::RUBY
6
- s.has_rdoc = true
7
- s.extra_rdoc_files = [<% spec['extra_rdoc_files'].each do |f| %>"<%= f %>",<% end %>]
8
- s.summary = "<%= spec['summary'] %>"
9
- s.author = "<%= spec['author'] %>"
10
- s.email = "<%= spec['email'] %>"
11
- s.homepage = "<%= spec['homepage'] %>"
12
- s.rubyforge_project = "<%= spec['rubyforge_project'] %>"
13
- <% spec['add_dependency'].each do |gem, version| %>s.add_dependency("<%= gem %>", "<%= version %>")<% end %>
14
- # s.require_path = "<%= spec['require_path'] %>"
15
- s.files = [<% spec['files'].each {|f| %>"<%= f %>",<% } %>]
16
- s.bindir = 'bin'
17
- s.executables = ['top4rsh']
18
- end
@@ -1,27 +0,0 @@
1
- <% require('pathname') %>
2
- spec:
3
- name: rtfs
4
- version: <%= RTFS::Version.to_version %>
5
- summary: RTFS is a Ruby Client for TFS.
6
- require_path: lib
7
- has_rdoc: false
8
- extra_rdoc_files:
9
- - README.markdown
10
- - CHANGES
11
- - MIT-LICENSE
12
- autorequire: rtfs
13
- # bindir: bin
14
- add_dependency:
15
- nice-ffi: >=0.4
16
- requirements:
17
- - Ruby 1.8.7+
18
- # - json gem, version 0.4.3 or higher
19
- # - jcode (for unicode support)
20
- required_ruby_version: >=1.8.7
21
- author: Nowa Zhu
22
- email: nowazhu@gmail.com
23
- homepage: http://rtfs.labs.nowa.me
24
- rubyforge_project: rtfs
25
- files: <% (self.project_files + self.spec_files).each do |file| %>
26
- - <%= Pathname.new(file).relative_path_from(Pathname.new(@root_dir)) %>
27
- <% end %>
@@ -1,6 +0,0 @@
1
- --colour
2
- --format
3
- progress
4
- --loadby
5
- mtime
6
- --reverse
@@ -1,22 +0,0 @@
1
- require 'rake/gempackagetask'
2
-
3
- meta = RTFS::Meta.new(ROOT_DIR)
4
- namespace :package do
5
- desc "Create Gem Packages"
6
- Rake::GemPackageTask.new(meta.gem_spec) do |pkg|
7
- pkg.need_zip = true
8
- pkg.need_tar = true
9
- end
10
- end
11
-
12
- namespace :gemspec do
13
- desc "Create GemSpec"
14
- task :generate do
15
- spec = meta.pkg_info['spec']
16
- rgs = ERB.new(File.read(File.join(ROOT_DIR, 'config', 'templates', 'github.gemspec.erb')), 0)
17
- s = rgs.result(spec.send(:binding))
18
- gs_file = File.join(ROOT_DIR, 'rtfs.gemspec')
19
- File.delete(gs_file) if File.exist?(gs_file)
20
- File.open(gs_file, 'w') {|f| f.write(s); }
21
- end
22
- end