dao 3.2.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
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 = "3.2.0"
6
+ spec.version = "3.3.0"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "dao"
9
9
  spec.description = "description: dao kicks the ass"
@@ -14,6 +14,8 @@ Gem::Specification::new do |spec|
14
14
  "TODO",
15
15
  "a.rb",
16
16
  "dao.gemspec",
17
+ "db",
18
+ "db/dao.yml",
17
19
  "lib",
18
20
  "lib/dao",
19
21
  "lib/dao.rb",
data/db/dao.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ foo:
3
+ "1":
4
+ id: 1
5
+ bar: 44
data/lib/dao.rb CHANGED
@@ -10,7 +10,7 @@
10
10
  # dao libs
11
11
  #
12
12
  module Dao
13
- Version = '3.2.0' unless defined?(Version)
13
+ Version = '3.3.0' unless defined?(Version)
14
14
 
15
15
  def version
16
16
  Dao::Version
@@ -11,6 +11,7 @@ module Dao
11
11
  @state ||= {
12
12
  :interfaces => {},
13
13
  :blocks => {},
14
+ :README => [],
14
15
  :docs => []
15
16
  }
16
17
  end
@@ -37,8 +38,8 @@ module Dao
37
38
  state[:interfaces]
38
39
  end
39
40
 
40
- def description(string)
41
- doc(:description => Dao.unindent(string))
41
+ def description(*args)
42
+ doc(:description => lines_for(*args))
42
43
  end
43
44
  alias_method('desc', 'description')
44
45
 
@@ -47,7 +48,7 @@ module Dao
47
48
  doc = docs.last
48
49
  options = Dao.options_for!(args)
49
50
  if options.empty?
50
- options[:description] = args.join(' ')
51
+ options[:description] = lines_for(*args)
51
52
  end
52
53
  doc.update(options)
53
54
  doc
@@ -57,8 +58,26 @@ module Dao
57
58
  state[:docs]
58
59
  end
59
60
 
61
+ def readme(*args)
62
+ if args.empty?
63
+ state[:README]
64
+ else
65
+ state[:README] = lines_for(args)
66
+ end
67
+ end
68
+ alias_method('README', 'readme')
69
+
70
+ def lines_for(*args)
71
+ Dao.unindent(args.flatten.compact.join("\n")).split(/\n/)
72
+ end
73
+
74
+ def readme=(readme)
75
+ self.readme = readme.to_s
76
+ end
77
+
60
78
  def index
61
79
  index = Map.new
80
+ index[:README] = readme
62
81
  interfaces.each do |path, interface|
63
82
  index[path] = interface.doc || {'description' => ''}
64
83
  end
data/lib/dao/db.rb CHANGED
@@ -44,6 +44,13 @@ module Dao
44
44
  find(id)
45
45
  end
46
46
 
47
+ def []=(id, data = {})
48
+ data.delete(:id)
49
+ data.delete('id')
50
+ data[:id] = id
51
+ save(data)
52
+ end
53
+
47
54
  def delete(id)
48
55
  @db.delete(@name, id)
49
56
  end
@@ -61,9 +68,10 @@ module Dao
61
68
  end
62
69
  end
63
70
 
64
- def [](name)
71
+ def collection(name)
65
72
  Collection.new(name, db)
66
73
  end
74
+ alias_method('[]', 'collection')
67
75
 
68
76
  def transaction(*args, &block)
69
77
  ystore.transaction(*args, &block)
@@ -1,13 +1,28 @@
1
1
  Api =
2
2
  Dao.api do
3
+ ##
4
+ #
5
+ README <<-__
6
+ this a dao api
7
+
8
+ so nice
9
+
10
+ so good
11
+ __
3
12
 
4
- description 'ping!'
5
- interface('/ping'){
13
+ ##
14
+ #
15
+ doc '/ping - hello world without a user'
16
+ call('/ping'){
6
17
  data.update :time => Time.now
7
18
  }
8
19
 
9
-
10
-
20
+ doc '/pong - hello world with a user'
21
+ call('/pong'){
22
+ require_current_user!
23
+ data.update :time => Time.now
24
+ data.update :current_user => current_user.id
25
+ }
11
26
 
12
27
  ## this is simply a suggested way to model your api. it is not required.
13
28
  #
@@ -23,6 +38,8 @@ Api =
23
38
  @real_user ||= @effective_user
24
39
  end
25
40
 
41
+ ## no doubt you'll want to customize this!
42
+ #
26
43
  def user_for(arg)
27
44
  User.respond_to?(:for) ? User.for(arg) : User.find(arg)
28
45
  end
@@ -51,6 +68,25 @@ Api =
51
68
  def current_user?
52
69
  !!effective_user
53
70
  end
71
+
72
+ def require_effective_user!
73
+ unless effective_user?
74
+ status :unauthorized
75
+ return!
76
+ end
77
+ end
78
+
79
+ def require_real_user!
80
+ unless effective_user?
81
+ status :unauthorized
82
+ return!
83
+ end
84
+ end
85
+
86
+ def require_current_user!
87
+ require_effective_user! and require_real_user!
88
+ end
89
+ alias_method('require_user!', 'require_current_user!')
54
90
  end
55
91
 
56
92
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dao
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 3.2.0
10
+ version: 3.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ara T. Howard
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-08 00:00:00 -06:00
18
+ date: 2011-06-09 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -33,6 +33,7 @@ files:
33
33
  - TODO
34
34
  - a.rb
35
35
  - dao.gemspec
36
+ - db/dao.yml
36
37
  - lib/dao.rb
37
38
  - lib/dao/active_record.rb
38
39
  - lib/dao/api.rb