rgen_ext 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e81f0f93168cf34943559d9546433a1ceddc5882
4
+ data.tar.gz: de8df370efa41c0da4c0851aaf3740a0cd533975
5
+ SHA512:
6
+ metadata.gz: 6c2b98fe69ccd6246942e05fde08c0b65a273704a4a338ccadfc94f8df74832232ca62a71c7061005b6a89bbf43601f2304d1f0ff1918f1203bc24ef5c23f1fe
7
+ data.tar.gz: af65eb914e16d77c6c96d0f6bc09ffdff00bd1052bce3ad481bc868b8d58d93e3935ce05506acfbc90a649ba3877c8383be070a76f7232c270926387ae957296
@@ -0,0 +1,39 @@
1
+ # RGen-ext
2
+ # Common extension to the RGen Framework
3
+ # Federico Tomassetti, 2013
4
+
5
+ require 'rgen/metamodel_builder'
6
+
7
+ module RGen
8
+ module Ext
9
+
10
+ module InstantiationExtensions
11
+
12
+ def build(values={})
13
+ instance = self.new
14
+ if values.is_a? Hash
15
+ values.each do |k,v|
16
+ attribute = self.ecore.eAllAttributes.find {|x| x.name==k.to_s}
17
+ reference = self.ecore.eAllReferences.find {|x| x.name==k.to_s}
18
+ raise "UnexistingFeature #{k}" unless (attribute or reference)
19
+ setter = (k.to_s+'=').to_sym
20
+ instance.send setter, v
21
+ end
22
+ else
23
+ raise "SingleAttributeRequired" if self.ecore.eAllAttributes.count!=1
24
+ attribute = self.ecore.eAllAttributes[0]
25
+ set_attr(instance,attribute,values)
26
+ end
27
+ instance
28
+ end
29
+
30
+ private
31
+
32
+ def set_attr(instance,attribute,value)
33
+ setter = (attribute.name+'=').to_sym
34
+ instance.send setter, value
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -22,7 +22,7 @@ module NavigationExtensions
22
22
  def all_children(of=self)
23
23
  arr = []
24
24
  ecore = of.class.ecore
25
- ecore.eAllReferences.select {|r| r.containment}.each do |ref|
25
+ ecore.eAllReferences.sort_by{|r| r.name}.select {|r| r.containment}.each do |ref|
26
26
  res = of.send(ref.name.to_sym)
27
27
  if ref.many
28
28
  res.each do |el|
@@ -1,3 +1,3 @@
1
1
  module RgenExt
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/rgen/ext.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require "rgen/ext/version"
2
2
  require "rgen/ext/comparison"
3
3
  require "rgen/ext/navigation_extensions"
4
+ require "rgen/ext/instantiation_extensions"
data/rgen_ext.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "rgen"
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "bundler"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "simplecov"
26
26
  end
@@ -0,0 +1,40 @@
1
+ require 'helper'
2
+
3
+ class InstantiationExtensionsTest < Test::Unit::TestCase
4
+
5
+ module TestMetamodel
6
+
7
+ class Dog < RGen::MetamodelBuilder::MMBase
8
+ class << self
9
+ include RGen::Ext::InstantiationExtensions
10
+ end
11
+ has_attr 'name',String
12
+ end
13
+
14
+ class Person < RGen::MetamodelBuilder::MMBase
15
+ class << self
16
+ include RGen::Ext::InstantiationExtensions
17
+ end
18
+ has_attr 'first_name', String
19
+ has_attr 'surname', String
20
+ has_attr 'age', Integer
21
+ end
22
+
23
+ end
24
+
25
+ def setup
26
+ end
27
+
28
+ def test_build_single_attribute
29
+ dog = TestMetamodel::Dog.build('fuffy')
30
+ assert_equal 'fuffy',dog.name
31
+ end
32
+
33
+ def test_build_multiple_attributes
34
+ person = TestMetamodel::Person.build(:first_name => 'Luca', :surname => 'Gillus', :age => 23)
35
+ assert_equal 'Luca',person.first_name
36
+ assert_equal 'Gillus',person.surname
37
+ assert_equal 23,person.age
38
+ end
39
+
40
+ end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgen_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Federico Tomassetti
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-06 00:00:00.000000000 Z
11
+ date: 2013-12-30 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rgen
@@ -18,29 +17,25 @@ dependencies:
18
17
  - - '>='
