dao 4.2.1 → 4.4.2

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 (78) hide show
  1. data/README +103 -63
  2. data/Rakefile +3 -3
  3. data/dao.gemspec +27 -16
  4. data/lib/dao.rb +17 -17
  5. data/lib/dao/active_record.rb +1 -0
  6. data/lib/dao/api.rb +2 -1
  7. data/lib/dao/api/{endpoints.rb → call.rb} +1 -0
  8. data/lib/dao/api/context.rb +2 -0
  9. data/lib/dao/api/dsl.rb +1 -0
  10. data/lib/dao/api/initializers.rb +1 -0
  11. data/lib/dao/api/modes.rb +1 -0
  12. data/lib/dao/api/routes.rb +1 -0
  13. data/lib/dao/blankslate.rb +1 -0
  14. data/lib/dao/conducer.rb +315 -274
  15. data/lib/dao/conducer/active_model.rb +98 -0
  16. data/lib/dao/conducer/attributes.rb +1 -0
  17. data/lib/dao/conducer/autocrud.rb +58 -0
  18. data/lib/dao/conducer/callback_support.rb +20 -0
  19. data/lib/dao/conducer/collection.rb +45 -0
  20. data/lib/dao/conducer/controller_support.rb +104 -0
  21. data/lib/dao/conducer/nav_support.rb +9 -0
  22. data/lib/dao/conducer/view_support.rb +16 -0
  23. data/lib/dao/data.rb +2 -1
  24. data/lib/dao/db.rb +2 -0
  25. data/lib/dao/endpoint.rb +1 -0
  26. data/lib/dao/engine.rb +1 -0
  27. data/lib/dao/errors.rb +109 -99
  28. data/lib/dao/exceptions.rb +1 -0
  29. data/lib/dao/extractor.rb +1 -0
  30. data/lib/dao/form.rb +175 -20
  31. data/lib/dao/instance_exec.rb +1 -0
  32. data/lib/dao/mode.rb +1 -0
  33. data/lib/dao/mongo_mapper.rb +1 -0
  34. data/lib/dao/name.rb +1 -0
  35. data/lib/dao/params.rb +2 -1
  36. data/lib/dao/path.rb +1 -0
  37. data/lib/dao/path_map.rb +24 -0
  38. data/lib/dao/rack.rb +1 -0
  39. data/lib/dao/rack/middleware.rb +1 -0
  40. data/lib/dao/rack/middleware/params_parser.rb +1 -0
  41. data/lib/dao/rails.rb +12 -32
  42. data/lib/dao/rails/lib/generators/dao/USAGE +2 -2
  43. data/lib/dao/rails/lib/generators/dao/dao_generator.rb +8 -27
  44. data/lib/dao/rails/lib/generators/dao/templates/api.rb +2 -1
  45. data/lib/dao/rails/lib/generators/dao/templates/api_controller.rb +22 -20
  46. data/lib/dao/rails/lib/generators/dao/templates/conducer.rb +49 -43
  47. data/lib/dao/rails/lib/generators/dao/templates/dao.css +26 -25
  48. data/lib/dao/rails/lib/generators/dao/templates/dao.js +3 -0
  49. data/lib/dao/rails/lib/generators/dao/templates/dao_helper.rb +58 -45
  50. data/lib/dao/result.rb +50 -1
  51. data/lib/dao/route.rb +1 -0
  52. data/lib/dao/slug.rb +12 -36
  53. data/lib/dao/status.rb +91 -7
  54. data/lib/dao/stdext.rb +1 -0
  55. data/lib/dao/support.rb +90 -80
  56. data/lib/dao/upload.rb +396 -0
  57. data/lib/dao/validations.rb +23 -5
  58. data/lib/dao/validations/callback.rb +5 -0
  59. data/lib/dao/validations/common.rb +100 -3
  60. data/lib/dao/validations/instance.rb +17 -0
  61. data/lib/dao/validations/validator.rb +192 -91
  62. data/test/active_model_conducer_lint_test.rb +1 -0
  63. data/test/api_test.rb +15 -0
  64. data/test/conducer_test.rb +608 -90
  65. data/test/data/han-solo.jpg +0 -0
  66. data/test/form_test.rb +1 -0
  67. data/test/helper.rb +1 -0
  68. data/test/leak.rb +1 -0
  69. data/test/support_test.rb +4 -1
  70. data/test/testing.rb +1 -0
  71. data/test/validations_test.rb +176 -30
  72. metadata +120 -131
  73. data/b.rb +0 -38
  74. data/lib/dao/conducer/crud.rb +0 -70
  75. data/lib/dao/current.rb +0 -66
  76. data/lib/dao/image_cache.rb +0 -193
  77. data/lib/dao/rails/lib/generators/dao/templates/conducer_controller.rb +0 -79
  78. data/test/db.yml +0 -9
