uzuuzu-core 0.1.10 → 0.1.11

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.10
1
+ 0.1.11
@@ -0,0 +1 @@
1
+ require 'dm-adapter-simpledb'
@@ -153,6 +153,8 @@ module UzuUzu
153
153
  action_return = send_action(request, response, controller, action, query)
154
154
  if response.body.blank?
155
155
  render = helper.render(action)
156
+ p action
157
+ p render
156
158
  end
157
159
  break
158
160
  end
@@ -215,6 +217,7 @@ module UzuUzu
215
217
  if routes.blank? || name != routes[-1]
216
218
  routes << "#{name.camel_case}"
217
219
  end
220
+ routes.shift if routes[0].blank?
218
221
  _base = "::#{@name.to_s.camel_case}"
219
222
  _base = '' if @name == :uzuuzu || @name == 'uzuuzu'
220
223
  helper = eval("#{_base}::#{helper_root.camel_case}")
@@ -234,6 +237,7 @@ module UzuUzu
234
237
  classies = []
235
238
  request_paths = env['PATH_INFO'].split('/')
236
239
  request_paths.shift if request_paths[0].blank?
240
+ request_paths << ''
237
241
 
238
242
  _controllers = controllers.clone
239
243
  _base = "::#{@name.to_s.camel_case}"
@@ -246,42 +250,32 @@ module UzuUzu
246
250
  _controllers.each do |c|
247
251
  _c = c
248
252
  _h = nil
249
- if request_paths.size == 0
250
- map = get_class_map('Index', _c, env['SCRIPT_NAME'], request_paths)
251
- if map && map[:controller].kind_of?(::Class)
252
- classies << map
253
- end
254
- end
255
253
  request_paths.each_with_index do |request_path, index|
256
254
  break if _c.nil?
257
- next if request_path.blank?
258
255
  c_str = request_path.camel_case
259
256
  route = "#{request_paths[0...index].join('/')}"
260
257
  if route.blank?
261
- route = "#{env['SCRIPT_NAME']}"
258
+ route = "#{env['SCRIPT_NAME']}/index"
259
+ route.blank?
262
260
  else
263
- route = "#{env['SCRIPT_NAME']}/#{route}"
261
+ route = "#{env['SCRIPT_NAME']}/#{route}/index"
264
262
  end
265
- query = request_paths[index..-1]
263
+ query = request_paths[index...-1]
266
264
  map = get_class_map('Index', _c, route, query)
267
265
  if map && map[:controller].kind_of?(::Class)
268
266
  classies << map
269
267
  end
270
- next if c_str == 'Index'
271
- route = "#{env['SCRIPT_NAME']}/#{request_paths[0..index].join('/')}"
272
- query = request_paths[(index+1)..-1]
268
+ next if c_str == 'Index' || c_str.blank?
269
+ route = "#{env['SCRIPT_NAME']}/#{request_paths[0...index].join('/')}"
270
+ query = request_paths[(index+1)...-1]
273
271
  map = get_class_map(c_str, _c, route, query)
274
- if map && map[:controller].kind_of?(::Class)
275
- classies << map
276
- end
272
+ _c = nil
277
273
  if map
278
- _c = map[:controller]
279
- else
280
- _c = nil
281
- end
282
- unless _c.kind_of?(::Class) || _c.kind_of?(::Module)
283
- _c = nil
284
- break
274
+ classies << map if map[:controller].kind_of?(::Class)
275
+ p map[:controller].kind_of?(::Module)
276
+ if map[:controller].kind_of?(::Class) || map[:controller].kind_of?(::Module)
277
+ _c = map[:controller]
278
+ end
285
279
  end
286
280
  end
287
281
  end
@@ -9,7 +9,7 @@ module UzuUzu
9
9
  end
10
10
 
11
11
  def error(code)
12
- response.respond(helper.render_file(__DIR__("view/error/#{code}.rhtml")))
12
+ response.respond(helper.render_file(__DIR__("view/index/error/#{code}.rhtml")))
13
13
  end
