marble 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.autotest +9 -0
  2. data/.gitignore +19 -0
  3. data/.travis.yml +6 -0
  4. data/.yardopts +3 -0
  5. data/Gemfile +2 -0
  6. data/Gemfile.lock +93 -0
  7. data/LICENSE +20 -0
  8. data/README.md +82 -0
  9. data/Rakefile +20 -0
  10. data/lib/marble.rb +274 -0
  11. data/lib/marble/rails_template_handler.rb +43 -0
  12. data/lib/marble/version.rb +4 -0
  13. data/marble.gemspec +29 -0
  14. data/test/rails/.autotest +5 -0
  15. data/test/rails/.gitignore +17 -0
  16. data/test/rails/Gemfile +11 -0
  17. data/test/rails/Gemfile.lock +87 -0
  18. data/test/rails/README.md +1 -0
  19. data/test/rails/Rakefile +4 -0
  20. data/test/rails/app/controllers/application_controller.rb +2 -0
  21. data/test/rails/app/controllers/test_controller.rb +6 -0
  22. data/test/rails/app/views/test/index.json.marble +4 -0
  23. data/test/rails/app/views/test/index.yaml.marble +4 -0
  24. data/test/rails/config.ru +4 -0
  25. data/test/rails/config/application.rb +15 -0
  26. data/test/rails/config/boot.rb +6 -0
  27. data/test/rails/config/environment.rb +5 -0
  28. data/test/rails/config/environments/development.rb +9 -0
  29. data/test/rails/config/environments/production.rb +9 -0
  30. data/test/rails/config/environments/test.rb +9 -0
  31. data/test/rails/config/initializers/secret_token.rb +1 -0
  32. data/test/rails/config/initializers/session_store.rb +1 -0
  33. data/test/rails/config/routes.rb +3 -0
  34. data/test/rails/public/404.html +26 -0
  35. data/test/rails/public/422.html +26 -0
  36. data/test/rails/public/500.html +26 -0
  37. data/test/rails/public/favicon.ico +0 -0
  38. data/test/rails/public/robots.txt +5 -0
  39. data/test/rails/script/rails +6 -0
  40. data/test/rails/test/integration/marble_test.rb +13 -0
  41. data/test/rails/test/test_helper.rb +3 -0
  42. data/test/test_helper.rb +7 -0
  43. data/test/test_marble.rb +127 -0
  44. metadata +204 -0
