volt 0.8.15 → 0.8.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +11 -0
  3. data/CHANGELOG.md +11 -0
  4. data/Gemfile +1 -1
  5. data/Guardfile +2 -3
  6. data/Rakefile +1 -4
  7. data/VERSION +1 -1
  8. data/app/volt/controllers/notices_controller.rb +1 -1
  9. data/app/volt/tasks/live_query/data_store.rb +7 -7
  10. data/app/volt/tasks/live_query/live_query.rb +7 -9
  11. data/app/volt/tasks/live_query/live_query_pool.rb +13 -12
  12. data/app/volt/tasks/live_query/query_tracker.rb +4 -5
  13. data/app/volt/tasks/query_tasks.rb +9 -11
  14. data/app/volt/tasks/store_tasks.rb +4 -4
  15. data/app/volt/tasks/user_tasks.rb +1 -1
  16. data/bin/volt +2 -2
  17. data/lib/volt.rb +3 -7
  18. data/lib/volt/assets/test.rb +1 -2
  19. data/lib/volt/benchmark/benchmark.rb +3 -3
  20. data/lib/volt/boot.rb +1 -1
  21. data/lib/volt/cli.rb +18 -18
  22. data/lib/volt/cli/asset_compile.rb +8 -10
  23. data/lib/volt/cli/generate.rb +9 -11
  24. data/lib/volt/cli/new_gem.rb +51 -51
  25. data/lib/volt/config.rb +2 -3
  26. data/lib/volt/console.rb +1 -1
  27. data/lib/volt/controllers/model_controller.rb +6 -6
  28. data/lib/volt/data_stores/data_store.rb +1 -1
  29. data/lib/volt/data_stores/mongo_driver.rb +1 -1
  30. data/lib/volt/extra_core/array.rb +2 -2
  31. data/lib/volt/extra_core/blank.rb +1 -2
  32. data/lib/volt/extra_core/extra_core.rb +1 -1
  33. data/lib/volt/extra_core/inflector/methods.rb +0 -1
  34. data/lib/volt/extra_core/logger.rb +13 -7
  35. data/lib/volt/extra_core/numeric.rb +1 -1
  36. data/lib/volt/extra_core/string.rb +7 -7
  37. data/lib/volt/extra_core/stringify_keys.rb +5 -5
  38. data/lib/volt/models.rb +2 -2
  39. data/lib/volt/models/array_model.rb +18 -19
  40. data/lib/volt/models/cursor.rb +0 -1
  41. data/lib/volt/models/model.rb +17 -35
  42. data/lib/volt/models/model_hash_behaviour.rb +0 -2
  43. data/lib/volt/models/model_state.rb +1 -1
  44. data/lib/volt/models/model_wrapper.rb +1 -1
  45. data/lib/volt/models/persistors/array_store.rb +26 -13
  46. data/lib/volt/models/persistors/base.rb +1 -1
  47. data/lib/volt/models/persistors/flash.rb +2 -2
  48. data/lib/volt/models/persistors/local_store.rb +2 -3
  49. data/lib/volt/models/persistors/model_store.rb +7 -6
  50. data/lib/volt/models/persistors/params.rb +2 -2
  51. data/lib/volt/models/persistors/query/query_listener.rb +2 -0
  52. data/lib/volt/models/persistors/query/query_listener_pool.rb +1 -1
  53. data/lib/volt/models/persistors/store.rb +1 -2
  54. data/lib/volt/models/persistors/store_state.rb +2 -3
  55. data/lib/volt/models/url.rb +17 -16
  56. data/lib/volt/models/validations.rb +11 -14
  57. data/lib/volt/models/validators/length_validator.rb +3 -3
  58. data/lib/volt/models/validators/presence_validator.rb +2 -2
  59. data/lib/volt/page/bindings/attribute_binding.rb +2 -3
  60. data/lib/volt/page/bindings/base_binding.rb +1 -1
  61. data/lib/volt/page/bindings/each_binding.rb +8 -9
  62. data/lib/volt/page/bindings/event_binding.rb +2 -3
  63. data/lib/volt/page/bindings/template_binding.rb +8 -7
  64. data/lib/volt/page/bindings/template_binding/grouped_controllers.rb +2 -1
  65. data/lib/volt/page/channel.rb +10 -10
  66. data/lib/volt/page/channel_stub.rb +1 -1
  67. data/lib/volt/page/document.rb +0 -1
  68. data/lib/volt/page/document_events.rb +4 -4
  69. data/lib/volt/page/page.rb +26 -19
  70. data/lib/volt/page/string_template_renderer.rb +2 -2
  71. data/lib/volt/page/sub_context.rb +10 -4
  72. data/lib/volt/page/targets/attribute_section.rb +1 -1
  73. data/lib/volt/page/targets/attribute_target.rb +1 -2
  74. data/lib/volt/page/targets/base_section.rb +4 -4
  75. data/lib/volt/page/targets/binding_document/base_node.rb +0 -1
  76. data/lib/volt/page/targets/binding_document/component_node.rb +4 -5
  77. data/lib/volt/page/targets/dom_section.rb +21 -22
  78. data/lib/volt/page/targets/dom_target.rb +1 -1
  79. data/lib/volt/page/targets/dom_template.rb +11 -12
  80. data/lib/volt/page/targets/helpers/comment_searchers.rb +7 -8
  81. data/lib/volt/page/tasks.rb +0 -1
  82. data/lib/volt/page/template_renderer.rb +1 -1
  83. data/lib/volt/page/url_tracker.rb +3 -3
  84. data/lib/volt/reactive/computation.rb +5 -11
  85. data/lib/volt/reactive/dependency.rb +1 -3
  86. data/lib/volt/reactive/eventable.rb +17 -4
  87. data/lib/volt/reactive/hash_dependency.rb +1 -0
  88. data/lib/volt/reactive/reactive_accessors.rb +0 -1
  89. data/lib/volt/reactive/reactive_array.rb +20 -25
  90. data/lib/volt/reactive/reactive_hash.rb +3 -3
  91. data/lib/volt/router/routes.rb +11 -13
  92. data/lib/volt/server.rb +17 -17
  93. data/lib/volt/server/component_handler.rb +2 -2
  94. data/lib/volt/server/component_templates.rb +8 -8
  95. data/lib/volt/server/html_parser/attribute_scope.rb +9 -10
  96. data/lib/volt/server/html_parser/if_view_scope.rb +2 -2
  97. data/lib/volt/server/html_parser/sandlebars_parser.rb +14 -14
  98. data/lib/volt/server/html_parser/textarea_scope.rb +1 -2
  99. data/lib/volt/server/html_parser/view_handler.rb +1 -1
  100. data/lib/volt/server/html_parser/view_parser.rb +1 -1
  101. data/lib/volt/server/html_parser/view_scope.rb +10 -10
  102. data/lib/volt/server/rack/asset_files.rb +15 -16
  103. data/lib/volt/server/rack/component_code.rb +2 -2
  104. data/lib/volt/server/rack/component_html_renderer.rb +0 -1
  105. data/lib/volt/server/rack/component_paths.rb +13 -10
  106. data/lib/volt/server/rack/index_files.rb +4 -4
  107. data/lib/volt/server/rack/opal_files.rb +4 -5
  108. data/lib/volt/server/rack/source_map_server.rb +3 -3
  109. data/lib/volt/server/socket_connection_handler.rb +3 -4
  110. data/lib/volt/server/socket_connection_handler_stub.rb +1 -1
  111. data/lib/volt/spec/setup.rb +3 -3
  112. data/lib/volt/store/mongo.rb +2 -2
  113. data/lib/volt/tasks/task_handler.rb +3 -3
  114. data/lib/volt/utils/generic_counting_pool.rb +2 -2
  115. data/lib/volt/utils/generic_pool.rb +7 -8
  116. data/lib/volt/utils/local_storage.rb +4 -4
  117. data/lib/volt/volt/environment.rb +1 -1
  118. data/spec/apps/file_loading/app/shared/config/dependencies.rb +1 -1
  119. data/spec/apps/kitchen_sink/Gemfile +0 -2
  120. data/spec/apps/kitchen_sink/app/main/config/routes.rb +5 -5
  121. data/spec/apps/kitchen_sink/app/main/controllers/main_controller.rb +7 -6
  122. data/spec/apps/kitchen_sink/app/main/controllers/todos_controller.rb +3 -4
  123. data/spec/controllers/reactive_accessors_spec.rb +4 -4
  124. data/spec/extra_core/inflector_spec.rb +1 -1
  125. data/spec/extra_core/string_transformation_test_cases.rb +23 -24
  126. data/spec/extra_core/string_transformations_spec.rb +11 -12
  127. data/spec/integration/bindings_spec.rb +15 -15
  128. data/spec/integration/list_spec.rb +12 -13
  129. data/spec/integration/templates_spec.rb +3 -3
  130. data/spec/models/model_spec.rb +74 -80
  131. data/spec/models/persistors/params_spec.rb +2 -2
  132. data/spec/models/persistors/store_spec.rb +4 -4
  133. data/spec/models/validations_spec.rb +14 -23
  134. data/spec/page/bindings/content_binding_spec.rb +7 -8
  135. data/spec/page/bindings/template_binding_spec.rb +22 -24
  136. data/spec/page/sub_context_spec.rb +2 -2
  137. data/spec/reactive/computation_spec.rb +3 -3
  138. data/spec/reactive/reactive_array_spec.rb +12 -12
  139. data/spec/router/routes_spec.rb +45 -48
  140. data/spec/server/html_parser/sandlebars_parser_spec.rb +42 -42
  141. data/spec/server/html_parser/view_parser_spec.rb +132 -153
  142. data/spec/server/rack/asset_files_spec.rb +9 -8
  143. data/spec/server/rack/component_paths_spec.rb +5 -5
  144. data/spec/server/rack/rack_requests_spec.rb +3 -3
  145. data/spec/spec_helper.rb +1 -1
  146. data/spec/tasks/live_query_spec.rb +4 -5
  147. data/spec/tasks/query_tasks.rb +2 -4
  148. data/spec/tasks/query_tracker_spec.rb +29 -29
  149. data/spec/templates/targets/binding_document/component_node_spec.rb +1 -1
  150. data/spec/utils/generic_counting_pool_spec.rb +4 -4
  151. data/spec/utils/generic_pool_spec.rb +12 -12
  152. data/templates/component/config/routes.rb +2 -2
  153. data/templates/component/controllers/main_controller.rb +7 -6
  154. data/templates/newgem/app/newgem/config/dependencies.rb +1 -1
  155. data/templates/newgem/app/newgem/config/routes.rb +1 -1
  156. data/templates/project/app/main/config/routes.rb +2 -2
  157. data/templates/project/app/main/controllers/main_controller.rb +7 -6
  158. data/templates/project/spec/sample_spec.rb +2 -2
  159. data/volt.gemspec +32 -33
  160. metadata +3 -4
  161. data/lib/volt/extra_core/log.rb +0 -56
  162. data/lib/volt/extra_core/try.rb +0 -31
