dima-ruboss4ruby 1.0.5
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/Generators +7 -0
- data/History.txt +4 -0
- data/Manifest.txt +116 -0
- data/README.rdoc +23 -0
- data/gpl-3.0.txt +674 -0
- data/lib/ruboss4ruby.rb +84 -0
- data/lib/ruboss4ruby/active_foo.rb +221 -0
- data/lib/ruboss4ruby/active_record_tasks.rb +75 -0
- data/lib/ruboss4ruby/configuration.rb +59 -0
- data/lib/ruboss4ruby/datamapper_foo.rb +25 -0
- data/lib/ruboss4ruby/generated_attribute.rb +61 -0
- data/lib/ruboss4ruby/tasks.rb +80 -0
- data/merb_generators/ruboss_config.rb +103 -0
- data/merb_generators/ruboss_controller.rb +59 -0
- data/merb_generators/ruboss_flex_app.rb +67 -0
- data/merb_generators/ruboss_resource.rb +37 -0
- data/merb_generators/ruboss_resource_controller.rb +80 -0
- data/merb_generators/ruboss_scaffold.rb +157 -0
- data/merb_generators/templates/ruboss_config/actionscript.properties +16 -0
- data/merb_generators/templates/ruboss_config/actionscriptair.properties +16 -0
- data/merb_generators/templates/ruboss_config/expressInstall.swf +0 -0
- data/merb_generators/templates/ruboss_config/flex.properties +2 -0
- data/merb_generators/templates/ruboss_config/html-template/AC_OETags.js +276 -0
- data/merb_generators/templates/ruboss_config/html-template/history/history.css +6 -0
- data/merb_generators/templates/ruboss_config/html-template/history/history.js +645 -0
- data/merb_generators/templates/ruboss_config/html-template/history/historyFrame.html +29 -0
- data/merb_generators/templates/ruboss_config/html-template/index.template.html +121 -0
- data/merb_generators/templates/ruboss_config/html-template/playerProductInstall.swf +0 -0
- data/merb_generators/templates/ruboss_config/index.html.erb +18 -0
- data/merb_generators/templates/ruboss_config/mainair-app.xml +134 -0
- data/merb_generators/templates/ruboss_config/project.properties +18 -0
- data/merb_generators/templates/ruboss_config/projectair.properties +24 -0
- data/merb_generators/templates/ruboss_config/ruboss.yml +16 -0
- data/merb_generators/templates/ruboss_config/swfobject.js +5 -0
- data/merb_generators/templates/ruboss_controller/controller.as.erb +40 -0
- data/merb_generators/templates/ruboss_flex_app/mainapp.mxml +34 -0
- data/merb_generators/templates/ruboss_resource_controller/controller_ar.rb.erb +49 -0
- data/merb_generators/templates/ruboss_resource_controller/controller_dm.rb.erb +46 -0
- data/merb_generators/templates/ruboss_resource_controller/spec/controllers/%file_name%_spec.rb +7 -0
- data/merb_generators/templates/ruboss_resource_controller/spec/requests/%file_name%_spec.rb +1 -0
- data/merb_generators/templates/ruboss_resource_controller/test/controllers/%file_name%_test.rb +17 -0
- data/rails_generators/ruboss_config/USAGE +18 -0
- data/rails_generators/ruboss_config/ruboss_config_generator.rb +114 -0
- data/rails_generators/ruboss_config/templates/actionscript.properties +16 -0
- data/rails_generators/ruboss_config/templates/actionscriptair.properties +16 -0
- data/rails_generators/ruboss_config/templates/expressInstall.swf +0 -0
- data/rails_generators/ruboss_config/templates/flex.properties +2 -0
- data/rails_generators/ruboss_config/templates/html-template/AC_OETags.js +276 -0
- data/rails_generators/ruboss_config/templates/html-template/history/history.css +6 -0
- data/rails_generators/ruboss_config/templates/html-template/history/history.js +645 -0
- data/rails_generators/ruboss_config/templates/html-template/history/historyFrame.html +29 -0
- data/rails_generators/ruboss_config/templates/html-template/index.template.html +121 -0
- data/rails_generators/ruboss_config/templates/html-template/playerProductInstall.swf +0 -0
- data/rails_generators/ruboss_config/templates/index.html.erb +18 -0
- data/rails_generators/ruboss_config/templates/mainair-app.xml +134 -0
- data/rails_generators/ruboss_config/templates/mainapp-config.xml +21 -0
- data/rails_generators/ruboss_config/templates/mainapp.mxml +31 -0
- data/rails_generators/ruboss_config/templates/project-textmate.erb +52 -0
- data/rails_generators/ruboss_config/templates/project.properties +18 -0
- data/rails_generators/ruboss_config/templates/projectair.properties +24 -0
- data/rails_generators/ruboss_config/templates/ruboss.yml +14 -0
- data/rails_generators/ruboss_config/templates/ruboss_tasks.rake +5 -0
- data/rails_generators/ruboss_config/templates/swfobject.js +5 -0
- data/rails_generators/ruboss_controller/USAGE +11 -0
- data/rails_generators/ruboss_controller/ruboss_controller_generator.rb +31 -0
- data/rails_generators/ruboss_controller/templates/controller.as.erb +40 -0
- data/rails_generators/ruboss_scaffold/USAGE +35 -0
- data/rails_generators/ruboss_scaffold/ruboss_scaffold_generator.rb +177 -0
- data/rails_generators/ruboss_scaffold/templates/component.mxml.erb +149 -0
- data/rails_generators/ruboss_scaffold/templates/controller.rb.erb +97 -0
- data/rails_generators/ruboss_scaffold/templates/fixtures.yml.erb +35 -0
- data/rails_generators/ruboss_scaffold/templates/migration.rb.erb +19 -0
- data/rails_generators/ruboss_scaffold/templates/model.as.erb +42 -0
- data/rails_generators/ruboss_scaffold/templates/model.rb.erb +11 -0
- data/rails_generators/ruboss_yaml_scaffold/USAGE +14 -0
- data/rails_generators/ruboss_yaml_scaffold/ruboss_yaml_scaffold_generator.rb +44 -0
- data/rcl-1.0.txt +0 -0
- metadata +197 -0
data/lib/ruboss4ruby.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
module Ruboss
|
2
|
+
VERSION = '1.0.5'
|
3
|
+
RUBOSS_FRAMEWORK_VERSION = '1.0.5'
|
4
|
+
|
5
|
+
LIB_DIR = File.join(File.dirname(__FILE__), 'ruboss4ruby/')
|
6
|
+
end
|
7
|
+
|
8
|
+
# Merb specific handling
|
9
|
+
# make sure we're running inside Merb
|
10
|
+
if defined?(Merb::Plugins)
|
11
|
+
Merb::Plugins.add_rakefiles 'ruboss4ruby/tasks'
|
12
|
+
|
13
|
+
Merb::BootLoader.before_app_loads do
|
14
|
+
require Ruboss::LIB_DIR + 'configuration'
|
15
|
+
|
16
|
+
if defined?(ActiveRecord::Base)
|
17
|
+
Merb.add_mime_type(:fxml, :to_fxml, %w[application/xml text/xml application/x-xml], :charset => "utf-8")
|
18
|
+
require Ruboss::LIB_DIR + 'active_foo'
|
19
|
+
Merb::Plugins.add_rakefiles 'ruboss4ruby/active_record_tasks'
|
20
|
+
else
|
21
|
+
Merb.add_mime_type(:fxml, :to_xml, %w[application/xml text/xml application/x-xml], :charset => "utf-8")
|
22
|
+
if defined?(Merb::Orms::DataMapper)
|
23
|
+
require Ruboss::LIB_DIR + 'datamapper_foo'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
elsif defined?(ActionController::Base)
|
28
|
+
# if we are not running in Merb, we've got to be running in Rails
|
29
|
+
Mime::Type.register_alias "application/xml", :fxml
|
30
|
+
|
31
|
+
['configuration', 'active_foo', 'rails/ruboss_helper',
|
32
|
+
'rails/ruboss_test_helpers'].each { |lib| require Ruboss::LIB_DIR + lib }
|
33
|
+
|
34
|
+
ActionView::Base.send :include, RubossHelper unless ActionView::Base.included_modules.include?(RubossHelper)
|
35
|
+
Test::Unit::TestCase.send :include, RubossTestHelpers unless Test::Unit::TestCase.included_modules.include?(RubossTestHelpers)
|
36
|
+
|
37
|
+
module ActionController
|
38
|
+
class Base
|
39
|
+
alias_method :old_render, :render unless method_defined?(:old_render)
|
40
|
+
|
41
|
+
# so that we can have handling for :fxml option and write code like
|
42
|
+
# format.fxml { render :fxml => @projects }
|
43
|
+
def render(options = nil, extra_options = {}, &block)
|
44
|
+
if options.is_a?(Hash) && options[:fxml]
|
45
|
+
xml = options[:fxml]
|
46
|
+
response.content_type ||= Mime::XML
|
47
|
+
render_for_text(xml.respond_to?(:to_fxml) ? xml.to_fxml : xml, options[:status])
|
48
|
+
else
|
49
|
+
old_render(options, extra_options, &block)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
module RubossController
|
56
|
+
private
|
57
|
+
|
58
|
+
# Extract any keys named _metadata from the models in the params hash
|
59
|
+
# and put them in the root of the params hash.
|
60
|
+
def extract_metadata_from_params
|
61
|
+
metadata = {}
|
62
|
+
metadata.merge!(params.delete('_metadata')) if params.has_key?('_metadata')
|
63
|
+
params.each do |k, v|
|
64
|
+
next unless v.respond_to?(:has_key?) and v.has_key?('_metadata')
|
65
|
+
metadata.merge!(v.delete('_metadata'))
|
66
|
+
end
|
67
|
+
params.merge!(metadata) unless metadata.empty?
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
module ActiveRecord
|
72
|
+
module NamedScope
|
73
|
+
class Scope
|
74
|
+
delegate :to_fxml, :to => :proxy_found
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
ActionController::Base.send :include, RubossController
|
80
|
+
ActionController::Base.send :prepend_before_filter, :extract_metadata_from_params
|
81
|
+
|
82
|
+
# temporarily disable forgery protection site-wise
|
83
|
+
ActionController::Base.allow_forgery_protection = false
|
84
|
+
end
|
@@ -0,0 +1,221 @@
|
|
1
|
+
#ActiveRecord+ActiveSupport specific patches
|
2
|
+
|
3
|
+
# Flex friendly date, datetime formats
|
4
|
+
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(:flex_date => "%Y/%m/%d")
|
5
|
+
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(:flex_datetime => "%Y/%m/%d %H:%M:%S")
|
6
|
+
|
7
|
+
Hash::XML_FORMATTING['date'] = Proc.new { |date| date.to_s(:flex_date) }
|
8
|
+
Hash::XML_FORMATTING['datetime'] = Proc.new { |datetime| datetime.to_s(:flex_datetime) }
|
9
|
+
|
10
|
+
module ActiveSupport
|
11
|
+
module CoreExtensions
|
12
|
+
module Hash
|
13
|
+
module Conversions
|
14
|
+
def to_fxml(options = {})
|
15
|
+
if self.empty? && !options[:root]
|
16
|
+
raise "empty hash being converted to FXML must specify :root option, e.g. <class_name>.to_s.underscore.pluralize"
|
17
|
+
end
|
18
|
+
options.merge!(:dasherize => false)
|
19
|
+
options[:indent] ||= 2
|
20
|
+
options.reverse_merge!({ :builder => Builder::XmlMarkup.new(:indent => options[:indent]),
|
21
|
+
:root => "hash" })
|
22
|
+
options[:builder].instruct! unless options.delete(:skip_instruct)
|
23
|
+
dasherize = !options.has_key?(:dasherize) || options[:dasherize]
|
24
|
+
root = dasherize ? options[:root].to_s.dasherize : options[:root].to_s
|
25
|
+
|
26
|
+
options[:builder].__send__(:method_missing, root) do
|
27
|
+
each do |key, value|
|
28
|
+
case value
|
29
|
+
when ::Hash
|
30
|
+
value.to_fxml(options.merge({ :root => key, :skip_instruct => true }))
|
31
|
+
when ::Array
|
32
|
+
value.to_fxml(options.merge({ :root => key, :children => key.to_s.singularize, :skip_instruct => true}))
|
33
|
+
when ::Method, ::Proc
|
34
|
+
# If the Method or Proc takes two arguments, then
|
35
|
+
# pass the suggested child element name. This is
|
36
|
+
# used if the Method or Proc will be operating over
|
37
|
+
# multiple records and needs to create an containing
|
38
|
+
# element that will contain the objects being
|
39
|
+
# serialized.
|
40
|
+
if 1 == value.arity
|
41
|
+
value.call(options.merge({ :root => key, :skip_instruct => true }))
|
42
|
+
else
|
43
|
+
value.call(options.merge({ :root => key, :skip_instruct => true }), key.to_s.singularize)
|
44
|
+
end
|
45
|
+
else
|
46
|
+
if value.respond_to?(:to_fxml)
|
47
|
+
value.to_fxml(options.merge({ :root => key, :skip_instruct => true }))
|
48
|
+
else
|
49
|
+
type_name = XML_TYPE_NAMES[value.class.name]
|
50
|
+
|
51
|
+
key = dasherize ? key.to_s.dasherize : key.to_s
|
52
|
+
|
53
|
+
attributes = options[:skip_types] || value.nil? || type_name.nil? ? { } : { :type => type_name }
|
54
|
+
if value.nil?
|
55
|
+
attributes[:nil] = true
|
56
|
+
end
|
57
|
+
|
58
|
+
options[:builder].tag!(key,
|
59
|
+
XML_FORMATTING[type_name] ? XML_FORMATTING[type_name].call(value) : value,
|
60
|
+
attributes
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
yield options[:builder] if block_given?
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
module Array
|
72
|
+
module Conversions
|
73
|
+
def to_fxml(options = {})
|
74
|
+
if self.empty? && !options[:root]
|
75
|
+
raise "empty array being converted to FXML must specify :root option, e.g. <class_name>.to_s.underscore.pluralize"
|
76
|
+
end
|
77
|
+
raise "Not all elements respond to to_fxml" unless all? { |e| e.respond_to? :to_fxml }
|
78
|
+
|
79
|
+
options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "records"
|
80
|
+
options[:children] ||= options[:root].singularize
|
81
|
+
options[:indent] ||= 2
|
82
|
+
options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
|
83
|
+
options.merge!(:dasherize => false)
|
84
|
+
|
85
|
+
root = options.delete(:root).to_s
|
86
|
+
children = options.delete(:children)
|
87
|
+
|
88
|
+
if !options.has_key?(:dasherize) || options[:dasherize]
|
89
|
+
root = root.dasherize
|
90
|
+
end
|
91
|
+
|
92
|
+
options[:builder].instruct! unless options.delete(:skip_instruct)
|
93
|
+
|
94
|
+
opts = options.merge({ :root => children })
|
95
|
+
|
96
|
+
xml = options[:builder]
|
97
|
+
if empty?
|
98
|
+
xml.tag!(root, options[:skip_types] ? {} : {:type => "array"})
|
99
|
+
else
|
100
|
+
xml.tag!(root, options[:skip_types] ? {} : {:type => "array"}) {
|
101
|
+
yield xml if block_given?
|
102
|
+
each { |e| e.to_fxml(opts.merge!({ :skip_instruct => true })) }
|
103
|
+
}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
module ActiveRecord
|
112
|
+
# Flex friendly XML serialization patches
|
113
|
+
class Base
|
114
|
+
class << self
|
115
|
+
# TODO: this doesn't work with hash based to_fxml(:include) options, only array based
|
116
|
+
def default_fxml_methods(*args)
|
117
|
+
methods = *args.dup
|
118
|
+
module_eval <<-END
|
119
|
+
def self.default_fxml_methods_array
|
120
|
+
return [#{methods.inspect}].flatten
|
121
|
+
end
|
122
|
+
END
|
123
|
+
end
|
124
|
+
|
125
|
+
def default_fxml_includes(*args)
|
126
|
+
includes = *args.dup
|
127
|
+
module_eval <<-END
|
128
|
+
def self.default_fxml_include_params
|
129
|
+
return [#{includes.inspect}].flatten
|
130
|
+
end
|
131
|
+
END
|
132
|
+
end
|
133
|
+
|
134
|
+
def default_fxml_hash(already_included = [])
|
135
|
+
# return {} unless self.class.respond_to?(:default_fxml_include_params) || self.class.respond_to?(:default_fxml_methods_array)
|
136
|
+
default_hash = {:include => {}}
|
137
|
+
default_hash[:methods] = self.default_fxml_methods_array if self.respond_to?(:default_fxml_methods_array)
|
138
|
+
if self.respond_to?(:default_fxml_include_params)
|
139
|
+
default_includes = self.default_fxml_include_params
|
140
|
+
default_hash[:include] = default_includes.inject({}) do |include_hash, included|
|
141
|
+
next if already_included.include?(included) # We only want to include things once, to avoid infinite loops
|
142
|
+
included_class = included.to_s.singularize.camelize.constantize
|
143
|
+
include_hash[included] = included_class.default_fxml_hash(already_included + default_includes)
|
144
|
+
include_hash
|
145
|
+
end
|
146
|
+
end
|
147
|
+
default_hash
|
148
|
+
end
|
149
|
+
|
150
|
+
# options[:include] can be a Hash, Array, Symbol or nil.
|
151
|
+
# We always want it as a Hash. This translates includes to a Hash like this:
|
152
|
+
# If it's a nil, return an empty Hash ({})
|
153
|
+
# If it's a Hash, then it is just returned
|
154
|
+
# If it's an array, then it returns a Hash with each array element as a key, and values of empty Hashes.
|
155
|
+
# If it's a symbol, then it returns a Hash with a single key/value pair, with the symbol as the key and an empty Hash as the value.
|
156
|
+
def includes_as_hash(includes = nil)
|
157
|
+
res = case
|
158
|
+
when includes.is_a?(Hash)
|
159
|
+
includes
|
160
|
+
when includes.nil?
|
161
|
+
{}
|
162
|
+
else #Deal with arrays and symbols
|
163
|
+
res = [includes].flatten.inject({}) {|include_hash, included| include_hash[included] = {} ; include_hash}
|
164
|
+
end
|
165
|
+
res
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
module Serialization
|
172
|
+
def to_fxml(options = {}, &block)
|
173
|
+
options.merge!(:dasherize => false)
|
174
|
+
default_except = [:crypted_password, :salt, :remember_token, :remember_token_expires_at]
|
175
|
+
options[:except] = (options[:except] ? options[:except] + default_except : default_except)
|
176
|
+
to_xml(options, &block)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# Change the xml serializer so that '?'s are stripped from attribute names.
|
181
|
+
# This makes it possible to serialize methods that end in a question mark, like 'valid?' or 'is_true?'
|
182
|
+
class XmlSerializer
|
183
|
+
def add_tag(attribute)
|
184
|
+
builder.tag!(
|
185
|
+
dasherize? ? attribute.display_name.dasherize : attribute.display_name,
|
186
|
+
attribute.value.to_s,
|
187
|
+
attribute.decorations(!options[:skip_types])
|
188
|
+
)
|
189
|
+
end
|
190
|
+
class Attribute
|
191
|
+
def display_name
|
192
|
+
@name.gsub('?','')
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
# Add more extensive reporting on errors including field name along with a message
|
198
|
+
# when errors are serialized to XML
|
199
|
+
class Errors
|
200
|
+
def to_fxml(options={})
|
201
|
+
options[:root] ||= "errors"
|
202
|
+
options[:indent] ||= 2
|
203
|
+
options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
|
204
|
+
options[:builder].instruct! unless options.delete(:skip_instruct)
|
205
|
+
options[:builder].errors do |e|
|
206
|
+
# The @errors instance variable is a Hash inside the Errors class
|
207
|
+
@errors.each_key do |attr|
|
208
|
+
@errors[attr].each do |msg|
|
209
|
+
next if msg.nil?
|
210
|
+
if attr == "base"
|
211
|
+
options[:builder].error("message" => msg)
|
212
|
+
else
|
213
|
+
fullmsg = @base.class.human_attribute_name(attr) + ' ' + msg
|
214
|
+
options[:builder].error("field" => attr.camelcase(:lower), "message" => fullmsg)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'tasks')
|
2
|
+
|
3
|
+
# these tasks are active record specific
|
4
|
+
|
5
|
+
APP_ENV = defined?(ENV['RAILS_ENV']) ? ENV['RAILS_ENV'] : ENV['MERB_ENV']
|
6
|
+
|
7
|
+
namespace :db do
|
8
|
+
namespace :mysql do
|
9
|
+
namespace :stage do
|
10
|
+
desc "Stage production, test and development databases"
|
11
|
+
task :all do
|
12
|
+
db_names = %w(development test production)
|
13
|
+
admin_password = ENV["ADMINPASS"] || ""
|
14
|
+
db_user_name = ENV["USER"] || "root"
|
15
|
+
db_password = ENV["PASS"] || ""
|
16
|
+
stage_database(db_names, admin_password, db_user_name, db_password)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Stage the database environment for #{APP_ENV}"
|
21
|
+
task :stage do
|
22
|
+
db_names = [APP_ENV]
|
23
|
+
admin_password = ENV["ADMINPASS"] || ""
|
24
|
+
db_user_name = ENV["USER"] || "root"
|
25
|
+
db_password = ENV["PASS"] || ""
|
26
|
+
stage_database(db_names, admin_password, db_user_name, db_password)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def stage_database(db_names, admin_password, db_user_name, db_password)
|
31
|
+
sql_command = ""
|
32
|
+
|
33
|
+
db_names.each do |name|
|
34
|
+
db_name = ActiveRecord::Base.configurations[name]['database']
|
35
|
+
sql_command += "drop database if exists #{db_name}; " <<
|
36
|
+
"create database #{db_name}; grant all privileges on #{db_name}.* " <<
|
37
|
+
"to #{db_user_name}@localhost identified by \'#{db_password}\';"
|
38
|
+
ActiveRecord::Base.configurations[name]['username'] = db_user_name
|
39
|
+
ActiveRecord::Base.configurations[name]['password'] = db_password
|
40
|
+
end
|
41
|
+
|
42
|
+
if (!File.exist?("#{APP_ROOT}/tmp/stage.sql"))
|
43
|
+
File.open("#{APP_ROOT}/tmp/stage.sql", "w") do |file|
|
44
|
+
file.print sql_command
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# back up the original database.yml file just in case
|
49
|
+
File.copy("#{APP_ROOT}/config/database.yml",
|
50
|
+
"#{APP_ROOT}/config/database.yml.sample") if !File.exist?("#{APP_ROOT}/config/database.yml.sample")
|
51
|
+
|
52
|
+
dbconfig = File.read("#{APP_ROOT}/config/database.yml")
|
53
|
+
dbconfig.gsub!(/username:.*/, "username: #{db_user_name}")
|
54
|
+
dbconfig.gsub!(/password:.*/, "password: #{db_password}")
|
55
|
+
|
56
|
+
File.open("#{APP_ROOT}/config/database.yml", "w") do |file|
|
57
|
+
file.print dbconfig
|
58
|
+
end
|
59
|
+
|
60
|
+
if system %(mysql -h localhost -u root --password=#{admin_password} < tmp/stage.sql)
|
61
|
+
puts "Updated config/database.yml and staged the database based on your settings"
|
62
|
+
File.delete("tmp/stage.sql") if File.file?("tmp/stage.sql")
|
63
|
+
else
|
64
|
+
puts "Staging was not performed. Check console for errors. It is possible that 'mysql' executable was not found."
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
desc "Drop the database environment for #{APP_ENV} only if it exists"
|
69
|
+
task :drop_if_exists do
|
70
|
+
Rake::Task["db:drop"].invoke rescue nil
|
71
|
+
end
|
72
|
+
|
73
|
+
desc "Refresh the database environment for #{APP_ENV}"
|
74
|
+
task :refresh => ['db:drop_if_exists', 'db:create', 'db:migrate', 'db:fixtures:load']
|
75
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class String
|
2
|
+
def capitalize_without_downcasing
|
3
|
+
self[0,1].capitalize + self[1..-1]
|
4
|
+
end
|
5
|
+
|
6
|
+
def downcase_first_letter
|
7
|
+
self[0,1].downcase + self[1..-1]
|
8
|
+
end
|
9
|
+
|
10
|
+
def camelcase(first_letter = :upper)
|
11
|
+
case first_letter
|
12
|
+
when :upper then self.camelize(true)
|
13
|
+
when :lower then self.camelize(false)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def camelize(first_letter_in_uppercase = true)
|
18
|
+
if first_letter_in_uppercase
|
19
|
+
self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
20
|
+
else
|
21
|
+
self[0,1].downcase + self.camelize[1..-1]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def underscore
|
26
|
+
self.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
27
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module Ruboss
|
32
|
+
module Configuration
|
33
|
+
APP_ROOT = defined?(RAILS_ROOT) ? RAILS_ROOT : Merb.root
|
34
|
+
|
35
|
+
def extract_names
|
36
|
+
project_name = APP_ROOT.split("/").last.camelcase.gsub(/\s/, '')
|
37
|
+
project_name_downcase = project_name.downcase
|
38
|
+
|
39
|
+
begin
|
40
|
+
config = YAML.load(File.open("#{APP_ROOT}/config/ruboss.yml"))
|
41
|
+
base_package = config['base-package'] || project_name_downcase
|
42
|
+
base_folder = base_package.gsub('.', '/').gsub(/\s/, '')
|
43
|
+
controller_name = config['controller-name'] || "ApplicationController"
|
44
|
+
rescue
|
45
|
+
base_folder = base_package = project_name_downcase
|
46
|
+
controller_name = "ApplicationController"
|
47
|
+
end
|
48
|
+
[project_name, project_name_downcase, controller_name, base_package, base_folder]
|
49
|
+
end
|
50
|
+
|
51
|
+
def list_as_files(dir_name)
|
52
|
+
Dir.entries(dir_name).grep(/\.as$/).map { |name| name.sub(/\.as$/, "") }.join(", ")
|
53
|
+
end
|
54
|
+
|
55
|
+
def list_mxml_files(dir_name)
|
56
|
+
Dir.entries(dir_name).grep(/\.mxml$/).map { |name| name.sub(/\.mxml$/, "") }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'builder'
|
2
|
+
require Ruboss::LIB_DIR + 'configuration'
|
3
|
+
|
4
|
+
module DataMapper
|
5
|
+
module Validate
|
6
|
+
class ValidationErrors
|
7
|
+
def to_xml
|
8
|
+
xml = Builder::XmlMarkup.new(:indent => 2)
|
9
|
+
xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
|
10
|
+
xml.errors do |e|
|
11
|
+
@errors.each_key do |attribute|
|
12
|
+
@errors[attribute].each do |msg|
|
13
|
+
next if msg.nil?
|
14
|
+
if attribute == "base"
|
15
|
+
e.error("message" => msg)
|
16
|
+
else
|
17
|
+
e.error("field" => attribute.to_s.camelcase(:lower), "message" => msg)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|