restfulx 1.2.5 → 1.3.0

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.
Files changed (52) hide show
  1. data/README.rdoc +3 -3
  2. data/Rakefile +17 -2
  3. data/VERSION.yml +2 -3
  4. data/bin/rx-gen +1 -1
  5. data/ext/restfulx/ext/amf/serializer/extconf.rb +3 -0
  6. data/lib/restfulx.rb +43 -81
  7. data/lib/restfulx/active_record_tasks.rb +8 -6
  8. data/lib/restfulx/active_record_uuid_helper.rb +9 -10
  9. data/lib/restfulx/amf.rb +14 -0
  10. data/lib/restfulx/amf/class_mapping.rb +106 -0
  11. data/lib/restfulx/amf/ext.rb +11 -0
  12. data/lib/restfulx/amf/ext/serializer.bundle +0 -0
  13. data/lib/restfulx/amf/pure.rb +11 -0
  14. data/lib/restfulx/amf/pure/io_helpers.rb +52 -0
  15. data/lib/restfulx/amf/pure/serializer.rb +304 -0
  16. data/lib/restfulx/configuration.rb +16 -12
  17. data/lib/restfulx/{rails/recipes.rb → recipes.rb} +1 -2
  18. data/lib/restfulx/rx_action_controller.rb +34 -0
  19. data/lib/restfulx/rx_active_record.rb +360 -0
  20. data/lib/restfulx/rx_active_support.rb +139 -0
  21. data/lib/restfulx/{datamapper_foo.rb → rx_datamapper.rb} +0 -2
  22. data/lib/restfulx/{rails/schema_to_yaml.rb → schema_to_rx_yaml.rb} +88 -5
  23. data/lib/restfulx/swf_helper.rb +61 -0
  24. data/lib/restfulx/tasks.rb +5 -3
  25. data/rails_generators/rx_config/rx_config_generator.rb +2 -2
  26. data/rails_generators/rx_config/templates/mainapp.mxml +1 -1
  27. data/rails_generators/rx_config/templates/restfulx.erb +5 -3
  28. data/rails_generators/rx_main_app/rx_main_app_generator.rb +2 -2
  29. data/rails_generators/rx_scaffold/rx_scaffold_generator.rb +7 -7
  30. data/rails_generators/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +5 -3
  31. data/rxgen_generators/rx_config/rx_config_generator.rb +1 -1
  32. data/test/rails/fixtures/locations.yml +5 -6
  33. data/test/rails/fixtures/notes.yml +5 -15
  34. data/test/rails/fixtures/projects.yml +7 -23
  35. data/test/rails/fixtures/tasks.yml +17 -43
  36. data/test/rails/fixtures/users.yml +7 -11
  37. data/test/rails/helpers/functional_test_helper.rb +5 -4
  38. data/test/rails/helpers/performance_test_helper.rb +5 -0
  39. data/test/rails/helpers/test_helper.rb +27 -0
  40. data/test/rails/helpers/unit_test_helper.rb +3 -15
  41. data/test/rails/test_active_foo.rb +21 -25
  42. data/test/rails/{test_rails_integration_functional.rb → test_notes_controller_functional.rb} +5 -5
  43. data/test/rails/test_serialiazation_performance.rb +32 -0
  44. data/test/rails/test_to_amf.rb +30 -0
  45. data/test/rails/test_to_fxml.rb +18 -15
  46. data/test/rails/test_to_json.rb +2 -14
  47. metadata +30 -19
  48. data/lib/restfulx/active_foo.rb +0 -178
  49. data/lib/restfulx/rails/schema_to_yaml/extensions/enumerable.rb +0 -8
  50. data/lib/restfulx/rails/schema_to_yaml/settings/config.rb +0 -17
  51. data/lib/restfulx/rails/schema_to_yaml/settings/core.rb +0 -73
  52. data/lib/restfulx/rails/swf_helper.rb +0 -59
@@ -1,35 +1,38 @@
1
1
  $:.unshift(File.dirname(__FILE__))
2
2
 
3
3
  require 'helpers/unit_test_helper'
4
- require 'models/location'
5
- require 'models/note'
6
- require 'models/project'
7
- require 'models/task'
8
- require 'models/user'
9
- require 'models/simple_property'
10
4
 
11
5
  class ToFxmlTest < ActiveRecord::TestCase
12
- fixtures :locations, :notes, :projects, :tasks, :users, :simple_properties
6
+ fixtures :users
13
7
 
14
8
  def test_to_fxml_sanity
15
- assert_nothing_raised {users(:ludwig).to_fxml}
9
+ assert_nothing_raised {users(:user_1).to_fxml}
16
10
  end
