model_xml 1.0.4 → 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/README.md CHANGED
@@ -65,6 +65,14 @@ For more complicated setups, you can use block notation like this:
65
65
  end
66
66
  end
67
67
 
68
+ The above relies on method_missing to work - so note that if you are using a ruby reserved method name (like id) for your tag, you may need to use the longer form block notation with the field operator:
69
+
70
+ class User < ActiveRecord::Base
71
+ model_xml do
72
+ field :id, proc {|u| u.some_other_id_method}
73
+ end
74
+ end
75
+
68
76
  For conditional data sets, you can declare named blocks using block notation like this:
69
77
 
70
78
  class User < ActiveRecord::Base
@@ -18,7 +18,7 @@ module ModelXML
18
18
  @field_set = []
19
19
  end
20
20
 
21
- def method_missing *args
21
+ def field *args
22
22
 
23
23
  # if the method is called without arguments, add it as a member of the field set
24
24
  if args.map(&:class) == [Symbol]
@@ -28,6 +28,11 @@ module ModelXML
28
28
  else
29
29
  @field_set << args
30
30
  end
31
+
32
+ end
33
+
34
+ def method_missing *args
35
+ field *args
31
36
  end
32
37
 
33
38
  end
@@ -1,10 +1,11 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "model_xml"
3
- s.version = '1.0.4'
3
+ s.version = '1.0.5'
4
4
  s.authors = "Rob Anderson"
5
5
  s.email = "rob.anderson@paymentcardsolutions.co.uk"
6
6
  s.summary = "Ruby object to xml converter"
7
7
  s.description = "Simple replacement for ActiveRecord's default to_xml"
8
+ s.homepage = "https://github.com/rob-anderson/model_xml"
8
9
 
9
10
  s.add_dependency 'builder', '>= 2.1.2'
10
11
 
@@ -12,5 +12,12 @@ class BlockParserTest < Test::Unit::TestCase
12
12
  assert_equal [:foo, [:bar, 3, 4]], ModelXML::BlockParser.parse(&block)
13
13
  end
14
14
 
15
+ def test_parse_with_id_field
16
+ block = Proc.new do
17
+ field :id, 2
18
+ end
19
+ assert_equal [[:id, 2]], ModelXML::BlockParser.parse(&block).inspect
20
+ end
21
+
15
22
  end
16
23
 
@@ -108,6 +108,21 @@ class ModelXMLTest < Test::Unit::TestCase
108
108
  assert_equal res, p.to_xml
109
109
  end
110
110
 
111
+ def test_field_operator
112
+ TestStruct.instance_eval do
113
+ model_xml_reset!
114
+ model_xml do
115
+ field :id, proc {|o| 'foo'}
116
+ end
117
+ end
118
+
119
+ res = '<?xml version="1.0" encoding="UTF-8"?>
120
+ <teststruct>
121
+ <id>foo</id>
122
+ </teststruct>
123
+ '
124
+ assert_equal res, @t.to_xml
125
+ end
111
126
 
112
127
 
113
128
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_xml
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 4
10
- version: 1.0.4
9
+ - 5
10
+ version: 1.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rob Anderson
@@ -50,7 +50,7 @@ files:
50
50
  - model_xml.gemspec
51
51
  - test/test_block_parser.rb
52
52
  - test/test_model_xml.rb
53
- homepage:
53
+ homepage: https://github.com/rob-anderson/model_xml
54
54
  licenses: []
55
55
 
56
56
  post_install_message: