Module: GreenPepper::NameResolver
- Defined in:
- lib/greenpepper/example/nameresolver.rb
Class Method Summary collapse
- .format_column_name(name) ⇒ Object
- .get_instance_field(fixture, field_name) ⇒ Object
- .set_instance_field(fixture, field_name, value) ⇒ Object
- .solve_fixture_name(fixture_name) ⇒ Object
Class Method Details
.format_column_name(name) ⇒ Object
40 41 42 |
# File 'lib/greenpepper/example/nameresolver.rb', line 40 def NameResolver.format_column_name name string = name.strip.downcase.split(' ').join('_') end |
.get_instance_field(fixture, field_name) ⇒ Object
49 50 51 52 |
# File 'lib/greenpepper/example/nameresolver.rb', line 49 def NameResolver.get_instance_field fixture, field_name reader = ReaderFieldAccessor.new reader.access_instance_field fixture, field_name end |
.set_instance_field(fixture, field_name, value) ⇒ Object
44 45 46 47 |
# File 'lib/greenpepper/example/nameresolver.rb', line 44 def NameResolver.set_instance_field fixture, field_name, value writer = WriterFieldAccessor.new writer.access_instance_field fixture, field_name + "=", value end |
.solve_fixture_name(fixture_name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/greenpepper/example/nameresolver.rb', line 12 def NameResolver.solve_fixture_name(fixture_name) # Remove accents using third party library # Ex. é => e fixture_name = fixture_name.removeaccents # Ignore illegal caracters fixture_name = fixture_name.gsub /[^a-zA-Z0-9_\s]/, "" regex = create_regex(fixture_name) fixture_classes = [] Module.constants.each{|constant| if(regex.match(constant)) fixture_classes.push(constant) end } return nil if(fixture_classes.length == 0) fixture_name_class = fixture_classes.find{|fixture_string| /.*(f|F)ixture$/ === fixture_string } if fixture_name_class == nil fixture_name_class = fixture_classes[0] end Object.const_get fixture_name_class end |