@@ -0,0 +1,127 @@
1
+ require 'test_helper'
2
+
3
+ class TestMarble < MiniTest::Unit::TestCase
4
+ def setup
5
+ @builder = Marble.new
6
+ end
7
+
8
+ def test_build
9
+ hash = @builder.build do |m|
10
+ m.hash do
11
+ m.foo 'foo'
12
+
13
+ m.bar :array do
14
+ m.item 'bar'
15
+ end
16
+
17
+ m.baz :hash do
18
+ m.baz 'baz'
19
+ end
20
+ end
21
+ end
22
+
23
+ assert_equal 'foo', hash['foo']
24
+ assert_equal ['bar'], hash['bar']
25
+ assert_equal({ 'baz' => 'baz' }, hash['baz'])
26
+ end
27
+
28
+ def test_empty_build
29
+ assert_nil @builder.build
30
+
31
+ @builder.build do |m|
32
+ assert_same @builder, m
33
+ end
34
+ end
35
+
36
+ def test_empty_array
37
+ assert_equal [], @builder.array
38
+
39
+ @builder.array do |m|
40
+ assert_same @builder, m
41
+ end
42
+ end
43
+
44
+ def test_empty_hash
45
+ assert_equal({}, @builder.hash)
46
+
47
+ @builder.hash do |m|
48
+ assert_same @builder, m
49
+ end
50
+ end
51
+
52
+ def test_item
53
+ array = @builder.array do |m|
54
+ m.item :array do
55
+ m.item 'bar'
56
+ end
57
+ end
58
+
59
+ assert_equal [['bar']], array
60
+
61
+ array = @builder.array do |m|
62
+ m.item do
63
+ 'bar'
64
+ end
65
+ end
66
+
67
+ assert_equal ['bar'], array
68
+
69
+ array = @builder.array do |m|
70
+ m.item 'bar'
71
+ end
72
+
73
+ assert_equal ['bar'], array
74
+ end
75
+
76
+ def test_pair
77
+ hash = @builder.hash do |m|
78
+ m.pair 'foo', :hash do
79
+ m.pair 'bar', 'baz'
80
+ end
81
+ end
82
+
83
+ assert_equal({ 'bar' => 'baz' }, hash['foo'])
84
+
85
+ hash = @builder.hash do |m|
86
+ m.pair 'foo' do
87
+ 'bar'
88
+ end
89
+ end
90
+
91
+ assert_equal({ 'foo' => 'bar' }, hash)
92
+
93
+ hash = @builder.hash do |m|
94
+ m.pair 'foo', 'bar'
95
+ end
96
+
97
+ assert_equal({ 'foo' => 'bar' }, hash)
98
+ end
99
+
100
+ def test_method_missing_in_array_context
101
+ array = @builder.array do |m|
102
+ m.foo :array do
103
+ m.bar 'baz'
104
+ end
105
+ end
106
+
107
+ assert_equal [['baz']], array
108
+ end
109
+
110
+ def test_method_missing_in_hash_context
111
+ hash = @builder.hash do |m|
112
+ m.foo :hash do
113
+ m.bar 'baz'
114
+ end
115
+ end
116
+
117
+ assert_equal({ 'bar' => 'baz' }, hash['foo'])
118
+ end
119
+
120
+ def test_method_missing_in_value_context
121
+ assert_raises NoMethodError do
122
+ @builder.build do |m|
123
+ m.bar
124
+ end
125
+ end
126
+ end
127
+ end
metadata ADDED
@@ -0,0 +1,204 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: marble
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Alexander Kern
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-19 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: minitest
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: "2.0"
25
+ type: :development
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: mocha
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: "0.9"
36
+ type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: autotest
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: "4.4"
47
+ type: :development
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rails
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - "="
56
+ - !ruby/object:Gem::Version
57
+ version: 3.0.5
58
+ type: :development
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: json
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: "1.5"
69
+ type: :development
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: yard
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ version: "0.6"
80
+ type: :development
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: maruku
84
+ prerelease: false
85
+ requirement: &id007 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: "0.6"
91
+ type: :development
92
+ version_requirements: *id007
93
+ description: DSL for creating complex Ruby hashes and arrays
94
+ email:
95
+ - alex@kernul.com
96
+ executables: []
97
+
98
+ extensions: []
99
+
100
+ extra_rdoc_files: []
101
+
102
+ files:
103
+ - .autotest
104
+ - .gitignore
105
+ - .travis.yml
106
+ - .yardopts
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE
110
+ - README.md
111
+ - Rakefile
112
+ - lib/marble.rb
113
+ - lib/marble/rails_template_handler.rb
114
+ - lib/marble/version.rb
115
+ - marble.gemspec
116
+ - test/rails/.autotest
117
+ - test/rails/.gitignore
118
+ - test/rails/Gemfile
119
+ - test/rails/Gemfile.lock
120
+ - test/rails/README.md
121
+ - test/rails/Rakefile
122
+ - test/rails/app/controllers/application_controller.rb
123
+ - test/rails/app/controllers/test_controller.rb
124
+ - test/rails/app/views/test/index.json.marble
125
+ - test/rails/app/views/test/index.yaml.marble
126
+ - test/rails/config.ru
127
+ - test/rails/config/application.rb
128
+ - test/rails/config/boot.rb
129
+ - test/rails/config/environment.rb
130
+ - test/rails/config/environments/development.rb
131
+ - test/rails/config/environments/production.rb
132
+ - test/rails/config/environments/test.rb
133
+ - test/rails/config/initializers/secret_token.rb
134
+ - test/rails/config/initializers/session_store.rb
135
+ - test/rails/config/routes.rb
136
+ - test/rails/public/404.html
137
+ - test/rails/public/422.html
138
+ - test/rails/public/500.html
139
+ - test/rails/public/favicon.ico
140
+ - test/rails/public/robots.txt
141
+ - test/rails/script/rails
142
+ - test/rails/test/integration/marble_test.rb
143
+ - test/rails/test/test_helper.rb
144
+ - test/test_helper.rb
145
+ - test/test_marble.rb
146
+ has_rdoc: true
147
+ homepage: https://github.com/CapnKernul/marble
148
+ licenses: []
149
+
150
+ post_install_message:
151
+ rdoc_options: []
152
+
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: "0"
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: "0"
167
+ requirements: []
168
+
169
+ rubyforge_project: marble
170
+ rubygems_version: 1.6.2
171
+ signing_key:
172
+ specification_version: 3
173
+ summary: Ruby object builder
174
+ test_files:
175
+ - test/rails/.autotest
176
+ - test/rails/.gitignore
177
+ - test/rails/Gemfile
178
+ - test/rails/Gemfile.lock
179
+ - test/rails/README.md
180
+ - test/rails/Rakefile
181
+ - test/rails/app/controllers/application_controller.rb
182
+ - test/rails/app/controllers/test_controller.rb
183
+ - test/rails/app/views/test/index.json.marble
184
+ - test/rails/app/views/test/index.yaml.marble
185
+ - test/rails/config.ru
186
+ - test/rails/config/application.rb
187
+ - test/rails/config/boot.rb
188
+ - test/rails/config/environment.rb
189
+ - test/rails/config/environments/development.rb
190
+ - test/rails/config/environments/production.rb
191
+ - test/rails/config/environments/test.rb
192
+ - test/rails/config/initializers/secret_token.rb
193
+ - test/rails/config/initializers/session_store.rb
194
+ - test/rails/config/routes.rb
195
+ - test/rails/public/404.html
196
+ - test/rails/public/422.html
197
+ - test/rails/public/500.html
198
+ - test/rails/public/favicon.ico
199
+ - test/rails/public/robots.txt
200
+ - test/rails/script/rails
201
+ - test/rails/test/integration/marble_test.rb
202
+ - test/rails/test/test_helper.rb
203
+ - test/test_helper.rb
204
+ - test/test_marble.rb