@@ -1,13 +1,12 @@
1
1
  module Volt
2
2
  class CLI
3
-
4
- desc "precompile", "precompile all application assets"
3
+ desc 'precompile', 'precompile all application assets'
5
4
 
6
5
  def precompile
7
6
  compile
8
7
  end
9
8
 
10
- desc "watch", "compiles the project to /compiled when a file changes"
9
+ desc 'watch', 'compiles the project to /compiled when a file changes'
11
10
 
12
11
  def watch
13
12
  require 'listen'
@@ -18,7 +17,7 @@ module Volt
18
17
 
19
18
  listener.start # non-blocking
20
19
 
21
- Signal.trap("SIGINT") do
20
+ Signal.trap('SIGINT') do
22
21
  listener.stop
23
22
  end
24
23
 
@@ -32,8 +31,9 @@ module Volt
32
31
  end
33
32
 
34
33
  private
34
+
35
35
  def compile
36
- print "compiling project..."
36
+ print 'compiling project...'
37
37
  require 'fileutils'
38
38
  require 'opal'
39
39
  require 'volt'
@@ -46,7 +46,7 @@ module Volt
46
46
  @root_path ||= Dir.pwd
47
47
  Volt.root = @root_path
48
48
 
49
- @app_path = File.expand_path(File.join(@root_path, "app"))
49
+ @app_path = File.expand_path(File.join(@root_path, 'app'))
50
50
 
