file_record 0.1.0

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.
Files changed (67) hide show
  1. data/.gitignore +12 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +107 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +66 -0
  7. data/Rakefile +31 -0
  8. data/file_record.gemspec +23 -0
  9. data/lib/file_record/attribute_management.rb +32 -0
  10. data/lib/file_record/attribute_methods/all.rb +11 -0
  11. data/lib/file_record/attribute_methods/dirty.rb +22 -0
  12. data/lib/file_record/attribute_methods/read.rb +24 -0
  13. data/lib/file_record/attribute_methods/validation.rb +17 -0
  14. data/lib/file_record/attribute_methods/write.rb +22 -0
  15. data/lib/file_record/attribute_methods.rb +10 -0
  16. data/lib/file_record/base.rb +19 -0
  17. data/lib/file_record/callbacks.rb +20 -0
  18. data/lib/file_record/compatibility.rb +11 -0
  19. data/lib/file_record/persistence.rb +53 -0
  20. data/lib/file_record/validations.rb +15 -0
  21. data/lib/file_record.rb +9 -0
  22. data/test/dummy/Rakefile +7 -0
  23. data/test/dummy/app/controllers/addresses_controller.rb +83 -0
  24. data/test/dummy/app/controllers/application_controller.rb +3 -0
  25. data/test/dummy/app/helpers/addresses_helper.rb +2 -0
  26. data/test/dummy/app/helpers/application_helper.rb +2 -0
  27. data/test/dummy/app/models/address.rb +10 -0
  28. data/test/dummy/app/views/addresses/_form.html.erb +32 -0
  29. data/test/dummy/app/views/addresses/edit.html.erb +6 -0
  30. data/test/dummy/app/views/addresses/index.html.erb +25 -0
  31. data/test/dummy/app/views/addresses/new.html.erb +5 -0
  32. data/test/dummy/app/views/addresses/show.html.erb +15 -0
  33. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  34. data/test/dummy/config/application.rb +45 -0
  35. data/test/dummy/config/boot.rb +10 -0
  36. data/test/dummy/config/database.yml +22 -0
  37. data/test/dummy/config/environment.rb +5 -0
  38. data/test/dummy/config/environments/development.rb +26 -0
  39. data/test/dummy/config/environments/production.rb +49 -0
  40. data/test/dummy/config/environments/test.rb +35 -0
  41. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  42. data/test/dummy/config/initializers/inflections.rb +10 -0
  43. data/test/dummy/config/initializers/mime_types.rb +5 -0
  44. data/test/dummy/config/initializers/secret_token.rb +7 -0
  45. data/test/dummy/config/initializers/session_store.rb +8 -0
  46. data/test/dummy/config/locales/en.yml +5 -0
  47. data/test/dummy/config/routes.rb +60 -0
  48. data/test/dummy/config.ru +4 -0
  49. data/test/dummy/public/404.html +26 -0
  50. data/test/dummy/public/422.html +26 -0
  51. data/test/dummy/public/500.html +26 -0
  52. data/test/dummy/public/favicon.ico +0 -0
  53. data/test/dummy/public/javascripts/application.js +2 -0
  54. data/test/dummy/public/javascripts/controls.js +965 -0
  55. data/test/dummy/public/javascripts/dragdrop.js +974 -0
  56. data/test/dummy/public/javascripts/effects.js +1123 -0
  57. data/test/dummy/public/javascripts/prototype.js +6001 -0
  58. data/test/dummy/public/javascripts/rails.js +191 -0
  59. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  60. data/test/dummy/public/stylesheets/scaffold.css +56 -0
  61. data/test/dummy/script/rails +6 -0
  62. data/test/dummy/tmp/file_records/.gitkeep +0 -0
  63. data/test/file_record_test.rb +187 -0
  64. data/test/integration/navigation_test.rb +7 -0
  65. data/test/support/integration_case.rb +5 -0
  66. data/test/test_helper.rb +22 -0
  67. metadata +201 -0
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/log/*.log
6
+ test/dummy/tmp/pids/
7
+ test/dummy/tmp/cache/
8
+ test/dummy/tmp/sessions/
9
+ test/dummy/tmp/sockets/
10
+ test/dummy/tmp/file_records/*
11
+ *~
12
+ *.swp
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ruby-1.9.2-p180@file_record
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,107 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ file_record (0.1.0)
5
+ rails (~> 3.0.4)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ abstract (1.0.0)
11
+ actionmailer (3.0.4)
12
+ actionpack (= 3.0.4)
13
+ mail (~> 2.2.15)
14
+ actionpack (3.0.4)
15
+ activemodel (= 3.0.4)
16
+ activesupport (= 3.0.4)
17
+ builder (~> 2.1.2)
18
+ erubis (~> 2.6.6)
19
+ i18n (~> 0.4)
20
+ rack (~> 1.2.1)
21
+ rack-mount (~> 0.6.13)
22
+ rack-test (~> 0.5.7)
23
+ tzinfo (~> 0.3.23)
24
+ activemodel (3.0.4)
25
+ activesupport (= 3.0.4)
26
+ builder (~> 2.1.2)
27
+ i18n (~> 0.4)
28
+ activerecord (3.0.4)
29
+ activemodel (= 3.0.4)
30
+ activesupport (= 3.0.4)
31
+ arel (~> 2.0.2)
32
+ tzinfo (~> 0.3.23)
33
+ activeresource (3.0.4)
34
+ activemodel (= 3.0.4)
35
+ activesupport (= 3.0.4)
36
+ activesupport (3.0.4)
37
+ arel (2.0.8)
38
+ builder (2.1.2)
39
+ capybara (0.4.1.1)
40
+ celerity (>= 0.7.9)
41
+ culerity (>= 0.2.4)
42
+ mime-types (>= 1.16)
43
+ nokogiri (>= 1.3.3)
44
+ rack (>= 1.0.0)
45
+ rack-test (>= 0.5.4)
46
+ selenium-webdriver (>= 0.0.27)
47
+ xpath (~> 0.1.3)
48
+ celerity (0.8.7)
49
+ childprocess (0.1.6)
50
+ ffi (~> 0.6.3)
51
+ culerity (0.2.15)
52
+ erubis (2.6.6)
53
+ abstract (>= 1.0.0)
54
+ ffi (0.6.3)
55
+ rake (>= 0.8.7)
56
+ i18n (0.5.0)
57
+ json_pure (1.5.1)
58
+ mail (2.2.15)
59
+ activesupport (>= 2.3.6)
60
+ i18n (>= 0.4.0)
61
+ mime-types (~> 1.16)
62
+ treetop (~> 1.4.8)
63
+ mime-types (1.16)
64
+ nokogiri (1.4.4)
65
+ polyglot (0.3.1)
66
+ rack (1.2.1)
67
+ rack-mount (0.6.13)
68
+ rack (>= 1.0.0)
69
+ rack-test (0.5.7)
70
+ rack (>= 1.0)
71
+ rails (3.0.4)
72
+ actionmailer (= 3.0.4)
73
+ actionpack (= 3.0.4)
74
+ activerecord (= 3.0.4)
75
+ activeresource (= 3.0.4)
76
+ activesupport (= 3.0.4)
77
+ bundler (~> 1.0)
78
+ railties (= 3.0.4)
79
+ railties (3.0.4)
80
+ actionpack (= 3.0.4)
81
+ activesupport (= 3.0.4)
82
+ rake (>= 0.8.7)
83
+ thor (~> 0.14.4)
84
+ rake (0.8.7)
85
+ rubyzip (0.9.4)
86
+ selenium-webdriver (0.1.2)
87
+ childprocess (~> 0.1.5)
88
+ ffi (~> 0.6.3)
89
+ json_pure
90
+ rubyzip
91
+ sqlite3 (1.3.3)
92
+ sqlite3-ruby (1.3.3)
93
+ sqlite3 (>= 1.3.3)
94
+ thor (0.14.6)
95
+ treetop (1.4.9)
96
+ polyglot (>= 0.3.1)
97
+ tzinfo (0.3.24)
98
+ xpath (0.1.3)
99
+ nokogiri (~> 1.3)
100
+
101
+ PLATFORMS
102
+ ruby
103
+
104
+ DEPENDENCIES
105
+ capybara
106
+ file_record!
107
+ sqlite3-ruby
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 Michal Taszycki
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.md ADDED
@@ -0,0 +1,66 @@
1
+ FileRecord
2
+ ==========
3
+
4
+ Simplistic implementation of persistent model library.
5
+ Inspired by ActiveRecord. And fully compatible with ActiveModel.
6
+
7
+ Created alongside the presentation [Digging into Rails 3.x internals - ActiveModel][0]
8
+
9
+ Installation
10
+ ------------
11
+
12
+ git clone git://github.com/mehowte/file_record.git
13
+ cd file_record
14
+ bundle install
15
+
16
+ Documentation
17
+ ------------
18
+
19
+ 1. See [the presentation][0]
20
+
21
+ 2. Look into
22
+ test
23
+ and
24
+ test/dummy directory.
25
+
26
+ Running tests
27
+ -------
28
+
29
+ rake
30
+
31
+ Running demo app
32
+ --------
33
+ cd test/dummy
34
+ rails server
35
+
36
+ ... and then visit [addresses index on localhost](http://localhost:3000/addresses)
37
+
38
+ models will be saved into
39
+
40
+ test/dummy/tmp/file_records
41
+
42
+ License
43
+ -------
44
+ Copyright 2011 Michal Taszycki
45
+
46
+ Permission is hereby granted, free of charge, to any person obtaining
47
+ a copy of this software and associated documentation files (the
48
+ "Software"), to deal in the Software without restriction, including
49
+ without limitation the rights to use, copy, modify, merge, publish,
50
+ distribute, sublicense, and/or sell copies of the Software, and to
51
+ permit persons to whom the Software is furnished to do so, subject to
52
+ the following conditions:
53
+
54
+ The above copyright notice and this permission notice shall be
55
+ included in all copies or substantial portions of the Software.
56
+
57
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
58
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
59
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
60
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
61
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
62
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
63
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
64
+
65
+ [0]: http://rails-3-internals-active-model.heroku.com/
66
+
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rake/rdoctask'
11
+
12
+ require 'rake/testtask'
13
+
14
+ Rake::TestTask.new(:test) do |t|
15
+ t.libs << 'lib'
16
+ t.libs << 'test'
17
+ t.pattern = 'test/**/*_test.rb'
18
+ t.verbose = false
19
+ end
20
+
21
+ task :default => :test
22
+
23
+ Rake::RDocTask.new(:rdoc) do |rdoc|
24
+ rdoc.rdoc_dir = 'rdoc'
25
+ rdoc.title = 'FileRecord'
26
+ rdoc.options << '--line-numbers' << '--inline-source'
27
+ rdoc.rdoc_files.include('README.rdoc')
28
+ rdoc.rdoc_files.include('lib/**/*.rb')
29
+ end
30
+ Bundler::GemHelper.install_tasks
31
+
@@ -0,0 +1,23 @@
1
+ # Provide a simple gemspec so you can easily use your enginex
2
+ # project in your rails apps through git.
3
+ Gem::Specification.new do |s|
4
+ s.name = "file_record"
5
+ s.platform = Gem::Platform::RUBY
6
+ s.authors = ["Michał Taszycki"]
7
+ s.homepage = "https://github.com/mehowte/file_record"
8
+ s.description = "Insert FileRecord description."
9
+ s.summary = %q{Simplistic implementation of persistent model library. }
10
+ s.description = %q{Simplistic implementation of persistent model library. Inspired by ActiveRecord. And fully compatible with ActiveModel.}
11
+ s.rubyforge_project = "file_record"
12
+
13
+ s.add_dependency "rails", "~> 3.0.4"
14
+ s.add_development_dependency "capybara"
15
+ s.add_development_dependency "sqlite3-ruby"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.version = "0.1.0"
23
+ end
@@ -0,0 +1,32 @@
1
+ module FileRecord
2
+ module AttributeManagement
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ class_attribute :_attribute_names
7
+ self._attribute_names = []
8
+
9
+ attr_reader :attributes
10
+ end
11
+
12
+ def attributes=(attributes)
13
+ @attributes = attributes
14
+ sanitize_attributes
15
+
16
+ end
17
+
18
+ def sanitize_attributes
19
+ @attributes.keep_if do |name, value|
20
+ self.class._attribute_names.include? name.to_sym
21
+ end
22
+ end
23
+
24
+ module ClassMethods
25
+ def attributes(*attribute_names)
26
+ self._attribute_names += attribute_names
27
+ self._attribute_names.uniq!
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ module FileRecord
2
+ module AttributeMethods
3
+ module All
4
+ extend ActiveSupport::Concern
5
+ include Read
6
+ include Write
7
+ include Validation
8
+ include Dirty
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ module FileRecord
2
+ module AttributeMethods
3
+ module Dirty
4
+ extend ActiveSupport::Concern
5
+
6
+ include ActiveModel::Dirty
7
+
8
+ def save
9
+ if status = super
10
+ @previously_changed = changes
11
+ @changed_attributes.clear
12
+ end
13
+ status
14
+ end
15
+
16
+ def attribute=(name, value)
17
+ attribute_will_change!(name) if attributes[name] != value
18
+ super(name, value)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ module FileRecord
2
+ module AttributeMethods
3
+ module Read
4
+ extend ActiveSupport::Concern
5
+ include ActiveModel::AttributeMethods
6
+
7
+ included do
8
+ attribute_method_prefix ""
9
+ end
10
+ module ClassMethods
11
+ def attributes(*args)
12
+ super(*args)
13
+ define_attribute_methods args
14
+ end
15
+ end
16
+
17
+ protected
18
+ def attribute(name)
19
+ @attributes[name]
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ module FileRecord
2
+ module AttributeMethods
3
+ module Validation
4
+ extend ActiveSupport::Concern
5
+ include ActiveModel::AttributeMethods
6
+
7
+ included do
8
+ attribute_method_affix :prefix => 'is_', :suffix => "_valid?"
9
+ end
10
+
11
+ protected
12
+ def is_attribute_valid?(attribute)
13
+ valid? || errors[attribute].empty?
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ module FileRecord
2
+ module AttributeMethods
3
+ module Write
4
+ extend ActiveSupport::Concern
5
+ include ActiveModel::AttributeMethods
6
+
7
+ included do
8
+ attribute_method_prefix "clear_"
9
+ attribute_method_suffix "="
10
+ end
11
+
12
+ protected
13
+ def attribute=(name, value)
14
+ @attributes[name] = value
15
+ end
16
+
17
+ def clear_attribute(attribute)
18
+ send(:"#{attribute}=", nil)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ module FileRecord
2
+ module AttributeMethods
3
+ autoload :Read, 'file_record/attribute_methods/read'
4
+ autoload :Write, 'file_record/attribute_methods/write'
5
+ autoload :Validation, 'file_record/attribute_methods/validation'
6
+ autoload :Dirty, 'file_record/attribute_methods/dirty'
7
+ autoload :All, 'file_record/attribute_methods/all'
8
+ end
9
+
10
+ end
@@ -0,0 +1,19 @@
1
+ module FileRecord
2
+ class Base
3
+
4
+ include AttributeManagement
5
+ include Persistence
6
+ include Validations
7
+ include Callbacks
8
+ include AttributeMethods::All
9
+ include Compatibility
10
+
11
+ attributes :id
12
+ validates :id, :presence => true
13
+
14
+ def initialize(attributes = {})
15
+ self.attributes = attributes
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,20 @@
1
+ module FileRecord
2
+ module Callbacks
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ extend ActiveModel::Callbacks
6
+ include ActiveModel::Validations::Callbacks
7
+
8
+ define_model_callbacks :save, :destroy
9
+ end
10
+
11
+
12
+ def save
13
+ run_callbacks(:save) { super }
14
+ end
15
+
16
+ def destroy
17
+ run_callbacks(:destroy) { super }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ module FileRecord
2
+ module Compatibility
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ extend ActiveModel::Naming
7
+ extend ActiveModel::Translation
8
+ include ActiveModel::Conversion
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,53 @@
1
+ module FileRecord
2
+ module Persistence
3
+ extend ActiveSupport::Concern
4
+ include ActiveModel::Serializers::JSON
5
+
6
+ module ClassMethods
7
+ def find(name)
8
+ if File.exists? filename(name)
9
+ self.new.from_json(File.read(filename(name)))
10
+ else
11
+ nil
12
+ end
13
+ end
14
+
15
+ def all
16
+ Dir.new(Rails.root + "tmp/file_records").entries.reject do |name|
17
+ File.directory?(name)
18
+ end.map do |name|
19
+ find(name)
20
+ end
21
+ end
22
+
23
+ def create(attributes = {})
24
+ obj = self.new(attributes)
25
+ obj.save ? obj : nil
26
+ end
27
+
28
+ def filename(name)
29
+ Rails.root + "tmp/file_records/" + name
30
+ end
31
+ end
32
+
33
+ def persisted?
34
+ id && File.exists?(self.class.filename(id))
35
+ end
36
+
37
+
38
+ def save
39
+ File.open(self.class.filename(id), 'w') {|f| f.write(to_json) }
40
+ end
41
+
42
+
43
+ def destroy
44
+ File.delete(self.class.filename(id)) if persisted?
45
+ end
46
+
47
+ def update_attributes(attributes)
48
+ @attributes.merge!(attributes)
49
+ sanitize_attributes
50
+ save
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,15 @@
1
+ module FileRecord
2
+ module Validations
3
+ extend ActiveSupport::Concern
4
+ include ActiveModel::Validations
5
+
6
+ def save
7
+ if valid?
8
+ super
9
+ true
10
+ else
11
+ false
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module FileRecord
2
+ autoload :Base, 'file_record/base'
3
+ autoload :AttributeMethods, 'file_record/attribute_methods'
4
+ autoload :AttributeManagement, 'file_record/attribute_management'
5
+ autoload :Persistence, 'file_record/persistence'
6
+ autoload :Validations, 'file_record/validations'
7
+ autoload :Callbacks, 'file_record/callbacks'
8
+ autoload :Compatibility, 'file_record/compatibility'
9
+ end
@@ -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,83 @@
1
+ class AddressesController < ApplicationController
2
+ # GET /addresses
3
+ # GET /addresses.json
4
+ def index
5
+ @addresses = Address.all
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.json { render :json => @addresses }
10
+ end
11
+ end
12
+
13
+ # GET /addresses/1
14
+ # GET /addresses/1.json
15
+ def show
16
+ @address = Address.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.json { render :json => @address }
21
+ end
22
+ end
23
+
24
+ # GET /addresses/new
25
+ # GET /addresses/new.json
26
+ def new
27
+ @address = Address.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.json { render :json => @address }
32
+ end
33
+ end
34
+
35
+ # GET /addresses/1/edit
36
+ def edit
37
+ @address = Address.find(params[:id])
38
+ end
39
+
40
+ # POST /addresses
41
+ # POST /addresses.json
42
+ def create
43
+ @address = Address.new(params[:address])
44
+
45
+ respond_to do |format|
46
+ if @address.save
47
+ format.html { redirect_to(@address, :notice => 'Address was successfully created.') }
48
+ format.json { render :json => @address, :status => :created, :location => @address }
49
+ else
50
+ format.html { render :action => "new" }
51
+ format.json { render :json => @address.errors, :status => :unprocessable_entity }
52
+ end
53
+ end
54
+ end
55
+
56
+ # PUT /addresses/1
57
+ # PUT /addresses/1.json
58
+ def update
59
+ @address = Address.find(params[:id])
60
+
61
+ respond_to do |format|
62
+ if @address.update_attributes(params[:address])
63
+ format.html { redirect_to(@address, :notice => 'Address was successfully updated.') }
64
+ format.json { head :ok }
65
+ else
66
+ format.html { render :action => "edit" }
67
+ format.json { render :json => @address.errors, :status => :unprocessable_entity }
68
+ end
69
+ end
70
+ end
71
+
72
+ # DELETE /addresses/1
73
+ # DELETE /addresses/1.json
74
+ def destroy
75
+ @address = Address.find(params[:id])
76
+ @address.destroy
77
+
78
+ respond_to do |format|
79
+ format.html { redirect_to(addresses_url) }
80
+ format.json { head :ok }
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,2 @@
1
+ module AddressesHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,10 @@
1
+ class Address < FileRecord::Base
2
+ def initialize(attributes = {})
3
+ super(attributes)
4
+ end
5
+
6
+ attributes :street, :house_number
7
+
8
+ validates :street, :house_number, :presence => true
9
+ validates :house_number, :numericality => true
10
+ end