msgpack-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.markdown +71 -0
  3. data/Rakefile +37 -0
  4. data/lib/msgpack-rails.rb +11 -0
  5. data/lib/msgpack_rails/2-3/msgpack-rails.rb +5 -0
  6. data/lib/msgpack_rails/2-3/msgpack_serializer.rb +16 -0
  7. data/lib/msgpack_rails/3/activeresource_formats/msgpack_format.rb +25 -0
  8. data/lib/msgpack_rails/3/activeresource_formats.rb +5 -0
  9. data/lib/msgpack_rails/3/msgpack-rails.rb +2 -0
  10. data/lib/msgpack_rails/3/msgpack_serializer.rb +23 -0
  11. data/lib/msgpack_rails/core_ext.rb +19 -0
  12. data/lib/msgpack_rails/mime_type.rb +1 -0
  13. data/lib/msgpack_rails/version.rb +3 -0
  14. data/lib/tasks/msgpack-rails_tasks.rake +4 -0
  15. data/test/core_ext_test.rb +22 -0
  16. data/test/dummy/README +256 -0
  17. data/test/dummy/Rakefile +7 -0
  18. data/test/dummy/app/controllers/application_controller.rb +3 -0
  19. data/test/dummy/app/helpers/application_helper.rb +2 -0
  20. data/test/dummy/app/models/endpoint/person.rb +3 -0
  21. data/test/dummy/app/models/group.rb +3 -0
  22. data/test/dummy/app/models/person.rb +3 -0
  23. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  24. data/test/dummy/config/application.rb +42 -0
  25. data/test/dummy/config/boot.rb +6 -0
  26. data/test/dummy/config/database.yml +22 -0
  27. data/test/dummy/config/environment.rb +5 -0
  28. data/test/dummy/config/environments/development.rb +26 -0
  29. data/test/dummy/config/environments/production.rb +49 -0
  30. data/test/dummy/config/environments/test.rb +35 -0
  31. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  32. data/test/dummy/config/initializers/inflections.rb +10 -0
  33. data/test/dummy/config/initializers/mime_types.rb +5 -0
  34. data/test/dummy/config/initializers/secret_token.rb +7 -0
  35. data/test/dummy/config/initializers/session_store.rb +8 -0
  36. data/test/dummy/config/locales/en.yml +5 -0
  37. data/test/dummy/config/routes.rb +58 -0
  38. data/test/dummy/config.ru +4 -0
  39. data/test/dummy/db/development.sqlite3 +0 -0
  40. data/test/dummy/db/migrate/20110926220233_create_people.rb +16 -0
  41. data/test/dummy/db/migrate/20110926220327_create_groups.rb +14 -0
  42. data/test/dummy/db/schema.rb +32 -0
  43. data/test/dummy/db/seeds.rb +7 -0
  44. data/test/dummy/db/test.sqlite3 +0 -0
  45. data/test/dummy/doc/README_FOR_APP +2 -0
  46. data/test/dummy/log/development.log +65 -0
  47. data/test/dummy/log/production.log +0 -0
  48. data/test/dummy/log/server.log +0 -0
  49. data/test/dummy/log/test.log +4 -0
  50. data/test/dummy/public/404.html +26 -0
  51. data/test/dummy/public/422.html +26 -0
  52. data/test/dummy/public/500.html +26 -0
  53. data/test/dummy/public/favicon.ico +0 -0
  54. data/test/dummy/public/images/rails.png +0 -0
  55. data/test/dummy/public/index.html +239 -0
  56. data/test/dummy/public/javascripts/application.js +0 -0
  57. data/test/dummy/public/robots.txt +5 -0
  58. data/test/dummy/script/rails +6 -0
  59. data/test/dummy_2_3_14/Gemfile +3 -0
  60. data/test/dummy_2_3_14/Gemfile.lock +30 -0
  61. data/test/dummy_2_3_14/README +243 -0
  62. data/test/dummy_2_3_14/Rakefile +10 -0
  63. data/test/dummy_2_3_14/app/controllers/application_controller.rb +10 -0
  64. data/test/dummy_2_3_14/app/helpers/application_helper.rb +3 -0
  65. data/test/dummy_2_3_14/app/models/endpoint/person.rb +3 -0
  66. data/test/dummy_2_3_14/app/models/group.rb +3 -0
  67. data/test/dummy_2_3_14/app/models/person.rb +3 -0
  68. data/test/dummy_2_3_14/config/boot.rb +128 -0
  69. data/test/dummy_2_3_14/config/database.yml +22 -0
  70. data/test/dummy_2_3_14/config/environment.rb +41 -0
  71. data/test/dummy_2_3_14/config/environments/development.rb +17 -0
  72. data/test/dummy_2_3_14/config/environments/production.rb +28 -0
  73. data/test/dummy_2_3_14/config/environments/test.rb +28 -0
  74. data/test/dummy_2_3_14/config/initializers/backtrace_silencers.rb +7 -0
  75. data/test/dummy_2_3_14/config/initializers/cookie_verification_secret.rb +7 -0
  76. data/test/dummy_2_3_14/config/initializers/inflections.rb +10 -0
  77. data/test/dummy_2_3_14/config/initializers/mime_types.rb +5 -0
  78. data/test/dummy_2_3_14/config/initializers/new_rails_defaults.rb +21 -0
  79. data/test/dummy_2_3_14/config/initializers/session_store.rb +15 -0
  80. data/test/dummy_2_3_14/config/locales/en.yml +5 -0
  81. data/test/dummy_2_3_14/config/preinitializer.rb +20 -0
  82. data/test/dummy_2_3_14/config/routes.rb +43 -0
  83. data/test/dummy_2_3_14/db/development.sqlite3 +0 -0
  84. data/test/dummy_2_3_14/db/migrate/20110926220233_create_people.rb +16 -0
  85. data/test/dummy_2_3_14/db/migrate/20110926220327_create_groups.rb +14 -0
  86. data/test/dummy_2_3_14/db/schema.rb +30 -0
  87. data/test/dummy_2_3_14/db/seeds.rb +7 -0
  88. data/test/dummy_2_3_14/db/test.sqlite3 +0 -0
  89. data/test/dummy_2_3_14/doc/README_FOR_APP +2 -0
  90. data/test/dummy_2_3_14/log/development.log +74 -0
  91. data/test/dummy_2_3_14/log/production.log +0 -0
  92. data/test/dummy_2_3_14/log/server.log +0 -0
  93. data/test/dummy_2_3_14/log/test.log +0 -0
  94. data/test/dummy_2_3_14/public/404.html +30 -0
  95. data/test/dummy_2_3_14/public/422.html +30 -0
  96. data/test/dummy_2_3_14/public/500.html +30 -0
  97. data/test/dummy_2_3_14/public/favicon.ico +0 -0
  98. data/test/dummy_2_3_14/public/images/rails.png +0 -0
  99. data/test/dummy_2_3_14/public/index.html +275 -0
  100. data/test/dummy_2_3_14/public/javascripts/application.js +2 -0
  101. data/test/dummy_2_3_14/public/javascripts/controls.js +963 -0
  102. data/test/dummy_2_3_14/public/javascripts/dragdrop.js +973 -0
  103. data/test/dummy_2_3_14/public/javascripts/effects.js +1128 -0
  104. data/test/dummy_2_3_14/public/javascripts/prototype.js +4320 -0
  105. data/test/dummy_2_3_14/public/robots.txt +5 -0
  106. data/test/dummy_2_3_14/script/about +4 -0
  107. data/test/dummy_2_3_14/script/console +3 -0
  108. data/test/dummy_2_3_14/script/dbconsole +3 -0
  109. data/test/dummy_2_3_14/script/destroy +3 -0
  110. data/test/dummy_2_3_14/script/generate +3 -0
  111. data/test/dummy_2_3_14/script/performance/benchmarker +3 -0
  112. data/test/dummy_2_3_14/script/performance/profiler +3 -0
  113. data/test/dummy_2_3_14/script/plugin +3 -0
  114. data/test/dummy_2_3_14/script/runner +3 -0
  115. data/test/dummy_2_3_14/script/server +3 -0
  116. data/test/msgpack_assertion_files/date.mpac +1 -0
  117. data/test/msgpack_assertion_files/datetime.mpac +1 -0
  118. data/test/msgpack_assertion_files/time.mpac +1 -0
  119. data/test/msgpack_format_test.rb +55 -0
  120. data/test/msgpack_rails_test.rb +7 -0
  121. data/test/msgpack_serializer_test.rb +25 -0
  122. data/test/test_helper.rb +19 -0
  123. metadata +339 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 Nathan Benes
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,71 @@
1
+ # MsgpackRails
2
+
3
+ Uses the fast and compact [msgpack](https://github.com/msgpack/msgpack 'MessagePack') binary format to let you serialize objects.
4
+
5
+ ## Installation
6
+
7
+ In your Gemfile include the following line:
8
+
9
+ gem 'msgpack-rails', :git => 'git://github.com/nzifnab/msgpack-rails.git'
10
+
11
+ ## Usage
12
+
13
+ To encode objects use [msgpack's](https://github.com/msgpack/msgpack 'MessagePack') `to_msgpack` method:
14
+
15
+ @person = Person.new(:first_name => 'bob', :last_name => 'joe')
16
+ @person.to_msgpack
17
+
18
+ In your controller's render action (to be consumed as an API like ActiveResource):
19
+
20
+ respond_to do |format|
21
+ format.mpac { render :text => @person.to_msgpack, :content_type => 'application/x-mpac' }
22
+ end
23
+
24
+ Additionally you can set up ActiveResource to accept :mpac content types:
25
+
26
+ class Animal < ActiveResource::Base
27
+ self.format = :mpac
28
+ end
29
+
30
+ # Meanwhile, across the desert...
31
+
32
+ Animal.find(1) # => Expects the content to be in the msgpack format
33
+
34
+ ## Gotchas
35
+
36
+ 1. Serialization options hash
37
+
38
+ It is currently more limiting than `to_json` or `to_xml` in that the 'options' hash does not (yet) work. If you want the equivalent of this from json:
39
+
40
+ @person.to_json(:include => [:group], :methods => [:monkey_see])
41
+
42
+ Then you have to generate it as a hash manually:
43
+
44
+ @person.serializable_hash(:include => [:group], :methods => [:monkey_see]).to_msgpack
45
+
46
+ I plan on finding a way to get this working as the other two format methods do, but for now this work-around should be fine.
47
+
48
+ 2. Date formats
49
+
50
+ The msgpack gem (written in C) does not natively serialize date formats. Instead, I convert the dates to a string and send them that way.
51
+ This is bad, because they are seen by the ActiveResource endpoint as a string and are not converted to a date. You need to keep this in mind and may have to
52
+ use `to_datetime` on dates in those models.
53
+
54
+ ## TODO
55
+
56
+ 1) Fix the two gotchas mentioned above
57
+
58
+ 2) Better render support in the controller (something like `render :mpac => @person.to_msgpack` without the `:content_type` requirement)
59
+
60
+ 3) Better support and testing for rails 2.3 (maybe, but low priority)
61
+
62
+ ## Contributing
63
+
64
+ If you use or are interested in the msgpack gem (even by itself) and want to or already do use it in Rails (with or without this msgpack-rails gem) I would
65
+ love to hear about your experiences! What did you do to get it to work for you?
66
+
67
+ If you have suggestions, ideas, or have taken a look at this gem's code and want to help improve it (fixing bugs, adding additional features, etc) then that's great!
68
+ Fork the project, make a 'feature branch' with your suggested changes (preferably one major 'feature' per branch/pull request), and then do a pull request from that
69
+ branch. Feel free to discuss with me ideas etc in the issues tracker here on github.
70
+
71
+ This project is licensed under the MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'MsgpackRails'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task :default => :test
@@ -0,0 +1,11 @@
1
+ require 'msgpack'
2
+ require "msgpack_rails/core_ext"
3
+ require 'msgpack_rails/mime_type'
4
+ if Rails::VERSION::MAJOR == 2
5
+ require 'msgpack_rails/2-3/msgpack-rails'
6
+ else
7
+ require 'msgpack_rails/3/msgpack-rails'
8
+ end
9
+
10
+ module MsgpackRails
11
+ end
@@ -0,0 +1,5 @@
1
+ # For legacy purposes I've added support for rails 2.3.x object serialization.
2
+ # Don't expect too many updates to this support, going forward all updates will be for
3
+ # newer versions of rails.
4
+
5
+ require 'msgpack_rails/2-3/msgpack_serializer'
@@ -0,0 +1,16 @@
1
+ module ActiveRecord
2
+ module Serialization
3
+ def to_msgpack(options = {})
4
+ options = {:out => options} if options.is_a?(String)
5
+ options[:out] ||= ''
6
+
7
+ options[:out] << MsgpackSerializer.new(self).to_s
8
+ end
9
+
10
+ class MsgpackSerializer < ActiveRecord::Serialization::Serializer
11
+ def serialize
12
+ MessagePack.pack(serializable_record)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ module ActiveResource
2
+ module Formats
3
+ module MsgpackFormat
4
+ extend self
5
+
6
+ def extension
7
+ "mpac"
8
+ end
9
+
10
+ def mime_type
11
+ Mime::MPAC.to_s
12
+ end
13
+
14
+ # Options hash currently serves no function.
15
+ # TODO: Fix it, duh. Just like the Serializer's issue
16
+ def encode(hash, options = nil)
17
+ hash.to_msgpack
18
+ end
19
+
20
+ def decode(mpac)
21
+ MessagePack.unpack(mpac)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveResource
2
+ module Formats
3
+ autoload :MsgpackFormat, 'msgpack_rails/3/activeresource_formats/msgpack_format'
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "msgpack_rails/3/msgpack_serializer"
2
+ require 'msgpack_rails/3/activeresource_formats'
@@ -0,0 +1,23 @@
1
+ module ActiveModel
2
+ module Serializers
3
+ module Msgpack
4
+ def to_msgpack(options = {})
5
+ options = {:out => options} if options.is_a?(String)
6
+ options[:out] ||= ''
7
+
8
+ options[:out] << serializable_hash(options).to_msgpack
9
+ end
10
+
11
+ # TODO: Test and uncomment this method
12
+ #def from_msgpack(msg)
13
+ # MessagePack.unpack(msg)
14
+ #end
15
+ end
16
+ end
17
+ end
18
+
19
+ module ActiveRecord
20
+ module Serialization
21
+ include ActiveModel::Serializers::Msgpack
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+
3
+ Time.class_eval do
4
+ def to_msgpack(out='')
5
+ self.to_s.to_msgpack(out)
6
+ end
7
+ end
8
+
9
+ DateTime.class_eval do
10
+ def to_msgpack(out='')
11
+ self.to_s.to_msgpack(out)
12
+ end
13
+ end
14
+
15
+ Date.class_eval do
16
+ def to_msgpack(out='')
17
+ self.to_s.to_msgpack(out)
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ Mime::Type.register "application/x-mpac", :mpac
@@ -0,0 +1,3 @@
1
+ module MsgpackRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :msgpack-rails do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ class TimeExtTest < Test::Unit::TestCase
4
+ def test_to_msgpack_renders_as_string
5
+ str = File.open(File.join(File.dirname(__FILE__), "msgpack_assertion_files", "time.mpac")).read
6
+ assert_equal str, "January 4, 2011 2:34:17 PM".to_time.utc.to_msgpack
7
+ end
8
+ end
9
+
10
+ class DateTimeExtTest < Test::Unit::TestCase
11
+ def test_to_msgpack_renders_as_string
12
+ str = File.open(File.join(File.dirname(__FILE__), "msgpack_assertion_files", "datetime.mpac")).read
13
+ assert_equal str, "February 3 2010 4:15:09 AM".to_datetime.utc.to_msgpack
14
+ end
15
+ end
16
+
17
+ class DateExtTest < Test::Unit::TestCase
18
+ def test_to_msgpack_renders_as_string
19
+ str = File.open(File.join(File.dirname(__FILE__), "msgpack_assertion_files", "date.mpac")).read
20
+ assert_equal str, "March 23 2011".to_date.to_msgpack
21
+ end
22
+ end
data/test/dummy/README ADDED
@@ -0,0 +1,256 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb"
7
+ templates that are primarily responsible for inserting pre-built data in between
8
+ HTML tags. The model contains the "smart" domain objects (such as Account,
9
+ Product, Person, Post) that holds all the business logic and knows how to
10
+ persist themselves to a database. The controller handles the incoming requests
11
+ (such as Save New Account, Update Product, Show Post) by manipulating the model
12
+ and directing data to the view.
13
+
14
+ In Rails, the model is handled by what's called an object-relational mapping
15
+ layer entitled Active Record. This layer allows you to present the data from
16
+ database rows as objects and embellish these data objects with business logic
17
+ methods. You can read more about Active Record in
18
+ link:files/vendor/rails/activerecord/README.html.
19
+
20
+ The controller and view are handled by the Action Pack, which handles both
21
+ layers by its two parts: Action View and Action Controller. These two layers
22
+ are bundled in a single package due to their heavy interdependence. This is
23
+ unlike the relationship between the Active Record and Action Pack that is much
24
+ more separate. Each of these packages can be used independently outside of
25
+ Rails. You can read more about Action Pack in
26
+ link:files/vendor/rails/actionpack/README.html.
27
+
28
+
29
+ == Getting Started
30
+
31
+ 1. At the command prompt, create a new Rails application:
32
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
33
+
34
+ 2. Change directory to <tt>myapp</tt> and start the web server:
35
+ <tt>cd myapp; rails server</tt> (run with --help for options)
36
+
37
+ 3. Go to http://localhost:3000/ and you'll see:
38
+ "Welcome aboard: You're riding Ruby on Rails!"
39
+
40
+ 4. Follow the guidelines to start developing your application. You can find
41
+ the following resources handy:
42
+
43
+ * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
+ * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
+
46
+
47
+ == Debugging Rails
48
+
49
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
50
+ will help you debug it and get it back on the rails.
51
+
52
+ First area to check is the application log files. Have "tail -f" commands
53
+ running on the server.log and development.log. Rails will automatically display
54
+ debugging and runtime information to these files. Debugging info will also be
55
+ shown in the browser on requests from 127.0.0.1.
56
+
57
+ You can also log your own messages directly into the log file from your code
58
+ using the Ruby logger class from inside your controllers. Example:
59
+
60
+ class WeblogController < ActionController::Base
61
+ def destroy
62
+ @weblog = Weblog.find(params[:id])
63
+ @weblog.destroy
64
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65
+ end
66
+ end
67
+
68
+ The result will be a message in your log file along the lines of:
69
+
70
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71
+
72
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
73
+
74
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75
+ several books available online as well:
76
+
77
+ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79
+
80
+ These two books will bring you up to speed on the Ruby language and also on
81
+ programming in general.
82
+
83
+
84
+ == Debugger
85
+
86
+ Debugger support is available through the debugger command when you start your
87
+ Mongrel or WEBrick server with --debugger. This means that you can break out of
88
+ execution at any point in the code, investigate and change the model, and then,
89
+ resume execution! You need to install ruby-debug to run the server in debugging
90
+ mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
91
+
92
+ class WeblogController < ActionController::Base
93
+ def index
94
+ @posts = Post.find(:all)
95
+ debugger
96
+ end
97
+ end
98
+
99
+ So the controller will accept the action, run the first line, then present you
100
+ with a IRB prompt in the server window. Here you can do things like:
101
+
102
+ >> @posts.inspect
103
+ => "[#<Post:0x14a6be8
104
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
105
+ #<Post:0x14a6620
106
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107
+ >> @posts.first.title = "hello from a debugger"
108
+ => "hello from a debugger"
109
+
110
+ ...and even better, you can examine how your runtime objects actually work:
111
+
112
+ >> f = @posts.first
113
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
114
+ >> f.
115
+ Display all 152 possibilities? (y or n)
116
+
117
+ Finally, when you're ready to resume execution, you can enter "cont".
118
+
119
+
120
+ == Console
121
+
122
+ The console is a Ruby shell, which allows you to interact with your
123
+ application's domain model. Here you'll have all parts of the application
124
+ configured, just like it is when the application is running. You can inspect
125
+ domain models, change values, and save to the database. Starting the script
126
+ without arguments will launch it in the development environment.
127
+
128
+ To start the console, run <tt>rails console</tt> from the application
129
+ directory.
130
+
131
+ Options:
132
+
133
+ * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
134
+ made to the database.
135
+ * Passing an environment name as an argument will load the corresponding
136
+ environment. Example: <tt>rails console production</tt>.
137
+
138
+ To reload your controllers and models after launching the console run
139
+ <tt>reload!</tt>
140
+
141
+ More information about irb can be found at:
142
+ link:http://www.rubycentral.com/pickaxe/irb.html
143
+
144
+
145
+ == dbconsole
146
+
147
+ You can go to the command line of your database directly through <tt>rails
148
+ dbconsole</tt>. You would be connected to the database with the credentials
149
+ defined in database.yml. Starting the script without arguments will connect you
150
+ to the development database. Passing an argument will connect you to a different
151
+ database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
152
+ PostgreSQL and SQLite 3.
153
+
154
+ == Description of Contents
155
+
156
+ The default directory structure of a generated Ruby on Rails application:
157
+
158
+ |-- app
159
+ | |-- controllers
160
+ | |-- helpers
161
+ | |-- mailers
162
+ | |-- models
163
+ | `-- views
164
+ | `-- layouts
165
+ |-- config
166
+ | |-- environments
167
+ | |-- initializers
168
+ | `-- locales
169
+ |-- db
170
+ |-- doc
171
+ |-- lib
172
+ | `-- tasks
173
+ |-- log
174
+ |-- public
175
+ | |-- images
176
+ | |-- javascripts
177
+ | `-- stylesheets
178
+ |-- script
179
+ |-- test
180
+ | |-- fixtures
181
+ | |-- functional
182
+ | |-- integration
183
+ | |-- performance
184
+ | `-- unit
185
+ |-- tmp
186
+ | |-- cache
187
+ | |-- pids
188
+ | |-- sessions
189
+ | `-- sockets
190
+ `-- vendor
191
+ `-- plugins
192
+
193
+ app
194
+ Holds all the code that's specific to this particular application.
195
+
196
+ app/controllers
197
+ Holds controllers that should be named like weblogs_controller.rb for
198
+ automated URL mapping. All controllers should descend from
199
+ ApplicationController which itself descends from ActionController::Base.
200
+
201
+ app/models
202
+ Holds models that should be named like post.rb. Models descend from
203
+ ActiveRecord::Base by default.
204
+
205
+ app/views
206
+ Holds the template files for the view that should be named like
207
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
208
+ eRuby syntax by default.
209
+
210
+ app/views/layouts
211
+ Holds the template files for layouts to be used with views. This models the
212
+ common header/footer method of wrapping views. In your views, define a layout
213
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
214
+ Inside default.html.erb, call <% yield %> to render the view using this
215
+ layout.
216
+
217
+ app/helpers
218
+ Holds view helpers that should be named like weblogs_helper.rb. These are
219
+ generated for you automatically when using generators for controllers.
220
+ Helpers can be used to wrap functionality for your views into methods.
221
+
222
+ config
223
+ Configuration files for the Rails environment, the routing map, the database,
224
+ and other dependencies.
225
+
226
+ db
227
+ Contains the database schema in schema.rb. db/migrate contains all the
228
+ sequence of Migrations for your schema.
229
+
230
+ doc
231
+ This directory is where your application documentation will be stored when
232
+ generated using <tt>rake doc:app</tt>
233
+
234
+ lib
235
+ Application specific libraries. Basically, any kind of custom code that
236
+ doesn't belong under controllers, models, or helpers. This directory is in
237
+ the load path.
238
+
239
+ public
240
+ The directory available for the web server. Contains subdirectories for
241
+ images, stylesheets, and javascripts. Also contains the dispatchers and the
242
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
243
+ server.
244
+
245
+ script
246
+ Helper scripts for automation and generation.
247
+
248
+ test
249
+ Unit and functional tests along with fixtures. When using the rails generate
250
+ command, template test files will be generated for you and placed in this
251
+ directory.
252
+
253
+ vendor
254
+ External libraries that the application depends on. Also includes the plugins
255
+ subdirectory. If the app has frozen rails, those gems also go here, under
256
+ vendor/rails/. This directory is in the load path.
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ class Endpoint::Person < ActiveResource::Base
2
+ self.site = "http://www.example.com"
3
+ end
@@ -0,0 +1,3 @@
1
+ class Group < ActiveRecord::Base
2
+ has_many :people
3
+ end
@@ -0,0 +1,3 @@
1
+ class Person < ActiveRecord::Base
2
+ belongs_to :group
3
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,42 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ # If you have a Gemfile, require the gems listed there, including any gems
6
+ # you've limited to :test, :development, or :production.
7
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
8
+
9
+ module Dummy
10
+ class Application < Rails::Application
11
+ # Settings in config/environments/* take precedence over those specified here.
12
+ # Application configuration should go into files in config/initializers
13
+ # -- all .rb files in that directory are automatically loaded.
14
+
15
+ # Custom directories with classes and modules you want to be autoloadable.
16
+ # config.autoload_paths += %W(#{config.root}/extras)
17
+
18
+ # Only load the plugins named here, in the order given (default is alphabetical).
19
+ # :all can be used as a placeholder for all plugins not explicitly named.
20
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
21
+
22
+ # Activate observers that should always be running.
23
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
24
+
25
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
26
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
27
+ # config.time_zone = 'Central Time (US & Canada)'
28
+
29
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
30
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
31
+ # config.i18n.default_locale = :de
32
+
33
+ # JavaScript files you want as :defaults (application.js is always included).
34
+ config.action_view.javascript_expansions[:defaults] = %w()
35
+
36
+ # Configure the default encoding used in templates for Ruby 1.9.
37
+ config.encoding = "utf-8"
38
+
39
+ # Configure sensitive parameters which will be filtered from the log file.
40
+ config.filter_parameters += [:password]
41
+ end
42
+ end
@@ -0,0 +1,6 @@
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'])
@@ -0,0 +1,22 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ # Warning: The database defined as "test" will be erased and
10
+ # re-generated from your development database when you run "rake".
11
+ # Do not set this db to the same as development or production.
12
+ test:
13
+ adapter: sqlite3
14
+ database: db/test.sqlite3
15
+ pool: 5
16
+ timeout: 5000
17
+
18
+ production:
19
+ adapter: sqlite3
20
+ database: db/production.sqlite3
21
+ pool: 5
22
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!