17
11
 
18
12
  def test_to_fxml_doesnt_dasherize
19
- set_response_to users(:ludwig).to_fxml
20
- assert_xml_select 'user first_name', 'Ludwig'
13
+ set_response_to users(:user_1).to_fxml
14
+ assert_xml_select 'user first_name', 'Foo1'
21
15
  end
22
16
 
23
17
  def test_default_xml_methods_on_user_are_included_in_fxml
24
- set_response_to users(:ludwig).to_fxml(:methods => [:has_nothing_to_do, :full_name])
25
- assert_xml_select 'user full_name', 'Ludwig van Beethoven'
18
+ set_response_to users(:user_1).to_fxml(:methods => [:has_nothing_to_do, :full_name])
19
+ assert_xml_select 'user full_name', 'Foo1 Bar1'
26
20
  assert_xml_select 'user has_nothing_to_do'
27
21
  end
28
22
 
29
23
  def test_default_xml_methods_on_user_are_included_in_fxml_if_you_call_it_twice
30
- set_response_to users(:ludwig).to_fxml(:methods => [:has_nothing_to_do, :full_name])
31
- set_response_to users(:ludwig).to_fxml(:methods => [:has_nothing_to_do, :full_name])
32
- assert_xml_select 'user full_name', 'Ludwig van Beethoven'
24
+ set_response_to users(:user_1).to_fxml(:methods => [:has_nothing_to_do, :full_name])
25
+ set_response_to users(:user_1).to_fxml(:methods => [:has_nothing_to_do, :full_name])
26
+ assert_xml_select 'user full_name', 'Foo1 Bar1'
33
27
  assert_xml_select 'user has_nothing_to_do'
34
28
  end
29
+
30
+ # need to fix this
31
+ # def test_to_fxml_serializes_validation_errors
32
+ # vince = users(:vincent)
33
+ # assert_invalid vince
34
+ # assert_not_nil vince.errors
35
+ # set_response_to vince.errors.to_fxml
36
+ # assert_xml_select 'errors error'
37
+ # end
35
38
  end
@@ -1,23 +1,11 @@
1
1
  $:.unshift(File.dirname(__FILE__))
2
2
 
3
3
  require 'helpers/unit_test_helper'
4
- require 'models/location'
5
- require 'models/note'
6
- require 'models/project'
7
- require 'models/task'
8
- require 'models/user'
9
- require 'models/simple_property'
10
4
 
11
5
  class ToJsonTest < ActiveRecord::TestCase
12
- fixtures :locations, :notes, :projects, :tasks, :users, :simple_properties
6
+ fixtures :users
13
7
 
14
8
  def test_to_json_sanity
15
- assert_nothing_raised {users(:ludwig).to_json}
16
- end
17
-
18
- def test_to_json_methods
19
- #set_response_to users(:ludwig).to_json
20
- #puts users(:ludwig).to_json
21
- puts User.all.to_json
9
+ assert_nothing_raised {users(:user_1).to_json}
22
10
  end
23
11
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 2
8
- - 5
9
- version: 1.2.5
7
+ - 3
8
+ - 0
9
+ version: 1.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dima Berastau
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-02 00:00:00 -07:00
17
+ date: 2010-09-27 00:00:00 +03:00
18
18
  default_executable: rx-gen
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -27,8 +27,8 @@ dependencies:
27
27
  segments:
28
28
  - 1
29
29
  - 5
30
- - 0
31
- version: 1.5.0
30
+ - 2
31
+ version: 1.5.2
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
@@ -45,12 +45,12 @@ dependencies:
45
45
  version: 2.0.0
46
46
  type: :runtime
47
47
  version_requirements: *id002
48
- description:
48
+ description: "RestfulX: The RESTful Way to develop Adobe Flex and AIR applications"
49
49
  email: dima.berastau@gmail.com
50
50
  executables:
51
51
  - rx-gen
52
- extensions: []
53
-
52
+ extensions:
53
+ - ext/restfulx/ext/amf/serializer/extconf.rb
54
54
  extra_rdoc_files:
55
55
  - README.rdoc
56
56
  files:
@@ -85,18 +85,23 @@ files:
85
85
  - app_generators/rx_app/templates/swfobject.js
86
86
  - bin/rx-gen
87
87
  - lib/restfulx.rb
88
- - lib/restfulx/active_foo.rb
89
88
  - lib/restfulx/active_record_tasks.rb
90
89
  - lib/restfulx/active_record_uuid_helper.rb
