Class: CloudTempfile::Config
- Inherits:
-
Object
- Object
- CloudTempfile::Config
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/cloud_tempfile/config.rb
Defined Under Namespace
Classes: Invalid
Instance Attribute Summary collapse
-
#aws_access_control_list ⇒ Object
Amazon AWS.
-
#aws_access_key_id ⇒ Object
Amazon AWS.
-
#aws_reduced_redundancy ⇒ Object
Amazon AWS.
-
#aws_secret_access_key ⇒ Object
Amazon AWS.
-
#clean_up ⇒ Object
Returns the value of attribute clean_up.
-
#clean_up_older_than ⇒ Object
Returns the value of attribute clean_up_older_than.
-
#enabled ⇒ Object
CloudTempfile.
-
#expiry ⇒ Object
Returns the value of attribute expiry.
-
#fail_silently ⇒ Object
Logging Options.
-
#fog_directory ⇒ Object
e.g.
-
#fog_endpoint ⇒ Object
e.g.
-
#fog_host ⇒ Object
FOG configuration.
-
#fog_provider ⇒ Object
Currently Supported [‘AWS’, ‘Google’, ‘Rackspace’, ‘Local’].
-
#fog_region ⇒ Object
e.g.
-
#google_storage_access_key_id ⇒ Object
Google Storage.
-
#google_storage_secret_access_key ⇒ Object
Google Storage.
-
#log_silently ⇒ Object
Returns the value of attribute log_silently.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#public ⇒ Object
Returns the value of attribute public.
-
#public_path ⇒ Object
Returns the value of attribute public_path.
-
#rackspace_api_key ⇒ Object
Rackspace.
-
#rackspace_auth_url ⇒ Object
Rackspace.
-
#rackspace_username ⇒ Object
Rackspace.
Instance Method Summary collapse
- #aws? ⇒ Boolean
-
#aws_acl? ⇒ Boolean
Set file’s access control list (ACL).
- #aws_rrs? ⇒ Boolean
- #clean_up? ⇒ Boolean
- #enabled? ⇒ Boolean
-
#expiry? ⇒ Boolean
def public_path @public_path || Rails.public_path end.
- #fail_silently? ⇒ Boolean
- #fog_options ⇒ Object
- #google? ⇒ Boolean
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_yml! ⇒ Object
- #local? ⇒ Boolean
- #log_silently? ⇒ Boolean
- #public? ⇒ Boolean
- #rackspace? ⇒ Boolean
- #yml ⇒ Object
- #yml_exists? ⇒ Boolean
- #yml_path ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/cloud_tempfile/config.rb', line 56 def initialize self.enabled = true self.fog_region = nil self.fog_endpoint = '/' self.fog_provider = 'Local' self.public = false self.prefix = "tmp/" self.expiry = 600 # 10 Min = 600 Seconds self.fail_silently = false self.log_silently = true self.clean_up = false self.clean_up_older_than = 86400 # 1 Day = 86400 Seconds self.public_path = Rails.root.join 'public' if defined?(Rails) load_yml! if defined?(Rails) && yml_exists? end |
Instance Attribute Details
#aws_access_control_list ⇒ Object
Amazon AWS
29 30 31 |
# File 'lib/cloud_tempfile/config.rb', line 29 def aws_access_control_list @aws_access_control_list end |
#aws_access_key_id ⇒ Object
Amazon AWS
29 30 31 |
# File 'lib/cloud_tempfile/config.rb', line 29 def aws_access_key_id @aws_access_key_id end |
#aws_reduced_redundancy ⇒ Object
Amazon AWS
29 30 31 |
# File 'lib/cloud_tempfile/config.rb', line 29 def aws_reduced_redundancy @aws_reduced_redundancy end |
#aws_secret_access_key ⇒ Object
Amazon AWS
29 30 31 |
# File 'lib/cloud_tempfile/config.rb', line 29 def aws_secret_access_key @aws_secret_access_key end |
#clean_up ⇒ Object
Returns the value of attribute clean_up.
18 19 20 |
# File 'lib/cloud_tempfile/config.rb', line 18 def clean_up @clean_up end |
#clean_up_older_than ⇒ Object
Returns the value of attribute clean_up_older_than.
19 20 21 |
# File 'lib/cloud_tempfile/config.rb', line 19 def clean_up_older_than @clean_up_older_than end |
#enabled ⇒ Object
CloudTempfile
12 13 14 |
# File 'lib/cloud_tempfile/config.rb', line 12 def enabled @enabled end |
#expiry ⇒ Object
Returns the value of attribute expiry.
17 18 19 |
# File 'lib/cloud_tempfile/config.rb', line 17 def expiry @expiry end |
#fail_silently ⇒ Object
Logging Options
38 39 40 |
# File 'lib/cloud_tempfile/config.rb', line 38 def fail_silently @fail_silently end |
#fog_directory ⇒ Object
e.g. ‘the-bucket-name’
24 25 26 |
# File 'lib/cloud_tempfile/config.rb', line 24 def fog_directory @fog_directory end |
#fog_endpoint ⇒ Object
e.g. ‘/’
26 27 28 |
# File 'lib/cloud_tempfile/config.rb', line 26 def fog_endpoint @fog_endpoint end |
#fog_host ⇒ Object
FOG configuration
22 23 24 |
# File 'lib/cloud_tempfile/config.rb', line 22 def fog_host @fog_host end |
#fog_provider ⇒ Object
Currently Supported [‘AWS’, ‘Google’, ‘Rackspace’, ‘Local’]
23 24 25 |
# File 'lib/cloud_tempfile/config.rb', line 23 def fog_provider @fog_provider end |
#fog_region ⇒ Object
e.g. ‘eu-west-1’ or ‘us-east-1’ etc…
25 26 27 |
# File 'lib/cloud_tempfile/config.rb', line 25 def fog_region @fog_region end |
#google_storage_access_key_id ⇒ Object
Google Storage
35 36 37 |
# File 'lib/cloud_tempfile/config.rb', line 35 def google_storage_access_key_id @google_storage_access_key_id end |
#google_storage_secret_access_key ⇒ Object
Google Storage
35 36 37 |
# File 'lib/cloud_tempfile/config.rb', line 35 def google_storage_secret_access_key @google_storage_secret_access_key end |
#log_silently ⇒ Object
Returns the value of attribute log_silently.
39 40 41 |
# File 'lib/cloud_tempfile/config.rb', line 39 def log_silently @log_silently end |
#prefix ⇒ Object
Returns the value of attribute prefix.
14 15 16 |
# File 'lib/cloud_tempfile/config.rb', line 14 def prefix @prefix end |
#public ⇒ Object
Returns the value of attribute public.
15 16 17 |
# File 'lib/cloud_tempfile/config.rb', line 15 def public @public end |
#public_path ⇒ Object
Returns the value of attribute public_path.
16 17 18 |
# File 'lib/cloud_tempfile/config.rb', line 16 def public_path @public_path end |
#rackspace_api_key ⇒ Object
Rackspace
32 33 34 |
# File 'lib/cloud_tempfile/config.rb', line 32 def rackspace_api_key @rackspace_api_key end |
#rackspace_auth_url ⇒ Object
Rackspace
32 33 34 |
# File 'lib/cloud_tempfile/config.rb', line 32 def rackspace_auth_url @rackspace_auth_url end |
#rackspace_username ⇒ Object
Rackspace
32 33 34 |
# File 'lib/cloud_tempfile/config.rb', line 32 def rackspace_username @rackspace_username end |
Instance Method Details
#aws? ⇒ Boolean
93 94 95 |
# File 'lib/cloud_tempfile/config.rb', line 93 def aws? fog_provider == 'AWS' end |
#aws_acl? ⇒ Boolean
Set file’s access control list (ACL). Valid acls: private, public-read, public-read-write, authenticated-read, bucket-owner-read, bucket-owner-full-control
103 104 105 |
# File 'lib/cloud_tempfile/config.rb', line 103 def aws_acl? ['private', 'public-read', 'public-read-write', 'authenticated-read', 'bucket-owner-read', 'bucket-owner-full-control'].include?(aws_access_control_list) end |
#aws_rrs? ⇒ Boolean
97 98 99 |
# File 'lib/cloud_tempfile/config.rb', line 97 def aws_rrs? aws_reduced_redundancy == true end |
#clean_up? ⇒ Boolean
119 120 121 |
# File 'lib/cloud_tempfile/config.rb', line 119 def clean_up? clean_up == true end |
#enabled? ⇒ Boolean
77 78 79 |
# File 'lib/cloud_tempfile/config.rb', line 77 def enabled? enabled == true end |
#expiry? ⇒ Boolean
def public_path
@public_path || Rails.public_path
end
89 90 91 |
# File 'lib/cloud_tempfile/config.rb', line 89 def expiry? !expiry.nil? end |
#fail_silently? ⇒ Boolean
203 204 205 |
# File 'lib/cloud_tempfile/config.rb', line 203 def fail_silently? fail_silently || !enabled? end |
#fog_options ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/cloud_tempfile/config.rb', line 123 def #If the CloudTempfile is disabled then revert to local file creation @fog_provider = 'Local' if (@enabled != true) = { :provider => fog_provider } if aws? .merge!({ :aws_access_key_id => aws_access_key_id, :aws_secret_access_key => aws_secret_access_key }) .merge!({:host => fog_host}) if !fog_host.blank? elsif rackspace? .merge!({ :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key }) .merge!({ :rackspace_region => fog_region }) if fog_region .merge!({ :rackspace_auth_url => rackspace_auth_url }) if rackspace_auth_url elsif google? .merge!({ :google_storage_secret_access_key => google_storage_secret_access_key, :google_storage_access_key_id => google_storage_access_key_id }) elsif local? .merge!({ :local_root => public_path, :endpoint => fog_endpoint }) else raise ArgumentError, "CloudTempfile Unknown provider: #{fog_provider} only AWS, Rackspace and Google are supported currently." end .merge!({:region => fog_region}) if fog_region && !rackspace? return end |
#google? ⇒ Boolean
111 112 113 |
# File 'lib/cloud_tempfile/config.rb', line 111 def google? fog_provider == 'Google' end |
#load_yml! ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/cloud_tempfile/config.rb', line 178 def load_yml! self.enabled = yml["enabled"] if yml.has_key?('enabled') self.fog_provider = yml["fog_provider"] if yml.has_key?('fog_provider') self.fog_directory = yml["fog_directory"] self.fog_region = yml["fog_region"] self.fog_host = yml["fog_host"] if yml.has_key?("fog_host") self.aws_access_key_id = yml["aws_access_key_id"] self.aws_secret_access_key = yml["aws_secret_access_key"] self.aws_reduced_redundancy = yml["aws_reduced_redundancy"] self.rackspace_username = yml["rackspace_username"] self.rackspace_auth_url = yml["rackspace_auth_url"] if yml.has_key?("rackspace_auth_url") self.rackspace_api_key = yml["rackspace_api_key"] self.google_storage_secret_access_key = yml["google_storage_secret_access_key"] self.google_storage_access_key_id = yml["google_storage_access_key_id"] self.clean_up = yml["clean_up"] if yml.has_key?("clean_up") self.clean_up_older_than = yml["clean_up_older_than"] if yml.has_key?("clean_up_older_than") self.fail_silently = yml["fail_silently"] if yml.has_key?("fail_silently") self.prefix = yml["prefix"] if yml.has_key?("prefix") self.public = yml["public"] if yml.has_key?("public") self.public_path = yml["public_path"] if yml.has_key?("public_path") self.expiry = yml["expiry"] if yml.has_key?("expiry") end |
#local? ⇒ Boolean
115 116 117 |
# File 'lib/cloud_tempfile/config.rb', line 115 def local? fog_provider == 'Local' end |
#log_silently? ⇒ Boolean
207 208 209 |
# File 'lib/cloud_tempfile/config.rb', line 207 def log_silently? self.log_silently == false end |
#public? ⇒ Boolean
81 82 83 |
# File 'lib/cloud_tempfile/config.rb', line 81 def public? public == true end |
#rackspace? ⇒ Boolean
107 108 109 |
# File 'lib/cloud_tempfile/config.rb', line 107 def rackspace? fog_provider == 'Rackspace' end |
#yml ⇒ Object
166 167 168 169 170 171 172 |
# File 'lib/cloud_tempfile/config.rb', line 166 def yml begin @yml ||= YAML.load(ERB.new(IO.read(yml_path)).result)[Rails.env] rescue nil || {} rescue Psych::SyntaxError @yml = {} end end |
#yml_exists? ⇒ Boolean
162 163 164 |
# File 'lib/cloud_tempfile/config.rb', line 162 def yml_exists? defined?(Rails.root) ? File.exists?(self.yml_path) : false end |
#yml_path ⇒ Object
174 175 176 |
# File 'lib/cloud_tempfile/config.rb', line 174 def yml_path Rails.root.join("config", "cloud_tempfile.yml").to_s end |