data/README CHANGED
@@ -3,104 +3,143 @@ NAME
3
3
 
4
4
  SYNOPSIS
5
5
  a sa-weet-ass library for structuring rails applications using the 'data
6
- access object' design pattern.
6
+ access object' design pattern. dao consists of two main data access
7
+ objects, *api* objects and *conducer* objects. conducers combine the
8
+ presenter pattern with the conductor pattern.
7
9
 
8
- DESCRITPION
9
- applications that are written on dao look like this in ruby
10
10
 
11
- result = api.call('/posts/new', params)
11
+ API
12
12
 
13
- and like this in javascript
13
+ class Api < Dao::Api
14
+ call('/posts') do
15
+ get do
16
+ data[:posts] = Post.all.map{|post| post.attributes}
17
+ end
14
18
 
15
- result = api.call('/posts/new', params)
19
+ post do
20
+ post = Post.new(params[:post])
16
21
 
17
- in command-line applications they look like this
22
+ if post.save
23
+ data[:post] = post.attributes
24
+ else
25
+ status 420
26
+ end
27
+ end
28
+ end
29
+ end
18
30
 
19
- result = api.call('/posts/new', params)
31
+ CONDUCER
20
32
 
21
- and in tests this syntax is used
33
+ # TODO
22
34
 
23
- result = api.call('/posts/new', params)
24
35
 
25
- when a developer wants to understand the interface of a dao application she
26
- does this
36
+ wikipedia has this to say about dao in general
27
37
 
28
- vi app/api.rb
38
+ "
29
39
 
30
- when a developer of a dao application wants to play with a dao application
31
- interactively she does
40
+ In computer software, a data access object (DAO) is an object that
41
+ provides an abstract interface to some type of database or persistence
42
+ mechanism, providing some specific operations without exposing details
43
+ of the database. It provides a mapping from application calls to the
44
+ persistence layer. This isolation separates the concerns of what data
45
+ accesses the application needs, in terms of domain-specific objects and
46
+ data types (the public interface of the DAO), and how these needs can be
47
+ satisfied with a specific DBMS, database schema, etc. (the
48
+ implementation of the DAO).
32
49
 
33
- (rails console)
50
+ "
51
+ - http://en.wikipedia.org/wiki/Data_access_object
34
52
 
35
- > api = Api.new
36
- > result = api.call('/posts/new', params)
53
+ and
37
54
 
38
- when a remote client wants to understand the api of a dao application she
39
- does
55
+ "
56
+ Models are not data access objects...
57
+ "
40
58
 
41
- curl --silent http://dao.app.com/api | less
59
+ - http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
42
60
 
61
+ DESCRITPION
43
62
 
63
+ API
64
+ applications that are written on dao look like this in ruby
44
65
 
45
- this kind of brutally consistent interface is made possible by structuring
46
- access to data around the finest data structure of all time - the hash. in
47
- the case of dao the hash is a well structured and slightly clever hash, but
48
- a simple hash interface is the basis of every bit of goodness dao has to
49
- offer.
66
+ result = api.call('/posts/new', params)
50
67
 