90
+ - lib/restfulx/amf.rb
91
+ - lib/restfulx/amf/class_mapping.rb
92
+ - lib/restfulx/amf/ext.rb
91
93
  - lib/restfulx/amf/ext/serializer.bundle
94
+ - lib/restfulx/amf/pure.rb
95
+ - lib/restfulx/amf/pure/io_helpers.rb
96
+ - lib/restfulx/amf/pure/serializer.rb
92
97
  - lib/restfulx/configuration.rb
93
- - lib/restfulx/datamapper_foo.rb
94
- - lib/restfulx/rails/recipes.rb
95
- - lib/restfulx/rails/schema_to_yaml.rb
96
- - lib/restfulx/rails/schema_to_yaml/extensions/enumerable.rb
97
- - lib/restfulx/rails/schema_to_yaml/settings/config.rb
98
- - lib/restfulx/rails/schema_to_yaml/settings/core.rb
99
- - lib/restfulx/rails/swf_helper.rb
98
+ - lib/restfulx/recipes.rb
99
+ - lib/restfulx/rx_action_controller.rb
100
+ - lib/restfulx/rx_active_record.rb
101
+ - lib/restfulx/rx_active_support.rb
102
+ - lib/restfulx/rx_datamapper.rb
103
+ - lib/restfulx/schema_to_rx_yaml.rb
104
+ - lib/restfulx/swf_helper.rb
100
105
  - lib/restfulx/tasks.rb
101
106
  - rails_generators/rx_config/USAGE
102
107
  - rails_generators/rx_config/rx_config_generator.rb
@@ -180,6 +185,7 @@ files:
180
185
  - test/rails/fixtures/tasks.yml
181
186
  - test/rails/fixtures/users.yml
182
187
  - test/rails/helpers/functional_test_helper.rb
188
+ - test/rails/helpers/performance_test_helper.rb
183
189
  - test/rails/helpers/test_helper.rb
184
190
  - test/rails/helpers/unit_test_helper.rb
185
191
  - test/rails/model.yml
@@ -192,7 +198,9 @@ files:
192
198
  - test/rails/schema.rb
193
199
  - test/rails/test.swf
194
200
  - test/rails/test_active_foo.rb
195
- - test/rails/test_rails_integration_functional.rb
201
+ - test/rails/test_notes_controller_functional.rb
202
+ - test/rails/test_serialiazation_performance.rb
203
+ - test/rails/test_to_amf.rb
196
204
  - test/rails/test_to_fxml.rb
197
205
  - test/rails/test_to_json.rb
198
206
  - test/rails/views/notes/empty_params_action.html.erb
@@ -237,6 +245,7 @@ test_files:
237
245
  - test/rails/controllers/tasks_controller.rb
238
246
  - test/rails/controllers/users_controller.rb
239
247
  - test/rails/helpers/functional_test_helper.rb
248
+ - test/rails/helpers/performance_test_helper.rb
240
249
  - test/rails/helpers/test_helper.rb
241
250
  - test/rails/helpers/unit_test_helper.rb
242
251
  - test/rails/models/location.rb
@@ -247,6 +256,8 @@ test_files:
247
256
  - test/rails/models/user.rb
248
257
  - test/rails/schema.rb
249
258
  - test/rails/test_active_foo.rb
250
- - test/rails/test_rails_integration_functional.rb
259
+ - test/rails/test_notes_controller_functional.rb
260
+ - test/rails/test_serialiazation_performance.rb
261
+ - test/rails/test_to_amf.rb
251
262
  - test/rails/test_to_fxml.rb
252
263
  - test/rails/test_to_json.rb