51
51
  @component_paths = ComponentPaths.new(@root_path)
52
52
  @app = Rack::Builder.new
@@ -67,7 +67,7 @@ module Volt
67
67
  @opal_files.environment.each_logical_path do |logical_path|
68
68
  logical_path = logical_path.to_s
69
69
  # Only include files that aren't compiled elsewhere, like fonts
70
- if !logical_path[/[.](y|css|js|html|erb)$/]
70
+ unless logical_path[/[.](y|css|js|html|erb)$/]
71
71
  write_file(logical_path)
72
72
  end
73
73
  end
@@ -78,7 +78,6 @@ module Volt
78
78
  logical_path = logical_path.gsub(/^\/assets\//, '')
79
79
  write_file(logical_path)
80
80
  end
81
-
82
81
  end
83
82
 
84
83
  def write_file(logical_path)
@@ -88,7 +87,7 @@ module Volt
88
87
 
89
88
  begin
90
89
  content = @opal_files.environment[logical_path].to_s
91
- File.open(path, "wb") do |file|
90
+ File.open(path, 'wb') do |file|
92
91
  file.write(content)
93
92
  end
94
93
  rescue Sprockets::FileNotFound, SyntaxError => e
@@ -106,7 +105,6 @@ module Volt
106
105
  end
107
106
  end
108
107
 
109
-
110
108
  def write_index
111
109
  path = "#{@root_path}/compiled/index.html"
112
110
  FileUtils.mkdir_p(File.dirname(path))
@@ -1,26 +1,24 @@
1
1
  class Generate < Thor
2
2
  include Thor::Actions
3
3
 
4
- desc "model NAME COMPONENT", "Creates a model named NAME in the component named COMPONENT"
5
- method_option :name, :type => :string, :banner => "The name of the model."
6
- method_option :component, :type => :string, :default => 'main', :banner => "The component the model should be created in.", :required => false
7
- def model(name, component='main')
4
+ desc 'model NAME COMPONENT', 'Creates a model named NAME in the component named COMPONENT'
5
+ method_option :name, type: :string, banner: 'The name of the model.'
6
+ method_option :component, type: :string, default: 'main', banner: 'The component the model should be created in.', required: false
7
+ def model(name, component = 'main')
8
8
  output_file = Dir.pwd + "/app/#{component.underscore}/models/#{name.underscore.singularize}.rb"
9
- template("model/model.rb.tt", output_file, {model_name: name.camelize.singularize})
9
+ template('model/model.rb.tt', output_file, model_name: name.camelize.singularize)
10
10
  end
11
11
 
12
- desc "component NAME", "Creates a component named NAME in the app folder."
13
- method_option :name, :type => :string, :banner => "The name of the component."
12
+ desc 'component NAME', 'Creates a component named NAME in the app folder.'
13
+ method_option :name, type: :string, banner: 'The name of the component.'
14
14
  def component(name)
15
15
  name = name.underscore
16
16
  component_folder = Dir.pwd + "/app/#{name}"
17
17
  @component_name = name
18
- directory("component", component_folder, {component_name: name})
18
+ directory('component', component_folder, component_name: name)
19
19
  end
20
20
 
21
-
22
21
  def self.source_root
23
22
  File.expand_path(File.join(File.dirname(__FILE__), '../../../templates'))
24
23
  end
25
-
26
- end
24
+ end
@@ -1,5 +1,5 @@
1
- require "net/http"
2
- require "uri"
1
+ require 'net/http'
2
+ require 'uri'
3
3
  require 'fileutils'
4
4
 
5
5
  # Creates a new "volt" gem, which can be used to easily repackage
@@ -7,8 +7,8 @@ require 'fileutils'
7
7
  class NewGem
8
8
  def initialize(thor, name, options)
9
9
  @thor = thor
10
- @component_name = name.chomp("/")
11
- @name = "volt-" + @component_name # remove trailing slash if present
10
+ @component_name = name.chomp('/')
11
+ @name = 'volt-' + @component_name # remove trailing slash if present
12
12
 
13
13
  if gem_is_available?
14
14
  @thor.say("#{@name} is available! Making gem files.", :green)
@@ -37,80 +37,80 @@ class NewGem
37
37
  request = Net::HTTP::Get.new(uri.request_uri)
38
38
  response = http.request(request)
39
39
 
40
- return response.code == "404"
40
+ return response.code == '404'
41
41
  rescue SocketError => e
42
42
  # rubygems is down, skip check
43
43
  return true
44
44
  end
45
45
 
46
46
  def copy_files
47
- @thor.directory("newgem/app/newgem", File.join("#{@target}", "app/#{@component_name}"), @opts)
48
- copy("newgem/Gemfile.tt", "Gemfile")
49
- copy("newgem/Rakefile.tt", "Rakefile")
50
- copy("newgem/README.md.tt", "README.md")
51
- copy("newgem/gitignore.tt", ".gitignore")
52
- copy("newgem/newgem.gemspec.tt", "#{@name}.gemspec")
53
- copy("newgem/lib/newgem.rb.tt", "lib/#{@namespaced_path}.rb")
54
- copy("newgem/VERSION", "VERSION")
47
+ @thor.directory('newgem/app/newgem', File.join("#{@target}", "app/#{@component_name}"), @opts)
48
+ copy('newgem/Gemfile.tt', 'Gemfile')
49
+ copy('newgem/Rakefile.tt', 'Rakefile')
50
+ copy('newgem/README.md.tt', 'README.md')
51
+ copy('newgem/gitignore.tt', '.gitignore')
52
+ copy('newgem/newgem.gemspec.tt', "#{@name}.gemspec")
53
+ copy('newgem/lib/newgem.rb.tt', "lib/#{@namespaced_path}.rb")
54
+ copy('newgem/VERSION', 'VERSION')
55
55
  FileUtils.mkdir_p(File.join(@target, "lib/#{@namespaced_path}"))
56
56
  end
57
57
 
58
58
  def copy_options
59
59
  if @options[:bin]
60
- copy("newgem/bin/newgem.tt", "bin/#{@name}")
60
+ copy('newgem/bin/newgem.tt', "bin/#{@name}")
61
61
  end
62
62
  case @options[:test]
63
63
  when 'rspec'
64
- copy("newgem/rspec.tt", ".rspec")
65
- copy("newgem/spec/spec_helper.rb.tt", "spec/spec_helper.rb")
66
- copy("newgem/spec/newgem_spec.rb.tt", "spec/#{@namespaced_path}_spec.rb")
64
+ copy('newgem/rspec.tt', '.rspec')
65
+ copy('newgem/spec/spec_helper.rb.tt', 'spec/spec_helper.rb')
66
+ copy('newgem/spec/newgem_spec.rb.tt', "spec/#{@namespaced_path}_spec.rb")
67
67
  when 'minitest'
68
- copy("newgem/test/minitest_helper.rb.tt", "test/minitest_helper.rb")
69
- copy("newgem/test/test_newgem.rb.tt", "test/test_#{@namespaced_path}.rb")
68
+ copy('newgem/test/minitest_helper.rb.tt', 'test/minitest_helper.rb')
69
+ copy('newgem/test/test_newgem.rb.tt', "test/test_#{@namespaced_path}.rb")
70
70
  end
71
71
  puts "Initializing git repo in #{@target}"
72
72
  Dir.chdir(@target) { `git init`; `git add .` }
73
73
 
74
74
  if @options[:edit]
75
- run("#{@options["edit"]} \"#{gemspec_dest}\"") # Open gemspec in editor
75
+ run("#{@options['edit']} \"#{gemspec_dest}\"") # Open gemspec in editor
76
76
  end
77
77
  end
78
78
 
79
79
  private
80
- def copy(from, to)
81
- @thor.template(File.join(from), File.join(@target, to), @opts)
82
- end
83
80
 
84
- def gem_options
85
- constant_name = get_constant_name
86
- constant_array = constant_name.split('::')
87
- git_user_name = `git config user.name`.chomp
88
- git_user_email = `git config user.email`.chomp
89
-
90
- opts = {
91
- :name => @name,
92
- :namespaced_path => @namespaced_path,
93
- :constant_name => constant_name,
94
- :constant_array => constant_array,
95
- :author => git_user_name.empty? ? "TODO: Write your name" : git_user_name,
96
- :email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email,
97
- :test => @options[:test],
98
- :volt_version_base => volt_version_base
99
- }
100
-
101
- return opts
102
- end
81
+ def copy(from, to)
82
+ @thor.template(File.join(from), File.join(@target, to), @opts)
83
+ end
103
84
 
104
- def volt_version_base
105
- version_path = File.join(File.dirname(__FILE__), '../../../VERSION')
106
- File.read(version_path).split('.').tap {|v| v[v.size-1] = 0 }.join('.')
107
- end
85
+ def gem_options
86
+ constant_name = get_constant_name
87
+ constant_array = constant_name.split('::')
88
+ git_user_name = `git config user.name`.chomp
89
+ git_user_email = `git config user.email`.chomp
90
+
91
+ opts = {
92
+ name: @name,
93
+ namespaced_path: @namespaced_path,
94
+ constant_name: constant_name,
95
+ constant_array: constant_array,
96
+ author: git_user_name.empty? ? 'TODO: Write your name' : git_user_name,
97
+ email: git_user_email.empty? ? 'TODO: Write your email address' : git_user_email,
98
+ test: @options[:test],
99
+ volt_version_base: volt_version_base
100
+ }
101
+
102
+ opts
103
+ end
108
104
 
109
- def get_constant_name
110
- constant_name = @name.split('_').map{|p| p[0..0].upcase + p[1..-1] }.join
111
- constant_name = constant_name.split('-').map{|q| q[0..0].upcase + q[1..-1] }.join('::') if constant_name =~ /-/
105
+ def volt_version_base
106
+ version_path = File.join(File.dirname(__FILE__), '../../../VERSION')
107
+ File.read(version_path).split('.').tap { |v| v[v.size - 1] = 0 }.join('.')
108
+ end
112
109
 
113
- return constant_name
114
- end
110
+ def get_constant_name
111
+ constant_name = @name.split('_').map { |p| p[0..0].upcase + p[1..-1] }.join
112
+ constant_name = constant_name.split('-').map { |q| q[0..0].upcase + q[1..-1] }.join('::') if constant_name =~ /-/
115
113
 
114
+ constant_name
115
+ end
116
116
  end
@@ -1,9 +1,8 @@
1
1
  # Config lets a user set global config options for Volt.
2
2
  module Volt
3
3
  module Config
4
-
5
4
  def setup
6
- yield self.config
5
+ yield config
7
6
  end
8
7
 
9
8
  def config
@@ -18,7 +17,7 @@ module Volt
18
17
  app_name: app_name,
19
18
  db_name: ENV['DB_NAME'] || (app_name + '_' + Volt.env.to_s),
20
19
  db_host: ENV['DB_HOST'] || 'localhost',
21
- db_port: (ENV['DB_PORT'] || 27017).to_i,
20
+ db_port: (ENV['DB_PORT'] || 27_017).to_i,
22
21
  db_driver: ENV['DB_DRIVER'] || 'mongo'
23
22
  )