14
14
 
15
15
  def logout
@@ -9,10 +9,14 @@ module UzuUzu
9
9
  #
10
10
  DEFAULT_YAML = 'uzuuzu.yaml'
11
11
  #
12
- attr_accessor :flyweight
12
+ attr_accessor :map
13
13
  #
14
14
  attr_accessor :service_name
15
15
  #
16
+ attr_accessor :dm
17
+ #
18
+ attr_accessor :s3
19
+ #
16
20
  attr_accessor :logger
17
21
  #
18
22
  attr_accessor :memcache
@@ -39,6 +43,7 @@ module UzuUzu
39
43
 
40
44
  def initialize(yaml=nil)
41
45
  load_yaml(yaml||self.class.default_yaml)
46
+ dm
42
47
  end
43
48
 
44
49
  def load_yaml(yaml)
@@ -69,9 +74,9 @@ module UzuUzu
69
74
  end
70
75
  end
71
76
 
72
- def flyweight
73
- @flyweight = {} if @flyweight.nil?
74
- @flyweight
77
+ def map
78
+ @map = {} if @map.nil?
79
+ @map
75
80
  end
76
81
 
77
82
  def config
@@ -81,15 +86,31 @@ module UzuUzu
81
86
 
82
87
  def logger
83
88
  if @logger.nil?
84
- env = @config['logger'].clone unless @config.nil?
89
+ env = @config['logger'].dup unless @config.nil?
85
90
  @logger = Wrapper::Logger.new(env || {}).logger
86
91
  end
87
92
  @logger
88
93
  end
89
94
 
95
+ def dm
96
+ if @dm.nil?
97
+ env = @config['dm'].dup unless @config.nil?
98
+ @dm = Wrapper::Dm.new(env || {})
99
+ end
100
+ @dm
101
+ end
102
+
103
+ def s3
104
+ if @s3.nil?
105
+ env = @config['s3'].dup unless @config.nil?
106
+ @s3 = Wrapper::S3.new(env || {})
107
+ end
108
+ @s3
109
+ end
110
+
90
111
  def memcache
91
112
  if @memcache.nil?
92
- env = @config['memcache'].clone unless @config.nil?
113
+ env = @config['memcache'].dup unless @config.nil?
93
114
  @memcache = Wrapper::Wrapper.new('memcache', env || {}).wrapper
94
115
  @memcache ||= {}
95
116
  end
@@ -98,7 +119,7 @@ module UzuUzu
98
119
 
99
120
  def rack_session
100
121
  if @rack_session.nil?
101
- env = @config['rack_session'].clone unless @config.nil?
122
+ env = @config['rack_session'].dup unless @config.nil?
102
123
  @rack_session = Wrapper::Wrapper.new('rack_session', env || {}).wrapper
103
124
  end
104
125
  @rack_session
@@ -82,8 +82,15 @@ module UzuUzu
82
82
  #
83
83
  #
84
84
  #
85
- def service
86
- ::UzuUzu.service
85
+ def dm
86
+ ::UzuUzu.dm
87
+ end
88
+
89
+ #
90
+ #
91
+ #
92
+ def s3
93
+ ::UzuUzu.s3
87
94
  end
88
95
 
89
96
  #
@@ -28,8 +28,8 @@ module UzuUzu
28
28
  def render(view, options={}, locals={}, &block)
29
29
  view_path = nil
30
30
  catch(:view_finded) do
31
- _view_path = "#{application.view_root}#{view}" if view[0] == '/'
32
- _view_path ||= "#{application.view_root}#{helper.route}/#{view}"
31
+ _view_path = "#{application.view_root}#{helper.route}"
32
+ p _view_path
33
33
  ::Tilt.mappings.each_key do |key|
34
34
  _path = "#{_view_path}.#{key}"
35
35
  if ::File.file?(_path)
@@ -38,6 +38,16 @@ module UzuUzu
38
38
  Environments.current.logger
39
39
  end
40
40
 