19
18
  - !ruby/object:Gem::Version
20
19
  version: '0'
21
- none: false
22
20
  requirement: !ruby/object:Gem::Requirement
23
21
  requirements:
24
22
  - - '>='
25
23
  - !ruby/object:Gem::Version
26
24
  version: '0'
27
- none: false
28
25
  prerelease: false
29
26
  type: :runtime
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  version_requirements: !ruby/object:Gem::Requirement
33
30
  requirements:
34
- - - ~>
31
+ - - '>='
35
32
  - !ruby/object:Gem::Version
36
- version: '1.3'
37
- none: false
33
+ version: '0'
38
34
  requirement: !ruby/object:Gem::Requirement
39
35
  requirements:
40
- - - ~>
36
+ - - '>='
41
37
  - !ruby/object:Gem::Version
42
- version: '1.3'
43
- none: false
38
+ version: '0'
44
39
  prerelease: false
45
40
  type: :development
46
41
  - !ruby/object:Gem::Dependency
@@ -50,13 +45,11 @@ dependencies:
50
45
  - - '>='
51
46
  - !ruby/object:Gem::Version
52
47
  version: '0'
53
- none: false
54
48
  requirement: !ruby/object:Gem::Requirement
55
49
  requirements:
56
50
  - - '>='
57
51
  - !ruby/object:Gem::Version
58
52
  version: '0'
59
- none: false
60
53
  prerelease: false
61
54
  type: :development
62
55
  - !ruby/object:Gem::Dependency
@@ -66,13 +59,11 @@ dependencies:
66
59
  - - '>='
67
60
  - !ruby/object:Gem::Version
68
61
  version: '0'
69
- none: false
70
62
  requirement: !ruby/object:Gem::Requirement
71
63
  requirements:
72
64
  - - '>='
73
65
  - !ruby/object:Gem::Version
74
66
  version: '0'
75
- none: false
76
67
  prerelease: false
77
68
  type: :development
78
69
  description: Extensions of general use to RGen
@@ -90,16 +81,19 @@ files:
90
81
  - Rakefile
91
82
  - lib/rgen/ext.rb
92
83
  - lib/rgen/ext/comparison.rb
84
+ - lib/rgen/ext/instantiation_extensions.rb
93
85
  - lib/rgen/ext/navigation_extensions.rb
94
86
  - lib/rgen/ext/version.rb
95
87
  - rgen_ext.gemspec
96
88
  - test/helper.rb
97
89
  - test/test_comparison.rb
90
+ - test/test_instantiation_extensions.rb
98
91
  - test/test_navigation_extensions.rb
99
92
  - test/test_traverse.rb
100
93
  homepage: http://github.com/ftomassetti/rgen_ext
101
94
  licenses:
102
95
  - Apache License v2
96
+ metadata: {}
103
97
  post_install_message:
104
98
  rdoc_options: []
105
99
  require_paths:
@@ -108,28 +102,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
102
  requirements:
109
103
  - - '>='
110
104
  - !ruby/object:Gem::Version
111
- segments:
112
- - 0
113
105
  version: '0'
114
- hash: 2
115
- none: false
116
106
  required_rubygems_version: !ruby/object:Gem::Requirement
117
107
  requirements:
118
108
  - - '>='
119
109
  - !ruby/object:Gem::Version
120
- segments:
121
- - 0
122
110
  version: '0'
123
- hash: 2
124
- none: false
125
111
  requirements: []
126
112
  rubyforge_project:
127
- rubygems_version: 1.8.24
113
+ rubygems_version: 2.2.0
128
114
  signing_key:
129
- specification_version: 3
115
+ specification_version: 4
130
116
  summary: Extensions of general use to RGen
131
117
  test_files:
132
118
  - test/helper.rb
133
119
  - test/test_comparison.rb
120
+ - test/test_instantiation_extensions.rb
134
121
  - test/test_navigation_extensions.rb
135
122
  - test/test_traverse.rb