51
- in dao, application developers do not bring models into controllers and,
52
- especially not into views. instead, a unified interface to application
53
- logic and data is used everywhere: in tests, in controllers, from the
54
- command-line, and also from javascript.
68
+ and like this in javascript
55
69
 
56
- this speration of concerns brings with it many, many desirable qualities:
70
+ result = api.call('/posts/new', params)
57
71
 
58
- - total seperation of concerns between the front and back end of a web
59
- application. when developers are using dao changes to the data model
60
- have zero effect on controllers and views.
72
+ in command-line applications they look like this
61
73
 
62
- - issues related to having models in controllers and views such as
63
- difficulty reasoning about caching and n+1 queries in views killing the
64
- db simply disappear.
74
+ result = api.call('/posts/new', params)
65
75
 
66
- - bad programming practices like using quasi-global variables
67
- (current_user) or decorating models with view specific attributes
68
- (password_verification) are no longer needed.
76
+ and in tests this syntax is used
69
77
 
70
- - developers are able to reason over the abilities of an application by
71
- reading only a few source files.
78
+ result = api.call('/posts/new', params)
72
79
 
73
- - databases can be swapped, mixed, or alternate storage/caching mechanisms
74
- added at any time without affecting the application's controllers or
75
- views.
80
+ when a developer wants to understand the interface of a dao application
81
+ she does this
76
82
 
77
- - transition from form based views to semi-ajax ones to fully-ajax ones is
78
- direct.
83
+ vi app/api.rb
79
84
 
80
- - forms and interfaces that involve dozens of models are as easy to deal
81
- with as simple ones.
85
+ when a developer of a dao application wants to play with a dao application
86
+ interactively she does
82
87
 
83
- - code can be optimized at the interface
88
+ (rails console)
84
89
 
90
+ > api = Api.new result = api.call('/posts/new', params)
85
91
 
86
- wikipedia has this to say about dao in general
92
+ when a remote client wants to understand the api of a dao application she
93
+ does
87
94
 
88
- "
95
+ curl --silent http://dao.app.com/api | less
89
96
 
90
- In computer software, a data access object (DAO) is an object that
91
- provides an abstract interface to some type of database or persistence
92
- mechanism, providing some specific operations without exposing details
93
- of the database. It provides a mapping from application calls to the
94
- persistence layer. This isolation separates the concerns of what data
95
- accesses the application needs, in terms of domain-specific objects and
96
- data types (the public interface of the DAO), and how these needs can be
97
- satisfied with a specific DBMS, database schema, etc. (the
98
- implementation of the DAO).
99
97
 
100
- "
101
- - http://en.wikipedia.org/wiki/Data_access_object
98
+
99
+ this kind of brutally consistent interface is made possible by structuring
100
+ access to data around the finest data structure of all time - the hash.
101
+ in the case of dao the hash is a well structured and slightly clever hash,
102
+ but a simple hash interface is the basis of every bit of goodness dao has
103
+ to offer.
104
+
105
+ in dao, application developers do not bring models into controllers and,
106
+ especially not into views. instead, a unified interface to application
107
+ logic and data is used everywhere: in tests, in controllers, from the
108
+ command-line, and also from javascript.
109
+
110
+ this seperation of concerns brings with it many, many desirable qualities:
111
+
112
+ - total seperation of concerns between the front and back end of a web
113
+ application. when developers are using dao changes to the data model
114
+ have zero effect on controllers and views.
115
+
116
+ - issues related to having models in controllers and views such as
117
+ difficulty reasoning about caching and n+1 queries in views killing
118
+ the db simply disappear.
119
+
120
+ - bad programming practices like using quasi-global variables
121
+ (current_user) or decorating models with view specific attributes
122
+ (password_verification) are no longer needed.
123
+
124
+ - developers are able to reason over the abilities of an application by
125
+ reading only a few source files.
126
+
127
+ - databases can be swapped, mixed, or alternate storage/caching
128
+ mechanisms added at any time without affecting the application's
129
+ controllers or views.
130
+
131
+ - transition from form based views to semi-ajax ones to fully-ajax ones
132
+ is direct.
133
+
134
+ - forms and interfaces that involve dozens of models are as easy to deal
135
+ with as simple ones.
136
+
137
+ - code can be optimized at the interface
102
138
 