24
23
  end
@@ -4,7 +4,7 @@ class Pry
4
4
  # To make the console more useful, we make it so we flush the event registry
5
5
  # after each line. This makes it so events are triggered after each line.
6
6
  # To accomplish this we monkey-patch pry.
7
- def rep(target=TOPLEVEL_BINDING)
7
+ def rep(target = TOPLEVEL_BINDING)
8
8
  target = Pry.binding_for(target)
9
9
  result = re(target)
10
10
 
@@ -18,14 +18,14 @@ module Volt
18
18
  if Symbol === val || String === val
19
19
  collections = [:page, :store, :params, :controller]
20
20
  if collections.include?(val.to_sym)
21
- self.current_model = self.send(val)
21
+ self.current_model = send(val)
22
22
  else
23
- raise "#{val} is not the name of a valid model, choose from: #{collections.join(', ')}"
23
+ fail "#{val} is not the name of a valid model, choose from: #{collections.join(', ')}"
24
24
  end
25
25
  elsif val
26
26
  self.current_model = val
27
27
  else
28
- raise "model can not be #{val.inspect}"
28
+ fail "model can not be #{val.inspect}"
29
29
  end
30
30
  end
31
31
 
@@ -37,17 +37,17 @@ module Volt
37
37
  model = model.call
