scaffold_parser 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f042c0e917538cbf64c26da83731d871a9b024d
4
- data.tar.gz: 74d9920de765dab0b8daa84774a740f8f9e0c4d7
3
+ metadata.gz: 96091a0980204269f8a932357cb225cd1d2d9ae8
4
+ data.tar.gz: 7ab015075a04be35f3199cfd399b6b14747b1bdd
5
5
  SHA512:
6
- metadata.gz: 50d8898fce80d67adb3451646ac39e9ba46dcb669a36803e0d1550dc1f43a100443a290dfef9d8870cdb658bb190f60139b5559f7b2928cfd4b8914710662c0e
7
- data.tar.gz: e753b2f92964c5efd0d566312f8599f24bb9a3475bef511267b9d45f99d3b0d0c131f0617dd9f7942fecf93dcdf9994b5a06c1120714a95b08908641e8399573
6
+ metadata.gz: df55b57182decf235dca79704cef3238b60330143620ddf55ab351126ff4c6457d42fe00724e7bcd92193db3b25a73d5b5aa636014b6a3dc75765ba8dd812963
7
+ data.tar.gz: 61fa3c5464cd7c0e8970daa7d96f7a113e238e11ea0362d0cece1b679a1ae86a4607ab48428b26195fcb9060dd34c7eea797843b04a3df2f655c1ed03c302304
@@ -7,6 +7,22 @@ module ScaffoldParser
7
7
  include BaseMethod
8
8
  include Utils
9
9
 
10
+ def to_s
11
+ f = StringIO.new
12
+
13
+ f.puts "def #{method_name}"
14
+ f.puts indent(method_body.lines).join
15
+ f.puts "end"
16
+
17
+ f.puts
18
+
19
+ f.puts "def #{method_name}_attributes"
20
+ f.puts " attributes_at '#{at}'"
21
+ f.puts "end"
22
+
23
+ f.string.strip
24
+ end
25
+
10
26
  def method_body
11
27
  "at '#{at}'"
12
28
  end
@@ -15,12 +31,13 @@ module ScaffoldParser
15
31
  [source.xmlns_prefix, "#{source.name}"].compact.join(':')
16
32
  end
17
33
 
18
- def to_h_with_attrs_method
19
- "hash[:#{method_name}] = #{method_name} if has? '#{at}'"
34
+ def to_h_method
35
+ "hash[:#{method_name}] = #{method_name} if has? '#{at}'\n"\
36
+ "hash[:#{method_name}_attributes] = #{method_name}_attributes if has? '#{at}'"
20
37
  end
21
38
 
22
39
  def to_builder
23
- "root << build_element('#{at}', data[:#{method_name}]) if data.key? :#{method_name}"
40
+ "root << build_element('#{at}', data[:#{method_name}], data[:#{method_name}_attributes]) if data.key? :#{method_name}"
24
41
  end
25
42
 
26
43
  def sequence(_)
@@ -56,10 +56,15 @@ module ScaffoldParser
56
56
  f.puts if methods.any?
57
57
  f.puts methods.map { |method| indent(method.to_s.lines).join }.join("\n\n")
58
58
  f.puts if methods.any?
59
- f.puts " def to_h_with_attrs"
60
- f.puts " hash = ParserCore::HashWithAttributes.new({}, attributes)"
59
+ f.puts " def to_h"
60
+ f.puts " hash = {}"
61
+ f.puts " hash[:attributes] = attributes"
61
62
  f.puts
62
- methods.each { |method| f.puts " #{method.to_h_with_attrs_method}" }
63
+ methods.each do |method|
64
+ method.to_h_method.lines.each do |line|
65
+ f.puts " #{line}"
66
+ end
67
+ end
63
68
  f.puts if methods.any?
64
69
  if includes.any?
65
70
  f.puts " mega.inject(hash) { |memo, r| memo.merge r }"
@@ -96,8 +101,8 @@ module ScaffoldParser
96
101
  f.puts
97
102
  f.puts " def builder"
98
103
  f.puts " root = Ox::Element.new(name)"
99
- f.puts " if data.respond_to? :attributes"
100
- f.puts " data.attributes.each { |k, v| root[k] = v }"
104
+ f.puts " if data.key? :attributes"
105
+ f.puts " data[:attributes].each { |k, v| root[k] = v }"
101
106
  f.puts " end"
102
107
  f.puts
103
108
  if inherit_from
@@ -24,11 +24,11 @@ module ScaffoldParser
24
24
  [source.xmlns_prefix, "#{source.name}"].compact.join(':')
25
25
  end
26
26
 