103
139
  READING
140
+ http://blog.plataformatec.com.br/2012/03/barebone-models-to-use-with-actionpack-in-rails-4-0/
141
+ http://martinfowler.com/eaaCatalog/serviceLayer.html
142
+ http://blog.firsthand.ca/2011/10/rails-is-not-your-application.html
104
143
  http://best-practice-software-engineering.ifs.tuwien.ac.at/patterns/dao.html
105
144
  http://www.codefutures.com/data-access-object/
106
145
  http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
@@ -108,6 +147,7 @@ READING
108
147
  http://google-styleguide.googlecode.com/svn/trunk/jsoncstyleguide.xml
109
148
  http://pragdave.blogs.pragprog.com/pragdave/2007/03/the_radar_archi.html
110
149
 
150
+
111
151
  INSTALL
112
152
  gem 'dao', :path => File.expand_path('..') ### Gemfile
113
153
  rails generate dao api
data/Rakefile CHANGED
@@ -29,7 +29,7 @@ def run_tests!(which = nil)
29
29
 
30
30
  test_rbs.each_with_index do |test_rb, index|
31
31
  testno = index + 1
32
- command = "#{ This.ruby } -I ./lib -I ./test/lib #{ test_rb }"
32
+ command = "#{ File.basename(This.ruby) } -I ./lib -I ./test/lib #{ test_rb }"
33
33
 
34
34
  puts
35
35
  say(div, :color => :cyan, :bold => true)
@@ -59,8 +59,8 @@ end
59
59
 
60
60
  task :gemspec do
61
61
  ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
62
- ignore_directories = ['pkg']
63
- ignore_files = ['test/log', 'a.rb'] + Dir['db/*'] + %w'db'
62
+ ignore_directories = ['pkg', 'db']
63
+ ignore_files = ['test/log', 'test/db.yml', 'a.rb', 'b.rb'] + Dir['db/*'] + %w'db'
64
64
 
65
65
  shiteless =
66
66
  lambda do |list|
data/dao.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "dao"
6
- spec.version = "4.2.1"
6
+ spec.version = "4.4.2"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "dao"
9
9
  spec.description = "description: dao kicks the ass"
@@ -11,27 +11,30 @@ Gem::Specification::new do |spec|
11
11
  spec.files =
