Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[merb-slices] AS migration

  • Loading branch information...
commit 77d1453d8af1903a0ff9a6289a9a1dcbe65b06ae 1 parent d1790ff
@ngollan ngollan authored
View
2  merb-slices/.rspec
@@ -1,4 +1,2 @@
--color
--format progress
---format html
---out rspec_results.html
View
12 merb-slices/lib/generators/base.rb
@@ -23,7 +23,11 @@ def initialize(*args)
end
class BaseSliceGenerator < NamedGenerator
-
+ def initialize(*args)
+ Merb.disable(:initfile)
+ super
+ end
+
def self.common_template(name, template_source)
common_base_dir = File.expand_path(File.dirname(__FILE__))
template name do |t|
@@ -31,9 +35,9 @@ def self.common_template(name, template_source)
t.destination = template_source
end
end
-
+
end
-
+
add :slice, SliceGenerator
-
+
end
View
8 merb-slices/lib/generators/full.rb
@@ -1,12 +1,6 @@
module Merb::Generators
class FullSliceGenerator < BaseSliceGenerator
-
- def initialize(*args)
- Merb.disable(:initfile)
- super
- end
-
def self.source_root
File.join(File.dirname(__FILE__), 'templates', 'full')
end
@@ -35,4 +29,4 @@ def destination_root
add_private :full_slice, FullSliceGenerator
-end
+end
View
14 merb-slices/lib/merb-slices/module.rb
@@ -1,5 +1,7 @@
# encoding: UTF-8
+require 'pathname'
+
module Merb
module Slices
@@ -11,7 +13,7 @@ class << self
#
# @return [Module] The slice module itself.
def [](module_name)
- Object.full_const_get(module_name.to_s) if exists?(module_name)
+ module_name.to_s.constantize if exists?(module_name)
end
# Helper method to transform a slice filename to a module Symbol.
@@ -62,8 +64,8 @@ def register(slice_file, force = true)
# given, `Merb::Plugins.config[:merb_slices][:search_path]` (String/Array)
def register_slices_from_search_path!
slice_files_from_search_path.each do |slice_file|
- absolute_path = File.expand_path(slice_file)
- Merb.logger.info!("Found slice '#{File.basename(absolute_path, '.rb')}' in search path at #{absolute_path.relative_path_from(Merb.root)}")
+ absolute_path = Pathname.new(File.expand_path(slice_file))
+ Merb.logger.info!("Found slice '#{File.basename(absolute_path, '.rb')}' in search path at #{absolute_path.relative_path_from(Pathname.new(Merb.root))}")
Merb::Slices::Loader.load_classes(absolute_path)
end
end
@@ -95,7 +97,7 @@ def unregister(slice_module)
# module name.
def activate(slice_module)
unless slice_file = self.files[slice_module.to_s]
- module_name_underscored = slice_module.to_s.snake_case.escape_regexp
+ module_name_underscored = slice_module.to_s.underscore.escape_regexp
module_name_dasherized = module_name_underscored.tr('_', '-').escape_regexp
regexp = Regexp.new(/\/(#{module_name_underscored}|#{module_name_dasherized})\/lib\/(#{module_name_underscored}|#{module_name_dasherized})\.rb$/)
slice_file = slice_files_from_search_path.find { |path| path.match(regexp) } # from search path(s)
@@ -217,7 +219,7 @@ def config
# @return [Array<Module>] A sorted array of all slice modules.
def slices
slice_names.map do |name|
- Object.full_const_get(name) rescue nil
+ name.constantize rescue nil
end.compact
end
@@ -305,7 +307,7 @@ def slice_files_from_search_path
# @return [Module] The module that has been setup.
def setup_module(module_name)
Object.make_module(module_name)
- slice_mod = Object.full_const_get(module_name)
+ slice_mod = module_name.constantize
slice_mod.extend(ModuleMixin)
slice_mod
end
View
8 merb-slices/lib/merb-slices/module_mixin.rb
@@ -169,7 +169,7 @@ def app_glob_for(type) self.app_paths[type][1] end
# requested type.
def public_dir_for(type)
dir = type.is_a?(Symbol) ? self.app_dir_for(type) : self.app_dir_for(:public) / type
- dir = dir.relative_path_from(Merb.dir_for(:public)) rescue '.'
+ dir = dir.relative_path_from(Merb.dir_for(:public))
dir == '.' ? '/' : "/#{dir}"
end
@@ -453,17 +453,17 @@ def setup_default_structure!
# using {Merb.push_path}.
def collect_load_paths(modify_load_path = true, push_merb_path = true)
self.collected_slice_paths.clear; self.collected_app_paths.clear
- Merb.push_path(:"#{self.name.snake_case}_file", File.dirname(self.file), File.basename(self.file))
+ Merb.push_path(:"#{self.name.underscore}_file", File.dirname(self.file), File.basename(self.file))
self.collected_app_paths << self.file
self.slice_paths.each do |component, path|
if File.directory?(component_path = path.first)
- $LOAD_PATH.unshift(component_path) if modify_load_path && component.in?(:model, :controller, :lib) && !$LOAD_PATH.include?(component_path)
+ $LOAD_PATH.unshift(component_path) if modify_load_path && [:model, :controller, :lib].include?(component) && !$LOAD_PATH.include?(component_path)
# slice-level component load path - will be preceded by application/app/component - loaded next by Setup.load_classes
self.collected_slice_paths << path.first / path.last if path.last
# app-level component load path (override) path - loaded by BootLoader::LoadClasses
if (app_glob = self.app_glob_for(component)) && File.directory?(app_component_dir = self.app_dir_for(component))
self.collected_app_paths << app_component_dir / app_glob
- Merb.push_path(:"#{self.name.snake_case}_#{component}", app_component_dir, app_glob) if push_merb_path
+ Merb.push_path(:"#{self.name.underscore}_#{component}", app_component_dir, app_glob) if push_merb_path
end
end
end
View
2  merb-slices/lib/merb-slices/router_ext.rb
@@ -47,7 +47,7 @@ def all_slices(config = {}, &block)
def add_slice(slice_module, options = {}, &block)
if Merb::Slices.exists?(slice_module)
options = { :path => options } if options.is_a?(String)
- slice_module = Object.full_const_get(slice_module.to_s.camelize) if slice_module.class.in?(String, Symbol)
+ slice_module = slice_module.to_s.camelize.constantize if [String, Symbol].include?(slice_module.class)
namespace = options[:namespace] || slice_module.identifier_sym
options[:path] ||= options[:path_prefix] || slice_module[:path_prefix] || options[:namespace] || slice_module.identifier
options[:prepend_routes] = block if block_given?
View
4 merb-slices/spec/full_slice_generator_spec.rb
@@ -15,7 +15,7 @@
it "should create a number of templates" do
@generator.invoke!
- files = Dir[slices_path / 'testing' / '**' / '*'].map do |path|
+ files = Dir[slices_path / 'testing' / '**' / '*'].map do |path|
path.relative_path_from(slices_path)
end
expected = [
@@ -46,4 +46,4 @@
end
-end
+end
View
2  merb-slices/spec/full_slice_spec.rb
@@ -159,4 +159,4 @@
controller.slice_url(:home).should == url
end
-end
+end
View
2  merb-slices/spec/slices/full-test-slice/app/views/layout/full_test_slice.html.erb
@@ -13,4 +13,4 @@
<div id="main"><%= catch_content :for_layout %></div>
</div>
</body>
-</html>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.