Module: Anaconda
- Defined in:
- lib/anaconda.rb,
lib/anaconda/engine.rb,
lib/anaconda/errors.rb,
lib/anaconda/railtie.rb,
lib/anaconda/version.rb,
lib/anaconda/anaconda.rb,
lib/anaconda/s3_uploader.rb,
lib/anaconda/anaconda_for.rb,
lib/anaconda/form_builder_helpers.rb,
lib/generators/anaconda/install_generator.rb,
lib/generators/anaconda/migration_generator.rb
Defined Under Namespace
Modules: FormBuilderHelpers, Model, Rails Classes: AnacondaError, Error, InstallGenerator, MigrationGenerator, Railtie, S3Uploader
Constant Summary collapse
- MagicMethods =
[:url, :download_url, :anaconda_default_base_key]
- FieldSuffixes =
[ :filename, :file_path, :size, :original_filename, :stored_privately, :type ]
- @@aws =
{ aws_access_key: "", aws_secret_key: "", aws_bucket: "", aws_endpoint: "" }
- @@file_types =
{ audio: /(\.|\/)(wav|mp3|m4a|aiff|ogg|flac)$/, video: /(\.|\/)(mp[e]?g|mov|avi|mp4|m4v)$/, image: /(\.|\/)(jp[e]?g|png|bmp)$/, resource: /(\.|\/)(pdf|ppt[x]?|doc[x]?|xls[x]?)$/, }
Class Method Summary collapse
-
.config {|_self| ... } ⇒ Object
Default way to setup Anaconda.
- .js_file_types ⇒ Object
- .remove_s3_object(file_path, options) ⇒ Object
Class Method Details
.config {|_self| ... } ⇒ Object
Default way to setup Anaconda. Run rails generate anaconda:install to create a fresh initializer with all configuration values.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/anaconda.rb', line 32 def self.config yield self if @@aws[:aws_bucket].present? @@aws[:aws_endpoint] = "s3.amazonaws.com/#{@@aws[:aws_bucket]}" unless @@aws[:aws_endpoint].present? end if @@aws[:aws_endpoint].present? && @@aws[:aws_bucket].present? @@aws[:path_style] = !@@aws[:aws_endpoint].starts_with?(@@aws[:aws_bucket]) else @@aws[:path_style] = false end end |
.js_file_types ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/anaconda.rb', line 46 def self.js_file_types # http://stackoverflow.com/questions/4854714/how-to-translate-ruby-regex-to-javascript-i-mx-and-rails-3-0-3 js_file_types = {} file_types.each do |group_name, regexp| str = regexp.inspect. sub('\\A' , '^'). sub('\\Z' , '$'). sub('\\z' , '$'). sub(/^\// , ''). sub(/\/[a-z]*$/ , ''). gsub(/\(\?#.+\)/ , ''). gsub(/\(\?-\w+:/ , '('). gsub(/\s/ , '') regexp_str = Regexp.new(str).source js_file_types[group_name.to_s] = regexp_str end return js_file_types end |
.remove_s3_object(file_path, options) ⇒ Object
65 66 67 68 |
# File 'lib/anaconda.rb', line 65 def self.remove_s3_object(file_path, ) aws = Fog::Storage.new({:provider => 'AWS', :aws_access_key_id => [:aws_access_key], :aws_secret_access_key => [:aws_secret_key], :path_style => [:aws_use_path_style]}) aws.delete_object([:aws_bucket], file_path) end |