41
+ #
42
+ def dm
43
+ Environments.current.dm
44
+ end
45
+
46
+ #
47
+ def s3
48
+ Environments.current.s3
49
+ end
50
+
41
51
  #
42
52
  def memcache
43
53
  Environments.current.memcache
@@ -0,0 +1,137 @@
1
+ # coding: utf-8
2
+ require 'dm-core'
3
+
4
+ module UzuUzu
5
+ module Wrapper
6
+ class Dm
7
+ #
8
+ attr_reader :adapter
9
+ #
10
+ attr_reader :repositories
11
+
12
+ #
13
+ #
14
+ #
15
+ def initialize(env=nil)
16
+ if env.nil?
17
+ return
18
+ end
19
+
20
+ unless env['logger'].nil?
21
+ DataMapper::logger = ::UzuUzu::Wrapper::Logger.new(env['logger']).logger
22
+ end
23
+ @repositories = []
24
+ env.each do |key, value|
25
+ @repositories.push key.to_sym
26
+ if value['adapter']
27
+ @adapter = value['adapter']
28
+ DataMapper.setup(key.to_sym, value)
29
+ if value['logger']
30
+ case(value['adapter'])
31
+ when 'sqlite3'
32
+ DataObjects::Sqlite3.logger = ::UzuUzu::Wrapper::Logger.new(value['logger']).logger
33
+ when 'postgres'
34
+ DataObjects::Postgres.logger = ::UzuUzu::Wrapper::Logger.new(value['logger']).logger
35
+ when 'mysql'
36
+ DataObjects::MySql.logger = ::UzuUzu::Wrapper::Logger.new(value['logger']).logger
37
+ end
38
+ end
39
+ end
40
+ end # repositories_env.each
41
+ end # new
42
+
43
+ #
44
+ #
45
+ #
46
+ def import_file(model, file, overwrite=false)
47
+ unless ::File.file?(file)
48
+ raise "UzuUzu fixture import error file not found : #{file}"
49
+ end
50
+ ext = ::File.extname(file)
51
+ case(ext)
52
+ when '.yml', '.yaml'
53
+ import_yaml(model, ::YAML.load_file(file), overwrite)
54
+ when '.xml'
55
+ # TODO
56
+ when '.json', '.js'
57
+ # TODO
58
+ when '.csv'
59
+ begin
60
+ require 'fastercsv'
61
+ ::FasterCSV.foreach(file) do |row|
62
+ import_csv(model, row, overwrite)
63
+ end
64
+ rescue
65
+ require "csv"
66
+ ::CSV.open(file) do |row|
67
+ import_csv(model, row, overwrite)
68
+ end
69
+ end
70
+ end
71
+ nil
72
+ end # import_file
73
+
74
+ def import_yaml(model, yaml, overwrite=false)
75
+ ::UzuUzu.logger.debug 'import yaml'
76
+ if yaml.kind_of?(Array)
77
+ yaml.each do |map|
78
+ ::UzuUzu.logger.debug "import #{map.inspect}"
79
+ resource = model.first(:id => map[:id]) unless map[:id].nil?
80
+ if resource.nil?
81
+ resource = model.new(map)
82
+ unless resource.valid?
83
+ ::UzuUzu.logger.error resource.errors
84
+ end
85
+ resource.save
86
+ elsif overwrite
87
+ resource.update(map)
88
+ unless resource.valid?
89
+ ::UzuUzu.logger.error resource.errors
90
+ end
91
+ end
92
+ end
93
+ elsif yaml.kind_of?(Hash)
94
+ ::UzuUzu.logger.debug "import #{yaml.inspect}"
95
+ resource = model.first(:id => yaml[:id]) unless yaml[:id].nil?
96
+ if resource.nil?
97
+ resource = model.new(yaml)
98
+ unless resource.valid?
99
+ ::UzuUzu.logger.error resource.errors
100
+ end
101
+ resource.save
102
+ elsif overwrite
103
+ resource.update(yaml)
104
+ unless resource.valid?
105
+ ::UzuUzu.logger.error resource.errors
106
+ end
107
+ end
108
+ else
109
+ ::UzuUzu.logger.error "import type miss match #{yaml.inspect}"
110
+ end
111
+ ::UzuUzu.logger.debug 'imported yaml'
112
+ end # import_yaml
113
+
114
+ def import_json(model, json, overwrite=false)
115
+ # TODO
116
+ end # import_json
117
+
118
+ def import_xml(model, xml, overwrite=false)
119
+ # TODO
120
+ end # import_xml
121
+
122
+ def import_csv(model, csv, overwrite=false)
123
+ resource = model.first(:id => csv[0])
124
+ csv.each_with_index do |culumn, index|
125
+ if resource.nil? || overwrite
126
+ resource ||= model.new
127
+ resource.properties.each_with_index do |property, column_no|
128
+ resource[property.name] = culumn if index = column_no
129
+ end
130
+ resource.save
131
+ end
132
+ end
133
+ end # import_csv
134
+
135
+ end # Dm
136
+ end # Wrapper
137
+ end # UzuUzu
@@ -0,0 +1,52 @@
1
+ # coding: utf-8
2
+ require 'right_aws'
3
+
4
+ module UzuUzu
5
+ module Wrapper
6
+ class S3
7
+ #
8
+ attr_reader :s3
9
+ #
10
+ attr_reader :buckets
11
+
12
+ #
13
+ #
14
+ #
15
+ def initialize(env=nil)
16
+ if env.nil?
17
+ return
18
+ end
19
+ @env = env.dup
20
+ @buckets_env = @env['buckets'].dup
21
+ @access_key = @env['access_key'] || @env[:access_key] ||''
22
+ @secret_key = @env['secret_key'] || @env[:secret_key] ||''
23
+
24
+ params = {}
25
+ params[:server] = @env['server'] unless @env['server'] .blank?
26
+ params[:port] = @env['port'] unless @env['port'] .blank?
27
+ params[:protocol] = @env['protocol'] unless @env['protocol'] .blank?
28
+ params[:logger] = ::UzuUzu.logger
29
+ @s3 = ::RightAws::S3.new(@access_key, @secret_key, params)
30
+ @buckets = {}
31
+ end # new
32
+
33
+ #
34
+ #
35
+ #
36
+ def method_missing(name, *args)
37
+ name = name.to_s
38
+ if @buckets_env[name].nil?
39
+ return nil
40
+ end
41
+ if @buckets[name].nil?
42
+ params = {}
43
+ params[:location] = @buckets_env[name]['location'] unless @buckets_env[name]['location'].blank?
44
+ params = nil if params.blank?
45
+ @buckets[name] = @s3.bucket(@buckets_env[name]['name'], true, params)
46
+ end
47
+ @buckets[name]
48
+ end # method_missing
49
+
50
+ end # S3
51
+ end # Wrapper
52
+ end # UzuUzu
data/lib/uzuuzu_core.rb CHANGED
@@ -9,6 +9,8 @@ require 'tilt'
9
9
  require 'uzuuzu-core/ext/object'