12
12
  ["README",
13
13
  "Rakefile",
14
- "b.rb",
15
14
  "dao.gemspec",
16
- "db",
17
15
  "lib",
18
16
  "lib/dao",
19
17
  "lib/dao.rb",
20
18
  "lib/dao/active_record.rb",
21
19
  "lib/dao/api",
22
20
  "lib/dao/api.rb",
21
+ "lib/dao/api/call.rb",
23
22
  "lib/dao/api/context.rb",
24
23
  "lib/dao/api/dsl.rb",
25
- "lib/dao/api/endpoints.rb",
26
24
  "lib/dao/api/initializers.rb",
27
25
  "lib/dao/api/modes.rb",
28
26
  "lib/dao/api/routes.rb",
29
27
  "lib/dao/blankslate.rb",
30
28
  "lib/dao/conducer",
31
29
  "lib/dao/conducer.rb",
30
+ "lib/dao/conducer/active_model.rb",
32
31
  "lib/dao/conducer/attributes.rb",
33
- "lib/dao/conducer/crud.rb",
34
- "lib/dao/current.rb",
32
+ "lib/dao/conducer/autocrud.rb",
33
+ "lib/dao/conducer/callback_support.rb",
34
+ "lib/dao/conducer/collection.rb",
35
+ "lib/dao/conducer/controller_support.rb",
36
+ "lib/dao/conducer/nav_support.rb",
37
+ "lib/dao/conducer/view_support.rb",
35
38
  "lib/dao/data.rb",
36
39
  "lib/dao/db.rb",
37
40
  "lib/dao/endpoint.rb",
@@ -40,13 +43,13 @@ Gem::Specification::new do |spec|
40
43
  "lib/dao/exceptions.rb",
41
44
  "lib/dao/extractor.rb",
42
45
  "lib/dao/form.rb",
43
- "lib/dao/image_cache.rb",
44
46
  "lib/dao/instance_exec.rb",
45
47
  "lib/dao/mode.rb",
46
48
  "lib/dao/mongo_mapper.rb",
47
49
  "lib/dao/name.rb",
48
50
  "lib/dao/params.rb",
49
51
  "lib/dao/path.rb",
52
+ "lib/dao/path_map.rb",
50
53
  "lib/dao/rack",
51
54
  "lib/dao/rack.rb",
52
55
  "lib/dao/rack/middleware",
@@ -63,7 +66,6 @@ Gem::Specification::new do |spec|
63
66
  "lib/dao/rails/lib/generators/dao/templates/api.rb",
64
67
  "lib/dao/rails/lib/generators/dao/templates/api_controller.rb",
65
68
  "lib/dao/rails/lib/generators/dao/templates/conducer.rb",
66
- "lib/dao/rails/lib/generators/dao/templates/conducer_controller.rb",
67
69
  "lib/dao/rails/lib/generators/dao/templates/dao.css",
68
70
  "lib/dao/rails/lib/generators/dao/templates/dao.js",
69
71
  "lib/dao/rails/lib/generators/dao/templates/dao_helper.rb",
@@ -73,16 +75,19 @@ Gem::Specification::new do |spec|
73
75
  "lib/dao/status.rb",
74
76
  "lib/dao/stdext.rb",
75
77
  "lib/dao/support.rb",
78
+ "lib/dao/upload.rb",
76
79
  "lib/dao/validations",
77
80
  "lib/dao/validations.rb",
78
81
  "lib/dao/validations/callback.rb",
79
82
  "lib/dao/validations/common.rb",
83
+ "lib/dao/validations/instance.rb",
80
84
  "lib/dao/validations/validator.rb",
81
85
  "test",
82
86
  "test/active_model_conducer_lint_test.rb",
83
87
  "test/api_test.rb",
84
88
  "test/conducer_test.rb",
85
- "test/db.yml",
89
+ "test/data",
90
+ "test/data/han-solo.jpg",
86
91
  "test/form_test.rb",
87
92
  "test/helper.rb",
88
93
  "test/leak.rb",
@@ -97,19 +102,25 @@ Gem::Specification::new do |spec|
97
102
  spec.test_files = nil
98
103
 
99
104
 
100
- spec.add_dependency(*["rails", "~> 3.0"])
105
+ spec.add_dependency(*["rails", " >= 3.1"])
101
106
 
102
- spec.add_dependency(*["uuidtools", "~> 2.1"])
107
+ spec.add_dependency(*["map", " >= 5.4"])
103
108
 
104
- spec.add_dependency(*["tagz", "~> 9.0"])
109
+ spec.add_dependency(*["fattr", " >= 2.2"])
105
110
 
106
- spec.add_dependency(*["fattr", "~> 2.2"])
111
+ spec.add_dependency(*["tagz", " >= 9.3"])
107
112
 
108
- spec.add_dependency(*["map", "~> 4.4"])
113
+ spec.add_dependency(*["multi_json", " >= 1.0.3"])
109
114
 
110
- spec.add_dependency(*["unidecode", "~> 1.0"])
115
+ spec.add_dependency(*["uuidtools", " >= 2.1.2"])
111
116
 
112
- spec.add_dependency(*["yajl-ruby", "~> 0.8"])
117
+ spec.add_dependency(*["wrap", " >= 1.5.0"])
118
+
119
+ spec.add_dependency(*["rails_current", " >= 1.6"])
120
+
121
+ spec.add_dependency(*["rails_nav", " >= 1.0.1"])
122
+
123
+ spec.add_dependency(*["rails_helper", " >= 1.3.0"])
113
124
 
114
125
 
115
126
  spec.extensions.push(*[])
data/lib/dao.rb CHANGED
@@ -1,12 +1,16 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  # built-ins
2
3
  #
3
4
  require 'enumerator'
4
5
  require 'set'
6
+ require 'fileutils'
7
+ require 'cgi'
8
+ require 'tmpdir'
5
9
 
6
10
  # dao libs
7
11
  #
8
12
  module Dao
9
- Version = '4.2.1' unless defined?(Version)
13
+ Version = '4.4.2' unless defined?(Version)
10
14
 
11
15
  def version
12
16
  Dao::Version
@@ -14,13 +18,16 @@
14
18
 
15
19
  def dependencies
16
20
  {
17
- 'rails' => [ 'rails' , '~> 3.0' ],
18
- 'map' => [ 'map' , '~> 4.4' ],
19
- 'fattr' => [ 'fattr' , '~> 2.2' ],
20
- 'tagz' => [ 'tagz' , '~> 9.0' ],
21
- 'yajl' => [ 'yajl-ruby' , '~> 0.8' ],
22
- 'unidecode' => [ 'unidecode' , '~> 1.0' ],
23
- 'uuidtools' => [ 'uuidtools' , '~> 2.1' ]
21
+ 'rails' => [ 'rails' , ' >= 3.1' ] ,
22
+ 'map' => [ 'map' , ' >= 5.4' ] ,
23
+ 'fattr' => [ 'fattr' , ' >= 2.2' ] ,
24
+ 'tagz' => [ 'tagz' , ' >= 9.3' ] ,
25
+ 'multi_json' => [ 'multi_json' , ' >= 1.0.3' ] ,
26
+ 'uuidtools' => [ 'uuidtools' , ' >= 2.1.2' ] ,
27
+ 'wrap' => [ 'wrap' , ' >= 1.5.0' ] ,
28
+ 'rails_current' => [ 'rails_current' , ' >= 1.6' ] ,
29
+ 'rails_nav' => [ 'rails_nav' , ' >= 1.0.1' ] ,
30
+ 'rails_helper' => [ 'rails_helper' , ' >= 1.3.0' ]
24
31
  }
25
32
  end
26
33
 
@@ -61,9 +68,6 @@
61
68
  end
62
69
  end
63
70
 
64
- #active_record
65
- #action_mailer
66
- #rails/test_unit
67
71
  %w[
68
72
  action_controller
69
73
  active_resource
@@ -74,11 +78,8 @@
74
78
  rescue LoadError
75
79
  end
76
80
  end
77
- #require 'rails/all'
78
81
 
79
82
 
80
- require 'yajl/json_gem'
81
-
82
83
  Dao.load %w[
83
84
  blankslate.rb
84
85
  instance_exec.rb
@@ -90,6 +91,7 @@
90
91
 
91
92
  name.rb
92
93
  status.rb
94
+ path_map.rb
93
95
  errors.rb
94
96
  form.rb
95
97
  validations.rb
@@ -97,8 +99,6 @@
97
99
  result.rb
98
100
  params.rb
99
101
 
100
- current.rb
101
-
102
102
  mode.rb
103
103
  route.rb
104
104
  path.rb
@@ -112,7 +112,7 @@
112
112
  mongo_mapper.rb
113
113
 
114
114
  conducer.rb
115
- image_cache.rb
115
+ upload.rb
116
116
  ]
117
117
 
118
118
  # protect against rails' too clever reloading
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  begin
2
3
  ActiveRecord
3
4
  ActiveRecord::Base
data/lib/dao/api.rb CHANGED
@@ -1,10 +1,11 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  module Dao
2
3
  class Api
3
4
  Dao.load 'api/initializers.rb'
4
5
  Dao.load 'api/modes.rb'
5
6
  Dao.load 'api/routes.rb'
6
7
  Dao.load 'api/context.rb'
7
- Dao.load 'api/endpoints.rb'
8
+ Dao.load 'api/call.rb'
8
9
  Dao.load 'api/dsl.rb'
9
10
  end
10
11
  end