@@ -1,178 +0,0 @@
1
- # There's a number of things that ActiveRecord/ActiveSupport and the rest of the family get
2
- # ~wrong~ from the point of view of Flex clients.
3
- #
4
- # Some of these things are:
5
- # * XML format (Flex *really* doesn't like dashes in XML messages)
6
- # * Errors (we need to be more specific and communicate what went wrong *where*)
7
- #
8
- # This is where we try to fix this stuff.
9
- #
10
- # Some of the things that are done can be called _monkey_ _patching_ while others can
11
- # be called extensions. Caveat emptor.
12
-
13
- # ActiveSupport specific patches. More specifically we add +to_fxml+ methods to Array and
14
- # Hash conversion modules
15
- module ActiveSupport
16
- # refer to: http://api.rubyonrails.org/ for more details
17
- module CoreExtensions
18
- # Add Flex friendly +to_fxml+ to Hash conversions
19
- module Hash
20
- # refer to: http://api.rubyonrails.org/ for more details
21
- module Conversions
22
-
23
- # Flex friendly XML format, no dashes, etc
24
- def to_fxml(options = {})
25
- options.merge!(:dasherize => false)
26
- options[:indent] ||= 2
27
- options.reverse_merge!({ :builder => Builder::XmlMarkup.new(:indent => options[:indent]),
28
- :root => "hash" })
29
- options[:builder].instruct! unless options.delete(:skip_instruct)
30
- dasherize = !options.has_key?(:dasherize) || options[:dasherize]
31
- root = dasherize ? options[:root].to_s.dasherize : options[:root].to_s
32
-
33
- options[:builder].__send__(:method_missing, root) do
34
- each do |key, value|
35
- case value
36
- when ::Hash
37
- value.to_fxml(options.merge({ :root => key, :skip_instruct => true }))
38
- when ::Array
39
- value.to_fxml(options.merge({ :root => key, :children => key.to_s.singularize, :skip_instruct => true}))
40
- when ::Method, ::Proc
41
- # If the Method or Proc takes two arguments, then
42
- # pass the suggested child element name. This is
43
- # used if the Method or Proc will be operating over
44
- # multiple records and needs to create an containing
45
- # element that will contain the objects being
46
- # serialized.
47
- if 1 == value.arity
48
- value.call(options.merge({ :root => key, :skip_instruct => true }))
49
- else
50
- value.call(options.merge({ :root => key, :skip_instruct => true }), key.to_s.singularize)
51
- end
52
- else
53
- if value.respond_to?(:to_fxml)
54
- value.to_fxml(options.merge({ :root => key, :skip_instruct => true }))
55
- else
56
- type_name = XML_TYPE_NAMES[value.class.name]
57
-
58
- key = dasherize ? key.to_s.dasherize : key.to_s
59
-
60
- attributes = options[:skip_types] || value.nil? || type_name.nil? ? { } : { :type => type_name }
61
- if value.nil?
62
- attributes[:nil] = true
63
- end
64
-
65
- options[:builder].tag!(key,
66
- XML_FORMATTING[type_name] ? XML_FORMATTING[type_name].call(value) : value,
67
- attributes
68
- )
69
- end
70
- end
71
- end
72
-
73
- yield options[:builder] if block_given?
74
- end
75
- end
76
- end
77
- end
78
- # Add Flex friendly to_fxml to array conversions
79
- module Array
80
- # refer to: http://api.rubyonrails.org/ for more details
81
- module Conversions
82
- # Flex friendly XML format (no dashes, etc)
83
- def to_fxml(options = {})
84
- raise "Not all elements respond to to_fxml" unless all? { |e| e.respond_to? :to_fxml }
85
-
86
- options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "records"
87
- options[:children] ||= options[:root].singularize
88
- options[:indent] ||= 2
89
- options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
90
- options.merge!(:dasherize => false)
91
-
92
- options[:attributes] ||= {}
93
- options[:attributes].merge!(:type => "array")
94
-
95
- root = options.delete(:root).to_s
96
- children = options.delete(:children)
97
-
98
- if !options.has_key?(:dasherize) || options[:dasherize]
99
- root = root.dasherize
100
- end
101
-
102
- options[:builder].instruct! unless options.delete(:skip_instruct)
103
-
104
- opts = options.merge({ :root => children })
105
-
106
- xml = options[:builder]
107
- if empty?
108
- xml.tag!(root, options[:attributes])
109
- else
110
- xml.tag!(root, options[:attributes]) {
111
- yield xml if block_given?
112
- each { |e| e.to_fxml(opts.merge!({ :skip_instruct => true })) }
113
- }
114
- end
115
- end
116
- end
117
- end
118
- end
119
- end
120
-
121
- # Flex friendly ActiveRecord patches. More specifically XML serialization improvements.
122
- # These won't override whatever you may normally do with XML, hence there's Flex specific
123
- # name for this stuff +to_fxml+.
124
- module ActiveRecord
125
- # refer to: http://api.rubyonrails.org/ for more details
126
- module Serialization
127
- # Enforces Flex friendly options on XML and delegates processing to standard +to_xml+
128
- def to_fxml(options = {}, &block)
129
- options.merge!(:dasherize => false)
130
- default_except = [:crypted_password, :salt, :remember_token, :remember_token_expires_at]
131
- options[:except] = (options[:except] ? options[:except] + default_except : default_except)
132
- to_xml(options, &block)
133
- end
134
- end
135
-
136
- # Change the xml serializer so that '?'s are stripped from attribute names.
137
- # This makes it possible to serialize methods that end in a question mark, like 'valid?' or 'is_true?'
138
- class XmlSerializer
139
- # Strips '?' from serialized method names
140
- def add_tag(attribute)
141
- builder.tag!(
142
- dasherize? ? attribute.display_name.dasherize : attribute.display_name,
143
- attribute.value.to_s,
144
- attribute.decorations(!options[:skip_types])
145
- )
146
- end
147
- # Strips '?' from serialized method names
148
- class Attribute
149
- # Strips '?' from serialized method names
150
- def display_name
151
- @name.gsub('?','')
152
- end
153
- end
154
- end
155
-
156
- # Add more extensive reporting on errors including field name along with a message
157
- # when errors are serialized to XML
158
- class Errors
159
- # Flex friendly errors
160
- def to_fxml(options = {})
161
- options[:root] ||= "errors"
162
- options[:indent] ||= 2
163
- options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
164
- options[:builder].instruct! unless options.delete(:skip_instruct)
165
- options[:builder].errors do |e|
166
- # The @errors instance variable is a Hash inside the Errors class
167
- @errors.each do |attr, msg|
168
- next if msg.nil?
169
- if attr == "base"
170
- options[:builder].error("message", msg.to_s)
171
- else
172
- options[:builder].error("field" => attr.camelcase(:lower), "message" => msg.to_s)
173
- end
174
- end
175
- end
176
- end
177
- end
178
- end
@@ -1,8 +0,0 @@
1
- # Enumerable extensions
2
- module Enumerable
3
- # Helps you find duplicates
4
- # used in schema_to_yaml.rb for cleanup
5
- def dups
6
- inject({}) {|h,v| h[v]=h[v].to_i+1; h}.reject{|k,v| v==1}.keys
7
- end
8
- end
@@ -1,17 +0,0 @@
1
- # SchemaToYaml settings
2
- module SchemaToYaml
3
- module Settings
4
- class Config
5
- class << self
6
- def configure
7
- yield self
8
- end
9
-
10
- def settings_file
11
- @settings_file ||= :restfulx
12
- end
13
- attr_writer :settings_file
14
- end
15
- end
16
- end
17
- end
@@ -1,73 +0,0 @@
1
- # Inspired from http://settingslogic.rubyforge.org/
2
- # Used to read in settings from restfulx.yml for use in code generation
3
- module SchemaToYaml
4
- module Settings
5
- # We try to figure out the application root using a number of possible options
6
- APP_ROOT = defined?(RAILS_ROOT) ? RAILS_ROOT : defined?(Merb) ? Merb.root : File.expand_path(".")
7
-
8
- class Core
9
- class << self
10
- def name
11
- instance._settings.key?("name") ? instance.name : super
12
- end
13
-
14
- def reset!
15
- @instance = nil
16
- end
17
-
18
- private
19
- def instance
20
- @instance ||= new
21
- end
22
-
23
- def method_missing(name, *args, &block)
24
- instance.send(name, *args, &block)
25
- end
26
- end
27
-
28
- attr_accessor :_settings
29
-
30
- def initialize(name_or_hash = Config.settings_file)
31
- case name_or_hash
32
- when Hash
33
- self._settings = name_or_hash
34
- when String, Symbol
35
- root_path = defined?(APP_ROOT) ? "#{APP_ROOT}/config/" : ""
36
- file_path = name_or_hash.is_a?(Symbol) ? "#{root_path}#{name_or_hash}.yml" : name_or_hash
37
- self._settings = YAML.load(ERB.new(File.read(file_path)).result)
38
- self._settings = _settings[RAILS_ENV] if defined?(RAILS_ENV)
39
- else
40
- raise ArgumentError.new("Your settings must be a hash,
41
- a symbol representing the name of the .yml file in your config directory,
42
- or a string representing the abosolute path to your settings file.")
43
- end
44
- define_settings!
45
- end
46
-
47
- private
48
- def method_missing(name, *args, &block)
49
- raise NoMethodError.new("no configuration was specified for #{name}")
50
- end
51
-
52
- def define_settings!
53
- return if _settings.nil?
54
- _settings.each do |key, value|
55
- case value
56
- when Hash
57
- instance_eval <<-"end_eval", __FILE__, __LINE__
58
- def #{key}
59
- @#{key} ||= self.class.new(_settings["#{key}"])
60
- end
61
- end_eval
62
- else
63
- instance_eval <<-"end_eval", __FILE__, __LINE__
64
- def #{key}
65
- @#{key} ||= _settings["#{key}"]
66
- end
67
- end_eval
68
- end
69
- end
70
- end
71
- end
72
- end
73
- end