Class: RemoteCp::Clipboard

Inherits:
Object
  • Object
show all
Includes:
RightAws
Defined in:
lib/remote_cp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClipboard

Returns a new instance of Clipboard.



14
15
16
17
18
# File 'lib/remote_cp.rb', line 14

def initialize
  connect
  @bucket = @s3.buckets.detect{|a| a.full_name == "RemoteClipboard"}
  @content_object = @bucket.key('content', true)
end

Instance Attribute Details

#content_objectObject

Returns the value of attribute content_object.



12
13
14
# File 'lib/remote_cp.rb', line 12

def content_object
  @content_object
end

#filename_objectObject

Returns the value of attribute filename_object.



12
13
14
# File 'lib/remote_cp.rb', line 12

def filename_object
  @filename_object
end

#type_objectObject

Returns the value of attribute type_object.



12
13
14
# File 'lib/remote_cp.rb', line 12

def type_object
  @type_object
end

Instance Method Details

#bucket_nameObject



60
61
62
# File 'lib/remote_cp.rb', line 60

def bucket_name
  config[:bucket_name] 
end

#configObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/remote_cp.rb', line 24

def config
  config_filename = File.join(ENV["HOME"], ".remote_cp")
  old_filename = File.join(ENV["HOME"], ".remote_cp.yml")
 
  if File.exist?(old_filename)
    puts ".remote_cp.yml configuration file name is depricated. Renaming to .remote_cp"
    File.rename(old_filename, config_filename)
  end

  @config ||= if File.exist?(config_filename)
    conf = Hash.new {|key, val| raise "Missing key #{key} in config file: #{config_filename}"} 
    conf.replace(YAML::load_file(config_filename))
  else
    config = {:access_key_id => "MY_ACCESS_KEY", :secret_access_key => "MY_SECRET", :bucket_name => "MY_BUCKET_NAME"}
    File.open(config_filename, "w") do |f| 
      f << YAML::dump(config)
    end
    File.chmod(0600, config_filename)
    raise "Please setup your .remote_cp.yml config file in your home dir."
  end
end

#connectObject



20
21
22
# File 'lib/remote_cp.rb', line 20

def connect
  @s3 = RightAws::S3.new(config[:access_key_id], config[:secret_access_key], :logger => Logger.new('/dev/null'))
end

#contentObject



68
69
70
# File 'lib/remote_cp.rb', line 68

def content
  @content_object.data
end

#create_obj(key, value) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/remote_cp.rb', line 76

def create_obj(key, value)
  obj = @bucket.new_object
  obj.key = key
  obj.value = value
  obj.store
  obj
end

#filenameObject



72
73
74
# File 'lib/remote_cp.rb', line 72

def filename
  @content_object.meta_headers["filename"]
end

#filetypeObject



64
65
66
# File 'lib/remote_cp.rb', line 64

def filetype
  @content_object.meta_headers["type"]
end

#pullObject



56
57
58
# File 'lib/remote_cp.rb', line 56

def pull
  @content_object.get
end

#push(str, filename = "anomymous", type = :file, content_type = nil) ⇒ Object

str : content to copy type : :file, :directory



48
49
50
51
52
53
54
# File 'lib/remote_cp.rb', line 48

def push(str, filename = "anomymous", type = :file, content_type = nil)
   = { "filename" => filename, "type" => type.to_s}

  @content_object.meta_headers = 
  @content_object.data = str
  @content_object.put
end