Module: RestfulX::Configuration

Defined in:
lib/restfulx/configuration.rb

Overview

Computes necessary configuration options from the environment. This can be used in Rails, Merb or standalone from the command line.

Constant Summary collapse

APP_ROOT =

We try to figure out the application root using a number of possible options

defined?(RAILS_ROOT) ? RAILS_ROOT : defined?(Merb) ? Merb.root : File.expand_path(".")
RxSettings =
SchemaToYaml::Settings::Core

Instance Method Summary collapse

Instance Method Details

#extract_names(project = nil) ⇒ Object

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.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/restfulx/configuration.rb', line 37

def extract_names(project = nil)
  if project
    project_name = project.downcase.gsub(/\W/, '')
    flex_project_name = project_name.camelize
  else
    project_name = APP_ROOT.split("/").last.gsub(/\W/, '')
    flex_project_name = project_name.camelize
  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('.', '/')
    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"
    distributed = config['distributed'] || false
  rescue
    base_folder = base_package = flex_project_name.downcase
    controller_name = "ApplicationController"
    flex_root = "app/flex"
    distributed = false
  end
  [project_name, flex_project_name, controller_name, base_package, base_folder, flex_root, distributed]
end

#list_as_files(dir_name) ⇒ Object

List files ending in *.as (ActionScript) in a given folder



66
67
68
# File 'lib/restfulx/configuration.rb', line 66

def list_as_files(dir_name)
  Dir.entries(dir_name).grep(/\.as$/).map { |name| name.sub(/\.as$/, "") }.join(", ")
end

#list_mxml_files(dir_name) ⇒ Object

List files ending in *.mxml in a given folder



71
72
73
# File 'lib/restfulx/configuration.rb', line 71

def list_mxml_files(dir_name)
  Dir.entries(dir_name).grep(/\.mxml$/).map { |name| name.sub(/\.mxml$/, "") }
end