38
38
  end
39
39
 
40
- return model
40
+ model
41
41
  end
42
42
 
43
43
  def self.new(*args, &block)
44
- inst = self.allocate
44
+ inst = allocate
45
45
 
46
46
  inst.model = (@default_model || :controller)
47
47
 
48
48
  inst.initialize(*args, &block)
49
49
 
50
- return inst
50
+ inst
51
51
  end
52
52
 
53
53
  attr_accessor :attrs
@@ -6,7 +6,7 @@ module Volt
6
6
  if Volt.config.db_driver == 'mongo'
7
7
  return MongoDriver.fetch
8
8
  else
9
- raise "#{database_name} is not a supported database"
9
+ fail "#{database_name} is not a supported database"
10
10
  end
11
11
  end
12
12
  end
@@ -7,7 +7,7 @@ module Volt
7
7
  @@mongo_db ||= Mongo::MongoClient.new(Volt.config.db_host, Volt.config.db_path)
8
8
  @@db ||= @@mongo_db.db(Volt.config.db_name)
9
9
 
10
- return @@db
10
+ @@db
11
11
  end
12
12
  end
13
13
  end
@@ -1,10 +1,10 @@
1
1
  class Array
2
2
  def sum
3
3
  total = 0
4
- self.each do |val|
4
+ each do |val|
5
5
  total += val
