├── .gitignore
├── CHANGELOG.textile
├── Gemfile
├── Gemfile.lock
├── README.textile
├── Rakefile
├── VERSION
├── app
├── assets
│ ├── images
│ │ └── rails.png
│ ├── javascripts
│ │ ├── application.js
│ │ └── swift.js.coffee
│ └── stylesheets
│ │ ├── application.css
│ │ └── swift.css.scss
├── controllers
│ ├── application_controller.rb
│ └── swift_controller.rb
├── helpers
│ ├── application_helper.rb
│ └── swift_helper.rb
├── mailers
│ └── .gitkeep
├── models
│ └── .gitkeep
└── views
│ ├── layouts
│ └── application.html.erb
│ └── swift
│ ├── read_environment.html.erb
│ └── test_swift.html.erb
├── config.ru
├── config
├── application.rb
├── boot.rb
├── database.yml
├── environment.rb
├── environments
│ ├── development.rb
│ ├── production.rb
│ └── test.rb
├── initializers
│ ├── backtrace_silencers.rb
│ ├── inflections.rb
│ ├── mime_types.rb
│ ├── secret_token.rb
│ ├── session_store.rb
│ └── wrap_parameters.rb
├── locales
│ └── en.yml
└── routes.rb
├── db
├── schema.rb
└── seeds.rb
├── doc
└── README_FOR_APP
├── lib
├── assets
│ └── .gitkeep
├── swift
│ ├── storage.rb
│ └── swift_test.rb
└── tasks
│ └── .gitkeep
├── log
└── .gitkeep
├── public
├── .DS_Store
├── 404.html
├── 422.html
├── 500.html
├── favicon.ico
├── index.html
├── picture.jpg
├── robots.txt
└── swift_test.html
├── script
└── rails
├── test
├── fixtures
│ └── .gitkeep
├── functional
│ ├── .gitkeep
│ └── swift_controller_test.rb
├── integration
│ └── .gitkeep
├── performance
│ └── browsing_test.rb
├── test_helper.rb
└── unit
│ ├── .gitkeep
│ └── helpers
│ └── swift_helper_test.rb
└── vendor
├── assets
├── javascripts
│ └── .gitkeep
└── stylesheets
│ └── .gitkeep
└── plugins
└── .gitkeep
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 | #
3 | # If you find yourself ignoring temporary files generated by your text editor
4 | # or operating system, you probably want to add a global ignore instead:
5 | # git config --global core.excludesfile ~/.gitignore_global
6 |
7 | # Ignore bundler config
8 | /.bundle
9 |
10 | # Ignore the default SQLite database.
11 | /db/*.sqlite3
12 |
13 | # Ignore all logfiles and tempfiles.
14 | /log/*.log
15 | /tmp
16 |
17 | # Ignore rubymine project files
18 | .idea/*
19 |
--------------------------------------------------------------------------------
/CHANGELOG.textile:
--------------------------------------------------------------------------------
1 | h1. v0.1.1
2 | * create a temporary url for a file located in a private directory
3 | * create a public directory on swift
4 | * removes test file deletion
5 |
6 | h1. v0.1.0
7 | * basic features
8 | ** read_environment: prints out a list of environment variables
9 | ** test_swift: create directory, upload file, delete file on Swift storage
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | ruby '1.9.3'
4 |
5 | gem 'rails', '3.2.13'
6 |
7 | # Bundle edge Rails instead:
8 | # gem 'rails', :git => 'git://github.com/rails/rails.git'
9 |
10 | gem 'sqlite3'
11 | gem 'mysql2'
12 |
13 |
14 | # Gems used only for assets and not required
15 | # in production environments by default.
16 | group :assets do
17 | gem 'sass-rails', '~> 3.2.3'
18 | gem 'coffee-rails', '~> 3.2.1'
19 |
20 | # See https://github.com/sstephenson/execjs#readme for more supported runtimes
21 | # gem 'therubyracer', :platforms => :ruby
22 |
23 | gem 'uglifier', '>= 1.0.3'
24 | end
25 |
26 | gem 'jquery-rails'
27 |
28 | gem 'multi_json'
29 | gem 'fog'
30 |
31 | gem 'pry'
32 | gem 'pry-debugger'
33 |
34 | # To use ActiveModel has_secure_password
35 | # gem 'bcrypt-ruby', '~> 3.0.0'
36 |
37 | # To use Jbuilder templates for JSON
38 | # gem 'jbuilder'
39 |
40 | # Use unicorn as the app server
41 | # gem 'unicorn'
42 |
43 | # Deploy with Capistrano
44 | # gem 'capistrano'
45 |
46 | # To use debugger
47 | # gem 'debugger'
48 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | actionmailer (3.2.13)
5 | actionpack (= 3.2.13)
6 | mail (~> 2.5.3)
7 | actionpack (3.2.13)
8 | activemodel (= 3.2.13)
9 | activesupport (= 3.2.13)
10 | builder (~> 3.0.0)
11 | erubis (~> 2.7.0)
12 | journey (~> 1.0.4)
13 | rack (~> 1.4.5)
14 | rack-cache (~> 1.2)
15 | rack-test (~> 0.6.1)
16 | sprockets (~> 2.2.1)
17 | activemodel (3.2.13)
18 | activesupport (= 3.2.13)
19 | builder (~> 3.0.0)
20 | activerecord (3.2.13)
21 | activemodel (= 3.2.13)
22 | activesupport (= 3.2.13)
23 | arel (~> 3.0.2)
24 | tzinfo (~> 0.3.29)
25 | activeresource (3.2.13)
26 | activemodel (= 3.2.13)
27 | activesupport (= 3.2.13)
28 | activesupport (3.2.13)
29 | i18n (= 0.6.1)
30 | multi_json (~> 1.0)
31 | arel (3.0.2)
32 | builder (3.0.4)
33 | coderay (1.0.9)
34 | coffee-rails (3.2.2)
35 | coffee-script (>= 2.2.0)
36 | railties (~> 3.2.0)
37 | coffee-script (2.2.0)
38 | coffee-script-source
39 | execjs
40 | coffee-script-source (1.6.2)
41 | columnize (0.3.6)
42 | debugger (1.5.0)
43 | columnize (>= 0.3.1)
44 | debugger-linecache (~> 1.2.0)
45 | debugger-ruby_core_source (~> 1.2.0)
46 | debugger-linecache (1.2.0)
47 | debugger-ruby_core_source (1.2.2)
48 | erubis (2.7.0)
49 | excon (0.22.1)
50 | execjs (1.4.0)
51 | multi_json (~> 1.0)
52 | fog (1.11.1)
53 | builder
54 | excon (~> 0.20)
55 | formatador (~> 0.2.0)
56 | json (~> 1.7)
57 | mime-types
58 | net-scp (~> 1.1)
59 | net-ssh (>= 2.1.3)
60 | nokogiri (~> 1.5.0)
61 | ruby-hmac
62 | formatador (0.2.4)
63 | hike (1.2.3)
64 | i18n (0.6.1)
65 | journey (1.0.4)
66 | jquery-rails (3.0.1)
67 | railties (>= 3.0, < 5.0)
68 | thor (>= 0.14, < 2.0)
69 | json (1.8.0)
70 | mail (2.5.4)
71 | mime-types (~> 1.16)
72 | treetop (~> 1.4.8)
73 | method_source (0.8.1)
74 | mime-types (1.23)
75 | multi_json (1.7.7)
76 | mysql2 (0.3.11)
77 | net-scp (1.1.1)
78 | net-ssh (>= 2.6.5)
79 | net-ssh (2.6.7)
80 | nokogiri (1.5.9)
81 | polyglot (0.3.3)
82 | pry (0.9.12.2)
83 | coderay (~> 1.0.5)
84 | method_source (~> 0.8)
85 | slop (~> 3.4)
86 | pry-debugger (0.2.2)
87 | debugger (~> 1.3)
88 | pry (~> 0.9.10)
89 | rack (1.4.5)
90 | rack-cache (1.2)
91 | rack (>= 0.4)
92 | rack-ssl (1.3.3)
93 | rack
94 | rack-test (0.6.2)
95 | rack (>= 1.0)
96 | rails (3.2.13)
97 | actionmailer (= 3.2.13)
98 | actionpack (= 3.2.13)
99 | activerecord (= 3.2.13)
100 | activeresource (= 3.2.13)
101 | activesupport (= 3.2.13)
102 | bundler (~> 1.0)
103 | railties (= 3.2.13)
104 | railties (3.2.13)
105 | actionpack (= 3.2.13)
106 | activesupport (= 3.2.13)
107 | rack-ssl (~> 1.3.2)
108 | rake (>= 0.8.7)
109 | rdoc (~> 3.4)
110 | thor (>= 0.14.6, < 2.0)
111 | rake (10.0.4)
112 | rdoc (3.12.2)
113 | json (~> 1.4)
114 | ruby-hmac (0.4.0)
115 | sass (3.2.9)
116 | sass-rails (3.2.6)
117 | railties (~> 3.2.0)
118 | sass (>= 3.1.10)
119 | tilt (~> 1.3)
120 | slop (3.4.5)
121 | sprockets (2.2.2)
122 | hike (~> 1.2)
123 | multi_json (~> 1.0)
124 | rack (~> 1.0)
125 | tilt (~> 1.1, != 1.3.0)
126 | sqlite3 (1.3.7)
127 | thor (0.18.1)
128 | tilt (1.4.1)
129 | treetop (1.4.14)
130 | polyglot
131 | polyglot (>= 0.3.1)
132 | tzinfo (0.3.37)
133 | uglifier (2.1.1)
134 | execjs (>= 0.3.0)
135 | multi_json (~> 1.0, >= 1.0.2)
136 |
137 | PLATFORMS
138 | ruby
139 |
140 | DEPENDENCIES
141 | coffee-rails (~> 3.2.1)
142 | fog
143 | jquery-rails
144 | multi_json
145 | mysql2
146 | pry
147 | pry-debugger
148 | rails (= 3.2.13)
149 | sass-rails (~> 3.2.3)
150 | sqlite3
151 | uglifier (>= 1.0.3)
152 |
--------------------------------------------------------------------------------
/README.textile:
--------------------------------------------------------------------------------
1 | h1. Rails Swift Cloud Storage Usage Demo
2 |
3 | A simple rails application demonstrating the access of Swift File Storage from within an instance running on a cloud foundry installation.
4 |
5 | h2. Introduction
6 |
7 | When using cloud foundry services(mysql, postgresql, swift, ...), user credentials are provided as environment variables to the application instances.
8 | These credentials are stored within VCAP_SERVICES. An application can parse these credentials to access the desired services.
9 | This application demonstrates the usage scenario of accessing a Swift File Storage with the credentials provided by the cf_swift_service.
10 |
11 | h2. Code Walkthrough
12 |
13 | * SwiftController (app/controllers/swift_controller.rb)
14 | ** test_swift: performs the test defined in the SwiftTest class (see below)
15 | ** read_environment: prints out the environment variables visible to the application
16 |
17 | * Swift::Storage (lib/swift/storage.rb)
18 | ** wrapper around the fog gem API
19 | ** create/delete directories on a swift instance
20 | ** upload/download/delete files from/to a swift instance
21 | ** create temporary urls
22 | ** set directories to private/public
23 |
24 | * Swift::SwiftTest
25 | ** performs the actual test (perform_test)
26 | ** generates a hash containing test outputs
27 | ** the test consists of 2 steps:
28 | *** create public and private test directories (create_private_test_directory, create_public_test_directory)
29 | *** upload one example file to each directory (upload_example_file_1, upload_example_file_2)
30 |
31 | h3. Anynines deployment
32 | For installing the test application you have to bind a mysql and a swift service instance to the application.
33 |
34 | $> cf push
35 | Name> swift
36 |
37 | Instances> 1
38 |
39 | 1: 64M
40 | 2: 128M
41 | 3: 256M
42 | 4: 512M
43 | 5: 1G
44 | Memory Limit> 2
45 |
46 | Creating swift... OK
47 |
48 | 1: swift
49 | 2: none
50 | Subdomain> swift
51 |
52 | 1: de.a9sapp.eu
53 | 2: none
54 | Domain> de.a9sapp.eu
55 |
56 | Binding swift.de.a9sapp.eu to swift... OK
57 |
58 | Create services for application?> y
59 |
60 | 1: mongodb 2.0
61 | 2: mysql 5.5
62 | 3: postgresql 9.0
63 | 4: rabbitmq 2.8
64 | 5: redis 2.2
65 | 6: swift 1.0
66 | What kind?> 6
67 |
68 | Name?> swift-15f97
69 |
70 | 1: free: free plan
71 | Which plan?> 1
72 |
73 | Creating service swift-15f97... OK
74 | Binding swift-15f97 to swift... OK
75 | Create another service?> y
76 |
77 | 1: mongodb 2.0
78 | 2: mysql 5.5
79 | 3: postgresql 9.0
80 | 4: rabbitmq 2.8
81 | 5: redis 2.2
82 | 6: swift 1.0
83 | What kind?> 2
84 |
85 | Name?> mysql-f1300
86 |
87 | 1: 100: Shared server, shared VM, 1MB memory, 10MB storage, 10 connections
88 | Which plan?> 1
89 |
90 | Creating service mysql-f1300... OK
91 | Binding mysql-f1300 to swift... OK
92 | Create another service?> n
93 |
94 | Bind other services to application?> n
95 |
96 | Save configuration?> n
97 |
98 | Uploading swift... OK
99 | .....
100 | 1/1 instances: 1 running
101 | OK
102 |
103 | h3. Local execution
104 |
105 | At first you have to create a tenant with the according rights on your Swift Installation.
106 | To be able to execute the application from outside a cloud foundry installation, you have to specify the VCAP_SERVICES environment variable at startup (exchange the dummies with your credentials):
107 |
108 | VCAP_SERVICES='{"swift-1.0":[{"name":"swift-50e83","label":"swift-1.0","plan":"free","credentials":{"name":"name","authentication_uri":"https://auth.example.com:5000/v2.0/","user_name":"user_name","user_id":"user_id","password":"password","tenant_name":"tenant_name","tenant_id":"tenant_id","availability_zone":"nova","authentication_version":"v2"}}]}' rails s
109 |
110 | h3. Test the example application
111 | Show the environment variables controller:
112 | /swift/read_environment
113 |
114 | Execute the Swift storage tests and show the outputs:
115 | /swift/test_swift
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env rake
2 | # Add your own tasks in files placed in lib/tasks ending in .rake,
3 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4 |
5 | require File.expand_path('../config/application', __FILE__)
6 |
7 | SwiftTest::Application.load_tasks
8 |
--------------------------------------------------------------------------------
/VERSION:
--------------------------------------------------------------------------------
1 | v0.1.1
--------------------------------------------------------------------------------
/app/assets/images/rails.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/app/assets/images/rails.png
--------------------------------------------------------------------------------
/app/assets/javascripts/application.js:
--------------------------------------------------------------------------------
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files
2 | // listed below.
3 | //
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6 | //
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 | // the compiled file.
9 | //
10 | // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11 | // GO AFTER THE REQUIRES BELOW.
12 | //
13 | //= require jquery
14 | //= require jquery_ujs
15 | //= require_tree .
16 |
--------------------------------------------------------------------------------
/app/assets/javascripts/swift.js.coffee:
--------------------------------------------------------------------------------
1 | # Place all the behaviors and hooks related to the matching controller here.
2 | # All this logic will automatically be available in application.js.
3 | # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
4 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a manifest file that'll be compiled into application.css, which will include all the files
3 | * listed below.
4 | *
5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7 | *
8 | * You're free to add application-wide styles to this file and they'll appear at the top of the
9 | * compiled file, but it's generally better to create a new file per style scope.
10 | *
11 | *= require_self
12 | *= require_tree .
13 | */
14 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/swift.css.scss:
--------------------------------------------------------------------------------
1 | // Place all the styles related to the TestController controller here.
2 | // They will automatically be included in application.css.
3 | // You can use Sass (SCSS) here: http://sass-lang.com/
4 |
--------------------------------------------------------------------------------
/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | protect_from_forgery
3 |
4 | end
5 |
--------------------------------------------------------------------------------
/app/controllers/swift_controller.rb:
--------------------------------------------------------------------------------
1 | class SwiftController < ApplicationController
2 |
3 | # create a directory, write a file, delete it again, show output
4 | def test_swift
5 | stest = ::Swift::SwiftTest.new
6 | @hash = stest.perform_test
7 | end
8 |
9 | # just show the environment variables
10 | def read_environment
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module ApplicationHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/helpers/swift_helper.rb:
--------------------------------------------------------------------------------
1 | module SwiftHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/mailers/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/app/mailers/.gitkeep
--------------------------------------------------------------------------------
/app/models/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/app/models/.gitkeep
--------------------------------------------------------------------------------
/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | SwiftTest
5 | <%= stylesheet_link_tag "application", :media => "all" %>
6 | <%= javascript_include_tag "application" %>
7 | <%= csrf_meta_tags %>
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/views/swift/read_environment.html.erb:
--------------------------------------------------------------------------------
1 | SwiftController#read_environment
2 | Environment Variables visible to the application
3 |
4 | <% ENV.each_pair do |k,v| %>
5 |
6 | <%= k %> | <%= v %> |
7 |
8 | <% end %>
9 |
--------------------------------------------------------------------------------
/app/views/swift/test_swift.html.erb:
--------------------------------------------------------------------------------
1 | SwiftController#test_swift
2 |
3 | Step1: Created the test directories
4 | Private directory name: <%= @hash[:dirname_private] %>
5 | Public directory name: <%= @hash[:dirname_public] %>
6 |
7 | Step2: Uploaded the test files to the test directories
8 | Private directory listing: <%= @hash[:directory_contents_private] %>
9 | Public directory listing: <%= @hash[:directory_contents_public]%>
10 |
11 | Public file url: <%= @hash[:public_file_url] %>
12 | Private file temporary url: <%= @hash[:private_file_temp_url] %>
13 |
14 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require ::File.expand_path('../config/environment', __FILE__)
4 | run SwiftTest::Application
5 |
--------------------------------------------------------------------------------
/config/application.rb:
--------------------------------------------------------------------------------
1 | require File.expand_path('../boot', __FILE__)
2 |
3 | require 'rails/all'
4 |
5 | if defined?(Bundler)
6 | # If you precompile assets before deploying to production, use this line
7 | Bundler.require(*Rails.groups(:assets => %w(development test)))
8 | # If you want your assets lazily compiled in production, use this line
9 | # Bundler.require(:default, :assets, Rails.env)
10 | end
11 |
12 | module SwiftTest
13 | class Application < Rails::Application
14 | # Settings in config/environments/* take precedence over those specified here.
15 | # Application configuration should go into files in config/initializers
16 | # -- all .rb files in that directory are automatically loaded.
17 |
18 | # Custom directories with classes and modules you want to be autoloadable.
19 | # config.autoload_paths += %W(#{config.root}/extras)
20 | config.autoload_paths += %W(#{config.root}/lib)
21 |
22 | # Only load the plugins named here, in the order given (default is alphabetical).
23 | # :all can be used as a placeholder for all plugins not explicitly named.
24 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
25 |
26 | # Activate observers that should always be running.
27 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
28 |
29 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
30 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
31 | # config.time_zone = 'Central Time (US & Canada)'
32 |
33 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
34 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
35 | # config.i18n.default_locale = :de
36 |
37 | # Configure the default encoding used in templates for Ruby 1.9.
38 | config.encoding = "utf-8"
39 |
40 | # Configure sensitive parameters which will be filtered from the log file.
41 | config.filter_parameters += [:password]
42 |
43 | # Enable escaping HTML in JSON.
44 | config.active_support.escape_html_entities_in_json = true
45 |
46 | # Use SQL instead of Active Record's schema dumper when creating the database.
47 | # This is necessary if your schema can't be completely dumped by the schema dumper,
48 | # like if you have constraints or database-specific column types
49 | # config.active_record.schema_format = :sql
50 |
51 | # Enforce whitelist mode for mass assignment.
52 | # This will create an empty whitelist of attributes available for mass-assignment for all models
53 | # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
54 | # parameters by using an attr_accessible or attr_protected declaration.
55 | config.active_record.whitelist_attributes = true
56 |
57 | # Enable the asset pipeline
58 | config.assets.enabled = true
59 |
60 | # Version of your assets, change this if you want to expire all your assets
61 | config.assets.version = '1.0'
62 | end
63 | end
64 |
--------------------------------------------------------------------------------
/config/boot.rb:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 |
3 | # Set up gems listed in the Gemfile.
4 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5 |
6 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
7 |
--------------------------------------------------------------------------------
/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite version 3.x
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem 'sqlite3'
6 | development:
7 | adapter: sqlite3
8 | database: db/development.sqlite3
9 | pool: 5
10 | timeout: 5000
11 |
12 | # Warning: The database defined as "test" will be erased and
13 | # re-generated from your development database when you run "rake".
14 | # Do not set this db to the same as development or production.
15 | test:
16 | adapter: sqlite3
17 | database: db/test.sqlite3
18 | pool: 5
19 | timeout: 5000
20 |
21 | production:
22 | adapter: sqlite3
23 | database: db/production.sqlite3
24 | pool: 5
25 | timeout: 5000
26 |
--------------------------------------------------------------------------------
/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the rails application
2 | require File.expand_path('../application', __FILE__)
3 |
4 | # Initialize the rails application
5 | SwiftTest::Application.initialize!
6 |
--------------------------------------------------------------------------------
/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | SwiftTest::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb
3 |
4 | # In the development environment your application's code is reloaded on
5 | # every request. This slows down response time but is perfect for development
6 | # since you don't have to restart the web server when you make code changes.
7 | config.cache_classes = false
8 |
9 | # Log error messages when you accidentally call methods on nil.
10 | config.whiny_nils = true
11 |
12 | # Show full error reports and disable caching
13 | config.consider_all_requests_local = true
14 | config.action_controller.perform_caching = false
15 |
16 | # Don't care if the mailer can't send
17 | config.action_mailer.raise_delivery_errors = false
18 |
19 | # Print deprecation notices to the Rails logger
20 | config.active_support.deprecation = :log
21 |
22 | # Only use best-standards-support built into browsers
23 | config.action_dispatch.best_standards_support = :builtin
24 |
25 | # Raise exception on mass assignment protection for Active Record models
26 | config.active_record.mass_assignment_sanitizer = :strict
27 |
28 | # Log the query plan for queries taking more than this (works
29 | # with SQLite, MySQL, and PostgreSQL)
30 | config.active_record.auto_explain_threshold_in_seconds = 0.5
31 |
32 | # Do not compress assets
33 | config.assets.compress = false
34 |
35 | # Expands the lines which load the assets
36 | config.assets.debug = true
37 | end
38 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | SwiftTest::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb
3 |
4 | # Code is not reloaded between requests
5 | config.cache_classes = true
6 |
7 | # Full error reports are disabled and caching is turned on
8 | config.consider_all_requests_local = false
9 | config.action_controller.perform_caching = true
10 |
11 | # Disable Rails's static asset server (Apache or nginx will already do this)
12 | config.serve_static_assets = false
13 |
14 | # Compress JavaScripts and CSS
15 | config.assets.compress = true
16 |
17 | # Don't fallback to assets pipeline if a precompiled asset is missed
18 | config.assets.compile = false
19 |
20 | # Generate digests for assets URLs
21 | config.assets.digest = true
22 |
23 | # Defaults to nil and saved in location specified by config.assets.prefix
24 | # config.assets.manifest = YOUR_PATH
25 |
26 | # Specifies the header that your server uses for sending files
27 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
28 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
29 |
30 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
31 | # config.force_ssl = true
32 |
33 | # See everything in the log (default is :info)
34 | # config.log_level = :debug
35 |
36 | # Prepend all log lines with the following tags
37 | # config.log_tags = [ :subdomain, :uuid ]
38 |
39 | # Use a different logger for distributed setups
40 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
41 |
42 | # Use a different cache store in production
43 | # config.cache_store = :mem_cache_store
44 |
45 | # Enable serving of images, stylesheets, and JavaScripts from an asset server
46 | # config.action_controller.asset_host = "http://assets.example.com"
47 |
48 | # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
49 | # config.assets.precompile += %w( search.js )
50 |
51 | # Disable delivery errors, bad email addresses will be ignored
52 | # config.action_mailer.raise_delivery_errors = false
53 |
54 | # Enable threaded mode
55 | # config.threadsafe!
56 |
57 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
58 | # the I18n.default_locale when a translation can not be found)
59 | config.i18n.fallbacks = true
60 |
61 | # Send deprecation notices to registered listeners
62 | config.active_support.deprecation = :notify
63 |
64 | # Log the query plan for queries taking more than this (works
65 | # with SQLite, MySQL, and PostgreSQL)
66 | # config.active_record.auto_explain_threshold_in_seconds = 0.5
67 | end
68 |
--------------------------------------------------------------------------------
/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | SwiftTest::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb
3 |
4 | # The test environment is used exclusively to run your application's
5 | # test suite. You never need to work with it otherwise. Remember that
6 | # your test database is "scratch space" for the test suite and is wiped
7 | # and recreated between test runs. Don't rely on the data there!
8 | config.cache_classes = true
9 |
10 | # Configure static asset server for tests with Cache-Control for performance
11 | config.serve_static_assets = true
12 | config.static_cache_control = "public, max-age=3600"
13 |
14 | # Log error messages when you accidentally call methods on nil
15 | config.whiny_nils = true
16 |
17 | # Show full error reports and disable caching
18 | config.consider_all_requests_local = true
19 | config.action_controller.perform_caching = false
20 |
21 | # Raise exceptions instead of rendering exception templates
22 | config.action_dispatch.show_exceptions = false
23 |
24 | # Disable request forgery protection in test environment
25 | config.action_controller.allow_forgery_protection = false
26 |
27 | # Tell Action Mailer not to deliver emails to the real world.
28 | # The :test delivery method accumulates sent emails in the
29 | # ActionMailer::Base.deliveries array.
30 | config.action_mailer.delivery_method = :test
31 |
32 | # Raise exception on mass assignment protection for Active Record models
33 | config.active_record.mass_assignment_sanitizer = :strict
34 |
35 | # Print deprecation notices to the stderr
36 | config.active_support.deprecation = :stderr
37 | end
38 |
--------------------------------------------------------------------------------
/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format
4 | # (all these examples are active by default):
5 | # ActiveSupport::Inflector.inflections do |inflect|
6 | # inflect.plural /^(ox)$/i, '\1en'
7 | # inflect.singular /^(ox)en/i, '\1'
8 | # inflect.irregular 'person', 'people'
9 | # inflect.uncountable %w( fish sheep )
10 | # end
11 | #
12 | # These inflection rules are supported but not enabled by default:
13 | # ActiveSupport::Inflector.inflections do |inflect|
14 | # inflect.acronym 'RESTful'
15 | # end
16 |
--------------------------------------------------------------------------------
/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 | # Mime::Type.register_alias "text/html", :iphone
6 |
--------------------------------------------------------------------------------
/config/initializers/secret_token.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Your secret key for verifying the integrity of signed cookies.
4 | # If you change this key, all old signed cookies will become invalid!
5 | # Make sure the secret is at least 30 characters and all random,
6 | # no regular words or you'll be exposed to dictionary attacks.
7 | SwiftTest::Application.config.secret_token = '7cf304c08fe360b7edddd250992a514d10016fdaba939467424e55aad18c909c444e419abedd02985db112d2a1a46636a048864489e67ee9293d7fc95760655e'
8 |
--------------------------------------------------------------------------------
/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | SwiftTest::Application.config.session_store :cookie_store, key: '_swift_test_session'
4 |
5 | # Use the database for sessions instead of the cookie-based default,
6 | # which shouldn't be used to store highly confidential information
7 | # (create the session table with "rails generate session_migration")
8 | # SwiftTest::Application.config.session_store :active_record_store
9 |
--------------------------------------------------------------------------------
/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 | #
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters format: [:json]
9 | end
10 |
11 | # Disable root element in JSON by default.
12 | ActiveSupport.on_load(:active_record) do
13 | self.include_root_in_json = false
14 | end
15 |
--------------------------------------------------------------------------------
/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Sample localization file for English. Add more files in this directory for other locales.
2 | # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3 |
4 | en:
5 | hello: "Hello world"
6 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | SwiftTest::Application.routes.draw do
2 |
3 | get "swift/test_swift"
4 |
5 | get "swift/read_environment"
6 |
7 | # The priority is based upon order of creation:
8 | # first created -> highest priority.
9 |
10 | # Sample of regular route:
11 | # match 'products/:id' => 'catalog#view'
12 | # Keep in mind you can assign values other than :controller and :action
13 |
14 | # Sample of named route:
15 | # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
16 | # This route can be invoked with purchase_url(:id => product.id)
17 |
18 | # Sample resource route (maps HTTP verbs to controller actions automatically):
19 | # resources :products
20 |
21 | # Sample resource route with options:
22 | # resources :products do
23 | # member do
24 | # get 'short'
25 | # post 'toggle'
26 | # end
27 | #
28 | # collection do
29 | # get 'sold'
30 | # end
31 | # end
32 |
33 | # Sample resource route with sub-resources:
34 | # resources :products do
35 | # resources :comments, :sales
36 | # resource :seller
37 | # end
38 |
39 | # Sample resource route with more complex sub-resources
40 | # resources :products do
41 | # resources :comments
42 | # resources :sales do
43 | # get 'recent', :on => :collection
44 | # end
45 | # end
46 |
47 | # Sample resource route within a namespace:
48 | # namespace :admin do
49 | # # Directs /admin/products/* to Admin::ProductsController
50 | # # (app/controllers/admin/products_controller.rb)
51 | # resources :products
52 | # end
53 |
54 | # You can have the root of your site routed with "root"
55 | # just remember to delete public/index.html.
56 | # root :to => 'welcome#index'
57 |
58 | # See how all your routes lay out with "rake routes"
59 |
60 | # This is a legacy wild controller route that's not recommended for RESTful applications.
61 | # Note: This route will make all actions in every controller accessible via GET requests.
62 | # match ':controller(/:action(/:id))(.:format)'
63 | end
64 |
--------------------------------------------------------------------------------
/db/schema.rb:
--------------------------------------------------------------------------------
1 | # encoding: UTF-8
2 | # This file is auto-generated from the current state of the database. Instead
3 | # of editing this file, please use the migrations feature of Active Record to
4 | # incrementally modify your database, and then regenerate this schema definition.
5 | #
6 | # Note that this schema.rb definition is the authoritative source for your
7 | # database schema. If you need to create the application database on another
8 | # system, you should be using db:schema:load, not running all the migrations
9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10 | # you'll amass, the slower it'll run and the greater likelihood for issues).
11 | #
12 | # It's strongly recommended to check this file into your version control system.
13 |
14 | ActiveRecord::Schema.define(:version => 0) do
15 |
16 | end
17 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7 | # Mayor.create(name: 'Emanuel', city: cities.first)
8 |
--------------------------------------------------------------------------------
/doc/README_FOR_APP:
--------------------------------------------------------------------------------
1 | Use this README file to introduce your application and point to useful places in the API for learning more.
2 | Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
3 |
--------------------------------------------------------------------------------
/lib/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/lib/assets/.gitkeep
--------------------------------------------------------------------------------
/lib/swift/storage.rb:
--------------------------------------------------------------------------------
1 | module Swift
2 | class Storage
3 |
4 | def initialize(fog_options = {
5 | :provider => 'HP',
6 | :hp_access_key => "admin",
7 | :hp_secret_key => "yourpwd",
8 | :hp_tenant_id => "d4e1c14691d841f6b53a24b6c4c42a0e",
9 | :hp_auth_uri => 'https://auth.hydranodes.de:5000/v2.0/',
10 | :hp_use_upass_auth_style => true,
11 | :hp_avl_zone => 'nova',
12 | :hp_auth_version => :v2,
13 | }, account_meta_key)
14 |
15 | @connection = Fog::Storage.new(fog_options)
16 | @account_meta_key = account_meta_key
17 | end
18 |
19 | def c
20 | @connection
21 | end
22 |
23 | def print_directories
24 | # Retrieve directories and fetch their content
25 | puts "Retrieving directories..."
26 | @connection.directories.each do |dir|
27 | p dir.files
28 | end
29 | puts "-" * 30
30 | end
31 |
32 | def create_dir(dir)
33 | puts "Creating dir #{dir}..."
34 | dir = @connection.directories.create(:key => dir)
35 | puts "done."
36 | dir
37 | end
38 |
39 | def list_dir(dir)
40 | str = String.new
41 |
42 | dir = @connection.directories.get(dir)
43 | if dir then
44 | str = dir.files.to_s
45 | else
46 | str = "#{dir} directory wasn't found"
47 | end
48 |
49 | str
50 | end
51 |
52 | def upload_file(swift_dir, file_loc, swift_file_key)
53 | file = nil
54 | # Upload
55 | test_dir = @connection.directories.get(swift_dir)
56 | if test_dir then
57 | file = test_dir.files.create(:key => swift_file_key, :body => File.open(file_loc))
58 | else
59 | puts "\nWarning: #{dir} does not exist.\n"
60 | end
61 | file
62 | end
63 |
64 | def delete_file(id, dir = test)
65 | file = @connection.directories.get(dir).files.get(id)
66 | file.destroy
67 | end
68 |
69 | def create_temp_url(file, account_meta_key = @account_meta_key)
70 | # Generate tempURL
71 | method = 'GET'
72 |
73 | # Expires in 600sec
74 | expires = Time.now.to_i + 600
75 | public_url = URI(file.public_url)
76 | base = "#{public_url.scheme}://#{public_url.host}/"
77 | path = public_url.path
78 |
79 | hmac_body = "#{method}\n#{expires}\n#{path}"
80 | sig = Digest::HMAC.hexdigest(hmac_body, account_meta_key, Digest::SHA1)
81 |
82 | "#{file.public_url}?temp_url_sig=#{sig}&temp_url_expires=#{expires}"
83 | end
84 |
85 | def make_directory_public(directory)
86 | unless directory.public?
87 | directory.public = true
88 | return directory.save
89 | end
90 | true
91 | end
92 |
93 | def make_directory_private(directory)
94 | if directory.public?
95 | directory.public = false
96 | return directory.save
97 | end
98 | true
99 | end
100 |
101 | end
102 | end
--------------------------------------------------------------------------------
/lib/swift/swift_test.rb:
--------------------------------------------------------------------------------
1 | require 'json'
2 |
3 | module Swift
4 | class SwiftTest
5 |
6 | def initialize
7 | env_hash = fog_credentials_from_cf_swift_credentials(get_swift_credentials_hash)
8 | @storage = Storage.new(env_hash[:fog], env_hash[:account_meta_key])
9 | end
10 |
11 |
12 | # the test consists of 3 sub-tasks:
13 | # 1) create a public and a private directory
14 | # 2) upload one example file to the public directory and one to the private directory
15 | # the test prints out a directory listing after performing each sub-task
16 | # the sub-tasks are encapsulated within methods below
17 | def perform_test
18 | out_hash = Hash.new
19 |
20 | # create private and public test directories
21 | dirname_private = create_private_test_directory
22 | dirname_public = create_public_test_directory
23 |
24 | out_hash[:dirname_private] = dirname_private
25 | out_hash[:dirname_public] = dirname_public
26 |
27 | # upload files
28 | public_file = upload_example_file_1 dirname_public
29 | private_file = upload_example_file_2 dirname_private
30 |
31 | # list file urls
32 | out_hash[:private_file_temp_url] = generate_temp_url private_file
33 | out_hash[:public_file_url] = "#{public_file.public_url}"
34 |
35 | # list directory contents
36 | out_hash[:directory_contents_public] = list_directory_string dirname_public
37 | out_hash[:directory_contents_private] = list_directory_string dirname_private
38 |
39 | out_hash
40 | end
41 |
42 | # --------------------------------------------------------------------------
43 | # sub-methods for performing the test --------------------------------------
44 | # --------------------------------------------------------------------------
45 |
46 | # directory functions -------------------------------------
47 |
48 | # creates a directory with the given name on swift
49 | def create_swift_directory(dirname)
50 | puts "Creating Directory #{dirname}"
51 | dir = @storage.create_dir(dirname)
52 | { :dirname => dirname, :dir => dir }
53 | end
54 |
55 | # creates a private test directory on the swift server
56 | # returns the name of the test directory
57 | def create_private_test_directory
58 | dirname = "fog-swift-test-#{Time.now.to_i}"
59 | create_swift_directory dirname
60 | return dirname
61 | end
62 |
63 | # creates a public test directory on the swift server
64 | def create_public_test_directory
65 | dirname = "fog-swift-test-public-#{Time.now.to_i}"
66 | ha = create_swift_directory dirname
67 | @storage.make_directory_public ha[:dir]
68 | return ha[:dirname]
69 | end
70 |
71 | # returns a string with a listing of the files within
72 | # the directory with the given name
73 | def list_directory_string(dirname)
74 | "#{@storage.list_dir(dirname)}"
75 | end
76 |
77 |
78 | # file interaction -------------------------------------
79 |
80 | # uploads the file on the given location to the given directory
81 | # returns the file descriptor for the uploaded file
82 | def upload_file(file_location, file_name, dirname)
83 | puts "Uploading file"
84 | file = @storage.upload_file dirname, file_location, file_name
85 | end
86 |
87 | # uploads the picture.jpg file to the given directory
88 | def upload_example_file_1(dirname)
89 | file_location = Rails.root.to_s + "/public/picture.jpg"
90 | upload_file file_location, "picture.jpg", dirname
91 | end
92 |
93 | # uploads the public/swift_test.html file to the given directory
94 | def upload_example_file_2(dirname)
95 | file_location = Rails.root.to_s + "/public/swift_test.html"
96 | upload_file file_location, "swift_test.html", dirname
97 | end
98 |
99 | # deletes the file referenced by the given file descriptor
100 | # in the given directory on swift
101 | def delete_example_file (file, dirname)
102 | puts "Deleting the file: #{file.inspect} from directory #{dirname}"
103 | @storage.delete_file file.key, dirname
104 | end
105 |
106 | # generates a temporary url for the given file
107 | # returns a url as string
108 | def generate_temp_url(file)
109 | @storage.create_temp_url file
110 | end
111 |
112 | # fog swift configuration ----------------------------
113 |
114 | # reads the swift credentials from the environment variable
115 | # returns a hash with the credentials delivered by the VCAP_SERVICES env variable
116 | def get_swift_credentials_hash
117 | vcap_services_env_str = ENV["VCAP_SERVICES"]
118 | raise "please set ENV variable VCAP_SERVICES" unless vcap_services_env_str
119 | vcap_services_hash = JSON.parse vcap_services_env_str
120 | swift_credentials_hash = vcap_services_hash["swift-1.0"].first["credentials"]
121 | end
122 |
123 | # creates a valid fog configuration hash from the credentials retrieved from the
124 | # swift service.
125 | # the hash consists of 2 main keys:
126 | # :fog - the fog credentials hash
127 | # :account_meta_key - the swift account meta key for generating temporary urls
128 | def fog_credentials_from_cf_swift_credentials(cf_swift_credentials)
129 |
130 | fog_hash = {
131 | :provider => 'HP',
132 | :hp_access_key => cf_swift_credentials["user_name"],
133 | :hp_secret_key => cf_swift_credentials["password"],
134 | :hp_tenant_id => cf_swift_credentials["tenant_id"],
135 | :hp_auth_uri => cf_swift_credentials["authentication_uri"],
136 | :hp_use_upass_auth_style => true,
137 | :hp_avl_zone => cf_swift_credentials["availability_zone"],
138 | :hp_auth_version => cf_swift_credentials["authentication_version"].to_sym,
139 | }
140 | ha = { :fog => fog_hash, :account_meta_key => cf_swift_credentials["account_meta_key"] }
141 | end
142 |
143 | end
144 | end
--------------------------------------------------------------------------------
/lib/tasks/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/lib/tasks/.gitkeep
--------------------------------------------------------------------------------
/log/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/log/.gitkeep
--------------------------------------------------------------------------------
/public/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/public/.DS_Store
--------------------------------------------------------------------------------
/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
The page you were looking for doesn't exist.
23 |
You may have mistyped the address or the page may have moved.
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/public/422.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The change you wanted was rejected (422)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
The change you wanted was rejected.
23 |
Maybe you tried to change something you didn't have access to.
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | We're sorry, but something went wrong (500)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
We're sorry, but something went wrong.
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Ruby on Rails: Welcome aboard
5 |
174 |
187 |
188 |
189 |
190 |
203 |
204 |
205 |
209 |
210 |
214 |
215 |
216 |
Getting started
217 |
Here’s how to get rolling:
218 |
219 |
220 | -
221 |
Use rails generate
to create your models and controllers
222 | To see all available options, run it without parameters.
223 |
224 |
225 | -
226 |
Set up a default route and remove public/index.html
227 | Routes are set up in config/routes.rb.
228 |
229 |
230 | -
231 |
Create your database
232 | Run rake db:create
to create your database. If you're not using SQLite (the default), edit config/database.yml with your username and password.
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
--------------------------------------------------------------------------------
/public/picture.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/public/picture.jpg
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2 | #
3 | # To ban all spiders from the entire site uncomment the next two lines:
4 | # User-Agent: *
5 | # Disallow: /
6 |
--------------------------------------------------------------------------------
/public/swift_test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Ruby on Rails: Welcome aboard
5 |
6 |
7 | Congratulations
8 | If you can access this page, the temporary file url creation is working...
9 |
10 |
--------------------------------------------------------------------------------
/script/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3 |
4 | APP_PATH = File.expand_path('../../config/application', __FILE__)
5 | require File.expand_path('../../config/boot', __FILE__)
6 | require 'rails/commands'
7 |
--------------------------------------------------------------------------------
/test/fixtures/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/test/fixtures/.gitkeep
--------------------------------------------------------------------------------
/test/functional/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/test/functional/.gitkeep
--------------------------------------------------------------------------------
/test/functional/swift_controller_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class SwiftControllerTest < ActionController::TestCase
4 | test "should get test_swift" do
5 | get :test_swift
6 | assert_response :success
7 | end
8 |
9 | test "should get read_environment" do
10 | get :read_environment
11 | assert_response :success
12 | end
13 |
14 | end
15 |
--------------------------------------------------------------------------------
/test/integration/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/test/integration/.gitkeep
--------------------------------------------------------------------------------
/test/performance/browsing_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 | require 'rails/performance_test_help'
3 |
4 | class BrowsingTest < ActionDispatch::PerformanceTest
5 | # Refer to the documentation for all available options
6 | # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
7 | # :output => 'tmp/performance', :formats => [:flat] }
8 |
9 | def test_homepage
10 | get '/'
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | ENV["RAILS_ENV"] = "test"
2 | require File.expand_path('../../config/environment', __FILE__)
3 | require 'rails/test_help'
4 |
5 | class ActiveSupport::TestCase
6 | # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
7 | #
8 | # Note: You'll currently still have to declare fixtures explicitly in integration tests
9 | # -- they do not yet inherit this setting
10 | fixtures :all
11 |
12 | # Add more helper methods to be used by all tests here...
13 | end
14 |
--------------------------------------------------------------------------------
/test/unit/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/test/unit/.gitkeep
--------------------------------------------------------------------------------
/test/unit/helpers/swift_helper_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class SwiftHelperTest < ActionView::TestCase
4 | end
5 |
--------------------------------------------------------------------------------
/vendor/assets/javascripts/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/vendor/assets/javascripts/.gitkeep
--------------------------------------------------------------------------------
/vendor/assets/stylesheets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/vendor/assets/stylesheets/.gitkeep
--------------------------------------------------------------------------------
/vendor/plugins/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anynines/swift-rails-example/581edeaabb914c48ac001ea66f123544416a5623/vendor/plugins/.gitkeep
--------------------------------------------------------------------------------