serializer 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +23 -0
- data/lib/serializer.rb +4 -4
- data/lib/serializer/version.rb +1 -1
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +3 -0
- data/test/dummy/app/assets/javascripts/main.js +0 -0
- data/test/dummy/app/assets/javascripts/users.js +0 -0
- data/test/dummy/app/assets/stylesheets/application.css +16 -0
- data/test/dummy/app/assets/stylesheets/main.css +4 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/assets/stylesheets/users.css +4 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/main_controller.rb +10 -0
- data/test/dummy/app/controllers/users_controller.rb +57 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/main_helper.rb +2 -0
- data/test/dummy/app/helpers/users_helper.rb +2 -0
- data/test/dummy/app/models/user.rb +8 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/main/index.html.erb +5 -0
- data/test/dummy/app/views/users/_form.html.erb +36 -0
- data/test/dummy/app/views/users/edit.html.erb +6 -0
- data/test/dummy/app/views/users/index.html.erb +25 -0
- data/test/dummy/app/views/users/new.html.erb +5 -0
- data/test/dummy/app/views/users/show.html.erb +24 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +45 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +17 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +30 -0
- data/test/dummy/config/environments/production.rb +60 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/other.rb +2 -0
- data/test/dummy/config/locales/en.yml +1 -0
- data/test/dummy/config/routes.rb +7 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20110927222742_create_users.rb +11 -0
- data/test/dummy/db/schema.rb +24 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +24 -0
- data/test/dummy/log/test.log +825 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/users.yml +11 -0
- data/test/dummy/test/functional/main_controller_test.rb +10 -0
- data/test/dummy/test/functional/users_controller_test.rb +52 -0
- data/test/dummy/test/integration/user_create_test.rb +17 -0
- data/test/dummy/test/integration/user_update_test.rb +17 -0
- data/test/dummy/test/unit/helpers/main_helper_test.rb +4 -0
- data/test/dummy/test/unit/helpers/users_helper_test.rb +4 -0
- data/test/dummy/test/unit/user_test.rb +55 -0
- data/test/serializer_test.rb +7 -0
- data/test/test_helper.rb +8 -0
- metadata +135 -6
- data/Gemfile +0 -3
data/Rakefile
CHANGED
@@ -1,2 +1,25 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
1
3
|
require 'bundler'
|
4
|
+
|
5
|
+
require 'rdoc/task'
|
6
|
+
require 'rake/testtask'
|
7
|
+
|
2
8
|
Bundler::GemHelper.install_tasks
|
9
|
+
|
10
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
11
|
+
rdoc.rdoc_dir = 'rdoc'
|
12
|
+
rdoc.title = 'Serializer'
|
13
|
+
rdoc.options << '--line-numbers'
|
14
|
+
rdoc.rdoc_files.include('README.rdoc')
|
15
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
16
|
+
end
|
17
|
+
|
18
|
+
Rake::TestTask.new(:test) do |t|
|
19
|
+
t.libs << 'lib'
|
20
|
+
t.libs << 'test'
|
21
|
+
t.pattern = 'test/**/*_test.rb'
|
22
|
+
t.verbose = false
|
23
|
+
end
|
24
|
+
|
25
|
+
task :default => :test
|
data/lib/serializer.rb
CHANGED
@@ -29,14 +29,14 @@ module Serializer
|
|
29
29
|
|
30
30
|
define_method "#{method}" do
|
31
31
|
hash = send(name)
|
32
|
-
result = hash[method.
|
32
|
+
result = hash[method.to_sym] if hash
|
33
33
|
return options[:default] if hash.nil? or result.nil?
|
34
34
|
return result
|
35
35
|
end
|
36
36
|
|
37
37
|
define_method "#{method}?" do
|
38
38
|
hash = send(name)
|
39
|
-
result = hash[method.
|
39
|
+
result = hash[method.to_sym] if hash
|
40
40
|
return options[:default] if hash.nil? or result.nil?
|
41
41
|
return result
|
42
42
|
end
|
@@ -46,7 +46,7 @@ module Serializer
|
|
46
46
|
hash = send(name)
|
47
47
|
|
48
48
|
if options[:type] and value
|
49
|
-
case options[:type].
|
49
|
+
case options[:type].to_sym
|
50
50
|
when :float then value = value.to_f if value.respond_to? :to_f
|
51
51
|
when :integer then value = value.to_i if value.respond_to? :to_i
|
52
52
|
when :string then value = value.to_str if value.respond_to? :to_str
|
@@ -55,7 +55,7 @@ module Serializer
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
send(name)[method.
|
58
|
+
send(name)[method.to_sym] = value
|
59
59
|
end
|
60
60
|
|
61
61
|
end
|
data/lib/serializer/version.rb
CHANGED
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
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
|
+
Dummy::Application.load_tasks
|
File without changes
|
File without changes
|
@@ -0,0 +1,56 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
div.field, div.actions {
|
20
|
+
margin-bottom: 10px;
|
21
|
+
}
|
22
|
+
|
23
|
+
#notice {
|
24
|
+
color: green;
|
25
|
+
}
|
26
|
+
|
27
|
+
.field_with_errors {
|
28
|
+
padding: 2px;
|
29
|
+
background-color: red;
|
30
|
+
display: table;
|
31
|
+
}
|
32
|
+
|
33
|
+
#error_explanation {
|
34
|
+
width: 450px;
|
35
|
+
border: 2px solid red;
|
36
|
+
padding: 7px;
|
37
|
+
padding-bottom: 0;
|
38
|
+
margin-bottom: 20px;
|
39
|
+
background-color: #f0f0f0;
|
40
|
+
}
|
41
|
+
|
42
|
+
#error_explanation h2 {
|
43
|
+
text-align: left;
|
44
|
+
font-weight: bold;
|
45
|
+
padding: 5px 5px 5px 15px;
|
46
|
+
font-size: 12px;
|
47
|
+
margin: -7px;
|
48
|
+
margin-bottom: 0px;
|
49
|
+
background-color: #c00;
|
50
|
+
color: #fff;
|
51
|
+
}
|
52
|
+
|
53
|
+
#error_explanation ul li {
|
54
|
+
font-size: 12px;
|
55
|
+
list-style: square;
|
56
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class UsersController < ApplicationController
|
2
|
+
|
3
|
+
respond_to :html
|
4
|
+
|
5
|
+
# GET /users
|
6
|
+
def index
|
7
|
+
@users = User.all
|
8
|
+
|
9
|
+
respond_with(@users)
|
10
|
+
end
|
11
|
+
|
12
|
+
# GET /users/:id
|
13
|
+
def show
|
14
|
+
@user = User.find(params[:id])
|
15
|
+
|
16
|
+
respond_with(@user)
|
17
|
+
end
|
18
|
+
|
19
|
+
# GET /users/new
|
20
|
+
def new
|
21
|
+
@user = User.new
|
22
|
+
|
23
|
+
respond_with(@user)
|
24
|
+
end
|
25
|
+
|
26
|
+
# GET /users/:id/edit
|
27
|
+
def edit
|
28
|
+
@user = User.find(params[:id])
|
29
|
+
|
30
|
+
respond_with(@user)
|
31
|
+
end
|
32
|
+
|
33
|
+
# POST /users
|
34
|
+
def create
|
35
|
+
@user = User.create(params[:user])
|
36
|
+
|
37
|
+
respond_with(@user)
|
38
|
+
end
|
39
|
+
|
40
|
+
# PUT /users/:id
|
41
|
+
def update
|
42
|
+
@user = User.find(params[:id])
|
43
|
+
@user.attributes = params[:user]
|
44
|
+
@user.save
|
45
|
+
|
46
|
+
respond_with(@user)
|
47
|
+
end
|
48
|
+
|
49
|
+
# DELETE /users/:id
|
50
|
+
def destroy
|
51
|
+
@user = User.find(params[:id])
|
52
|
+
@user.destroy
|
53
|
+
|
54
|
+
respond_with(@user)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<%= form_for(@user) do |f| %>
|
2
|
+
|
3
|
+
<% if @user.errors.any? %>
|
4
|
+
<p><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</p>
|
5
|
+
<ul>
|
6
|
+
<% @user.errors.each do |attribute, message| %>
|
7
|
+
<li><%= "#{attribute} : #{message}" %></li>
|
8
|
+
<% end %>
|
9
|
+
</ul>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<div class="field">
|
13
|
+
<%= f.label :name, "Name:" %><br />
|
14
|
+
<%= f.text_field :name %>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<div class="field">
|
18
|
+
<%= f.label :email, "Email:" %><br />
|
19
|
+
<%= f.text_field :email %>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<div class="field">
|
23
|
+
<%= f.check_box :fb_share %>
|
24
|
+
<%= f.label :fb_share, "FB Share" %>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
<div class="field">
|
28
|
+
<%= f.check_box :tw_share %>
|
29
|
+
<%= f.label :tw_share, "TW Share" %>
|
30
|
+
</div>
|
31
|
+
|
32
|
+
<div class="actions">
|
33
|
+
<%= f.submit %>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<% end %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<h1>Index</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>Name</th>
|
6
|
+
<th>Email</th>
|
7
|
+
<th></th>
|
8
|
+
<th></th>
|
9
|
+
<th></th>
|
10
|
+
</tr>
|
11
|
+
|
12
|
+
<% @users.each do |user| %>
|
13
|
+
<tr>
|
14
|
+
<td><%= user.name %></td>
|
15
|
+
<td><%= user.email %></td>
|
16
|
+
<td><%= link_to 'Show', user %></td>
|
17
|
+
<td><%= link_to 'Edit', edit_user_path(user) %></td>
|
18
|
+
<td><%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %></td>
|
19
|
+
</tr>
|
20
|
+
<% end %>
|
21
|
+
</table>
|
22
|
+
|
23
|
+
<br />
|
24
|
+
|
25
|
+
<%= link_to 'New User', new_user_path %>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<h1>Show</h1>
|
2
|
+
|
3
|
+
<p id="notice"><%= notice %></p>
|
4
|
+
|
5
|
+
<p>
|
6
|
+
<b>Name:</b>
|
7
|
+
<%= @user.name %>
|
8
|
+
</p>
|
9
|
+
|
10
|
+
<p>
|
11
|
+
<b>Email:</b>
|
12
|
+
<%= @user.email %>
|
13
|
+
</p>
|
14
|
+
|
15
|
+
<%- if @user.fb_share? -%>
|
16
|
+
<p>FB Share</p>
|
17
|
+
<%- end -%>
|
18
|
+
|
19
|
+
<%- if @user.tw_share? -%>
|
20
|
+
<p>TW Share</p>
|
21
|
+
<%- end -%>
|
22
|
+
|
23
|
+
<%= link_to 'Edit', edit_user_path(@user) %>
|
24
|
+
<%= link_to 'Back', users_path %>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require
|
6
|
+
require "serializer"
|
7
|
+
|
8
|
+
module Dummy
|
9
|
+
class Application < Rails::Application
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
15
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
16
|
+
|
17
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
18
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
19
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
20
|
+
|
21
|
+
# Activate observers that should always be running.
|
22
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
23
|
+
|
24
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
25
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
26
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
27
|
+
|
28
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
29
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
30
|
+
# config.i18n.default_locale = :de
|
31
|
+
|
32
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
33
|
+
config.encoding = "utf-8"
|
34
|
+
|
35
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
36
|
+
config.filter_parameters += [:password]
|
37
|
+
|
38
|
+
# Enable the asset pipeline
|
39
|
+
config.assets.enabled = true
|
40
|
+
|
41
|
+
# Version of your assets, change this if you want to expire all your assets
|
42
|
+
config.assets.version = '1.0'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|