6
6
  end
7
7
 
8
- return total
8
+ total
9
9
  end
10
10
  end
@@ -17,7 +17,6 @@ class Object
17
17
  def present?
18
18
  !blank?
19
19
  end
20
-
21
20
  end
22
21
 
23
22
  class NilClass
@@ -73,7 +72,7 @@ class String
73
72
  def blank?
74
73
  # self !~ /[^[:space:]]/
75
74
  # TODO: Opal fails with the previous regex
76
- self.strip == ''
75
+ strip == ''
77
76
  end
78
77
  end
79
78
 
@@ -1,4 +1,4 @@
1
- require 'volt/extra_core/log'
1
+ require 'volt/extra_core/logger'
2
2
  require 'volt/extra_core/array'
3
3
  require 'volt/extra_core/object'
4
4
  require 'volt/extra_core/blank'
@@ -39,7 +39,6 @@ module Volt
39
39
  apply_inflections(word, inflections(locale).singulars)
40
40
  end
41
41
 
42
-
43
42
  private
44
43
 
45
44
  # Applies inflection rules for +singularize+ and +pluralize+.
@@ -1,12 +1,18 @@
1
- class Logger
2
- def initialize(log_to)
3
- end
1
+ if RUBY_PLATFORM == 'opal'
2
+ # The basic front-end logger, log to console
3
+ class Logger
4
+ def initialize(*args)
5
+ # TODO: handle options
6
+ end
4
7
 