10
10
  require 'uzuuzu-core/uzuuzu-core'
11
11
  require 'uzuuzu-core/wrapper/logger'
12
+ require 'uzuuzu-core/wrapper/dm'
13
+ require 'uzuuzu-core/wrapper/s3'
12
14
  require 'uzuuzu-core/wrapper/wrapper'
13
15
  require 'uzuuzu-core/application'
14
16
  require 'uzuuzu-core/environments'
data/uzuuzu-core.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{uzuuzu-core}
8
- s.version = "0.1.10"
8
+ s.version = "0.1.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Takuya Kondo"]
12
- s.date = %q{2012-01-03}
12
+ s.date = %q{2012-01-09}
13
13
  s.description = %q{uzuuzu core library}
14
14
  s.email = %q{takuya_v_v@uzuuzu.jp}
15
15
  s.extra_rdoc_files = [
@@ -26,14 +26,15 @@ Gem::Specification.new do |s|
26
26
  "README.rdoc",
27
27
  "Rakefile",
28
28
  "VERSION",
29
+ "lib/dm-simpledb-adapter.rb",
29
30
  "lib/uzuuzu-core/application.rb",
30
31
  "lib/uzuuzu-core/controller.rb",
31
32
  "lib/uzuuzu-core/controller/index.rb",
32
33
  "lib/uzuuzu-core/controller/login/facebook.rb",
33
34
  "lib/uzuuzu-core/controller/login/google.rb",
34
35
  "lib/uzuuzu-core/controller/login/twitter.rb",
35
- "lib/uzuuzu-core/controller/view/error/404.rhtml",
36
- "lib/uzuuzu-core/controller/view/error/500.rhtml",
36
+ "lib/uzuuzu-core/controller/view/index/error/404.rhtml",
37
+ "lib/uzuuzu-core/controller/view/index/error/500.rhtml",
37
38
  "lib/uzuuzu-core/environments.rb",
38
39
  "lib/uzuuzu-core/ext/object.rb",
39
40
  "lib/uzuuzu-core/helper.rb",
@@ -62,7 +63,9 @@ Gem::Specification.new do |s|
62
63
  "lib/uzuuzu-core/response.rb",
63
64
  "lib/uzuuzu-core/tilt.rb",
64
65
  "lib/uzuuzu-core/uzuuzu-core.rb",
66
+ "lib/uzuuzu-core/wrapper/dm.rb",
65
67
  "lib/uzuuzu-core/wrapper/logger.rb",
68
+ "lib/uzuuzu-core/wrapper/s3.rb",
66
69
  "lib/uzuuzu-core/wrapper/wrapper.rb",
67
70
  "lib/uzuuzu_core.rb",
68
71
  "spec/spec_helper.rb",
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: uzuuzu-core
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.10
5
+ version: 0.1.11
6
6
  platform: ruby
7
7
  authors:
8
8
  - Takuya Kondo
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-01-03 00:00:00 +09:00
13
+ date: 2012-01-09 00:00:00 +09:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -142,14 +142,15 @@ files:
142
142
  - README.rdoc
143
143
  - Rakefile
144
144
  - VERSION
145
+ - lib/dm-simpledb-adapter.rb
145
146
  - lib/uzuuzu-core/application.rb
146
147
  - lib/uzuuzu-core/controller.rb
147
148
  - lib/uzuuzu-core/controller/index.rb
148
149
  - lib/uzuuzu-core/controller/login/facebook.rb
149
150
  - lib/uzuuzu-core/controller/login/google.rb
150
151
  - lib/uzuuzu-core/controller/login/twitter.rb
151
- - lib/uzuuzu-core/controller/view/error/404.rhtml
152
- - lib/uzuuzu-core/controller/view/error/500.rhtml
152
+ - lib/uzuuzu-core/controller/view/index/error/404.rhtml
153
+ - lib/uzuuzu-core/controller/view/index/error/500.rhtml
153
154
  - lib/uzuuzu-core/environments.rb
154
155
  - lib/uzuuzu-core/ext/object.rb
155
156
  - lib/uzuuzu-core/helper.rb
@@ -178,7 +179,9 @@ files:
178
179
  - lib/uzuuzu-core/response.rb
179
180
  - lib/uzuuzu-core/tilt.rb
180
181
  - lib/uzuuzu-core/uzuuzu-core.rb
182
+ - lib/uzuuzu-core/wrapper/dm.rb
181
183
  - lib/uzuuzu-core/wrapper/logger.rb
184
+ - lib/uzuuzu-core/wrapper/s3.rb
182
185
  - lib/uzuuzu-core/wrapper/wrapper.rb
183
186
  - lib/uzuuzu_core.rb
184
187
  - spec/spec_helper.rb
@@ -198,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
198
201
  requirements:
199
202
  - - ">="
200
203
  - !ruby/object:Gem::Version
201
- hash: 2546083607633769446
204
+ hash: -4154038049771216448
202
205
  segments:
203
206
  - 0
204
207
  version: "0"