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

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.

Yields:

  • (_self)

Yield Parameters:

  • _self (Anaconda)

    the object that the method was called on



32
33
34
35
36
37
# File 'lib/anaconda.rb', line 32

def self.config
  yield self
  
  @@aws[:aws_endpoint] = "s3.amazonaws.com/#{@@aws[:aws_bucket]}" unless @@aws[:aws_endpoint].present?
  @@aws[:path_style] = !@@aws[:aws_endpoint].starts_with?(@@aws[:aws_bucket])
end

.js_file_typesObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/anaconda.rb', line 39

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_in_bucket_with_file_path(bucket, file_path) ⇒ Object



58
59
60
61
# File 'lib/anaconda.rb', line 58

def self.remove_s3_object_in_bucket_with_file_path(bucket, file_path)
  aws = Fog::Storage.new({:provider => 'AWS', :aws_access_key_id => Anaconda.aws[:aws_access_key], :aws_secret_access_key => Anaconda.aws[:aws_secret_key], :path_style => @@aws[:path_style]})
  aws.delete_object(bucket, file_path)
end