5
- [:fatal, :info, :warn, :debug, :error].each do |method_name|
6
- define_method(method_name) do |text, &block|
7
- text = block.call if block
8
+ [:fatal, :info, :warn, :debug, :error].each do |method_name|
9
+ define_method(method_name) do |text, &block|
10
+ text = block.call if block
8
11
 
9
- `console[method_name](text);`
12
+ `console[method_name](text);`
13
+ end
10
14
  end
11
15
  end
16
+ else
17
+ require 'logger'
12
18
  end
@@ -6,4 +6,4 @@ class Numeric
6
6
  return "#{self} #{unit}s"
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -7,20 +7,20 @@ class String
7
7
  # Turns a string into the camel case version. If it is already camel case, it should
8
8
  # return the same string.
9
9
  def camelize(first_letter = :upper)
10
- new_str = self.gsub(/_[a-z]/) { |a| a[1].upcase }
10
+ new_str = gsub(/_[a-z]/) { |a| a[1].upcase }
11
11
  new_str = new_str[0].capitalize + new_str[1..-1] if first_letter == :upper
12
12
 
13
- return new_str
13
+ new_str
14
14
  end
15
15
 
16
16
  # Returns the underscore version of a string. If it is already underscore, it should
17
17
  # return the same string.
18
18
  def underscore
19
- self.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase
19
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
20
20
  end
21
21
 
22
22
  def dasherize
23
- self.gsub('_', '-')
23
+ gsub('_', '-')
24
24
  end
25
25
 
26
26
  def pluralize
@@ -32,16 +32,16 @@ class String
32
32
  end
33
33
 
34
34
  def titleize
35
- self.gsub('_', ' ').split(' ').map {|w| w.capitalize }.join(' ')
35
+ gsub('_', ' ').split(' ').map(&:capitalize).join(' ')
36
36
  end
37
37
 
38
38
  def plural?
39
39
  # TODO: Temp implementation
40
- self.pluralize == self
40
+ pluralize == self
41
41
  end
42
42
 
43
43
  def singular?
44
44
  # TODO: Temp implementation
45
- self.singularize == self
45
+ singularize == self
46
46
  end
47
47
  end