27
- def to_h_with_attrs_method
27
+ def to_h_method
28
28
  if item_class == 'String'
29
29
  "hash[:#{method_name}] = #{method_name} if has? '#{name_with_prefix}'"
30
30
  else
31
- "hash[:#{method_name}] = #{method_name}.map(&:to_h_with_attrs) if has? '#{name_with_prefix}'"
31
+ "hash[:#{method_name}] = #{method_name}.map(&:to_h) if has? '#{name_with_prefix}'"
32
32
  end
33
33
  end
34
34
 
@@ -35,10 +35,15 @@ module ScaffoldParser
35
35
  methods.each { |method| template.methods << indent(method.to_s.lines).join }
36
36
 
37
37
  meth = StringIO.new
38
- meth.puts " def to_h_with_attrs"
39
- meth.puts " hash = ParserCore::HashWithAttributes.new({}, attributes)"
38
+ meth.puts " def to_h"
39
+ meth.puts " hash = {}"
40
+ meth.puts " hash[:attributes] = attributes"
40
41
  meth.puts
41
- methods.each { |method| meth.puts " #{method.to_h_with_attrs_method}" }
42
+ methods.each do |method|
43
+ method.to_h_method.lines.each do |line|
44
+ meth.puts " #{line}"
45
+ end
46
+ end
42
47
  meth.puts
43
48
  meth.puts " hash"
44
49
  meth.puts " end"
@@ -60,8 +65,8 @@ module ScaffoldParser
60
65
  meth = StringIO.new
61
66
  meth.puts " def builder"
62
67
  meth.puts " root = Ox::Element.new(name)"
63
- meth.puts " if data.respond_to? :attributes"
64
- meth.puts " data.attributes.each { |k, v| root[k] = v }"
68
+ meth.puts " if data.key? :attributes"
69
+ meth.puts " data[:attributes].each { |k, v| root[k] = v }"
65
70
  meth.puts " end"
66
71
  meth.puts
67
72
  meth.puts methods.map { |method| indent(indent(method.to_builder.lines)).join }.join("\n")
@@ -22,11 +22,11 @@ module ScaffoldParser
22
22
  [source.xmlns_prefix, "#{source.name}"].compact.join(':')
23
23
  end
24
24
 
25
- def to_h_with_attrs_method
25
+ def to_h_method
26
26
  if item_class == 'String'
27
27
  "hash[:#{method_name}] = #{method_name} if has? '#{name_with_prefix}'"
28
28
  else
29
- "hash[:#{method_name}] = #{method_name}.map(&:to_h_with_attrs) if has? '#{name_with_prefix}'"
29
+ "hash[:#{method_name}] = #{method_name}.map(&:to_h) if has? '#{name_with_prefix}'"
30
30
  end
31
31
  end
32
32
 
@@ -32,8 +32,8 @@ module ScaffoldParser
32
32
  [source.xmlns_prefix, "#{method_name}"].compact.join(':')
33
33
  end
34
34
 
35
- def to_h_with_attrs_method
36
- "hash[:#{method_name}] = #{method_name}.to_h_with_attrs if has? '#{at}'"
35
+ def to_h_method
36
+ "hash[:#{method_name}] = #{method_name}.to_h if has? '#{at}'"
37
37
  end
38
38
 
39
39
  def to_builder
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'scaffold_parser'
6
- spec.version = '0.7.0'
6
+ spec.version = '0.8.0'
7
7
  spec.authors = ['Premysl Donat']
8
8
  spec.email = ['pdonat@seznam.cz']
9
9
 
@@ -19,12 +19,13 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = ['scaffold_parser']
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency 'bundler', '~> 1.16'
23
- spec.add_development_dependency 'rake', '~> 10.0'
24
- spec.add_development_dependency 'rspec', '~> 3.0'
22
+ spec.add_dependency 'xsd_model'
23
+ spec.add_dependency 'activesupport'
24
+
25
+ spec.add_development_dependency 'bundler'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec'
25
28
  spec.add_development_dependency 'pry'
26
29
  spec.add_development_dependency 'pry-byebug'
27
- spec.add_development_dependency 'nokogiri'
28
- spec.add_development_dependency 'activesupport'
29
30
  spec.add_development_dependency 'saharspec'
30
31
  end
metadata CHANGED
@@ -1,59 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scaffold_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Premysl Donat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-12 00:00:00.000000000 Z
11
+ date: 2018-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: xsd_model
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
20
- type: :development
19
+ version: '0'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
33
+ version: '0'
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: pry
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: pry-byebug
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: nokogiri
84
+ name: pry
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: activesupport
98
+ name: pry-byebug
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="