lib/restfulx/configuration.rb in dima-restfulx-1.2.2 vs lib/restfulx/configuration.rb in dima-restfulx-1.2.3

- old
+ new

@@ -1,8 +1,17 @@ # Interestingly enough there's no way to *just* upper-case or down-case first letter of a given # string. Ruby's own +capitalize+ actually downcases all the rest of the characters in the string # We patch the class to add our own implementation. +require "yaml" +require "erb" +require File.dirname(__FILE__) + "/rails/schema_to_yaml/settings/config" +require File.dirname(__FILE__) + "/rails/schema_to_yaml/settings/core" + +Dir[File.dirname(__FILE__) + "/rails/schema_to_yaml/extensions/*.rb"].each do |f| + require f +end + class String # Upper-case first character of a string leave the rest of the string intact def ucfirst self[0,1].capitalize + self[1..-1] end @@ -11,37 +20,22 @@ def dcfirst self[0,1].downcase + self[1..-1] end end +# Primary RestfulX configuration options module RestfulX # Computes necessary configuration options from the environment. This can be used in Rails, Merb # or standalone from the command line. module Configuration + # We try to figure out the application root using a number of possible options APP_ROOT = defined?(RAILS_ROOT) ? RAILS_ROOT : defined?(Merb) ? Merb.root : File.expand_path(".") + + RxSettings = SchemaToYaml::Settings::Core - # Extract project, package, controller names from the environment. This will respect - # config/restfulx.yml if it exists, you can override all of the defaults there. The defaults are: - # - *base-package* same as project name downcased - # - *controller-name* 'ApplicationController' - # - # Here's a sample restfulx.yml file: - # - # RestfulX code generation configuration options - # - # By default flex models, commands, controllers and components are genearated into - # app/flex/<your rails project name> folder. If you'd like to customize the target folder - # (to say append a "com" package before your rails project name) uncomment the line below - # base-package must follow the usual flex package notation (a string separated by ".") - # - # base-package: com.pomodo - # - # Main RestfulX controller is typically named AppicationController. This controller is created in - # <base-package>.controllers folder. You can customize the name by uncommenting the following line - # and changing the controller name. - # - # controller-name: ApplicationController + # Extract project, package, controller name, etc from the environment. This will respect + # config/restfulx.yml if it exists, you can override all of the defaults there. def extract_names(project = nil) if project project_name = project.downcase.gsub(/\W/, '') flex_project_name = project_name.camelize else @@ -50,15 +44,15 @@ end # give a chance to override the settings via restfulx.yml begin config = YAML.load(File.open("#{APP_ROOT}/config/restfulx.yml")) - base_package = config['base-package'] || flex_project_name.downcase - base_folder = base_package.gsub('.', '/').gsub(/\W/, '') - project_name = config['project-name'].downcase.gsub(/\W/, '') || project_name + base_package = config['base_package'] || flex_project_name.downcase + base_folder = base_package.gsub('.', '/') + project_name = config['project_name'].downcase.gsub(/\W/, '') || project_name flex_project_name = project_name.camelize - controller_name = config['controller-name'] || "ApplicationController" - flex_root = config['flex-root'] || "app/flex" + controller_name = config['controller_name'] || "ApplicationController" + flex_root = config['flex_root'] || "app/flex" distributed = config['distributed'] || false rescue base_folder = base_package = flex_project_name.downcase controller_name = "ApplicationController" flex_root = "app/flex" \ No newline at end of file