Module: MundoPepino

Extended by:
Matchers::Fragments
Includes:
Base, Implementations, ImplementationsApi, ResourcesHistory, VisitsHistory
Defined in:
lib/mundo_pepino/version.rb,
lib/mundo_pepino.rb,
lib/mundo_pepino/base.rb,
lib/mundo_pepino/config.rb,
lib/mundo_pepino/en_US/mappings.rb,
lib/mundo_pepino/en_US/matchers.rb,
lib/mundo_pepino/es_ES/mappings.rb,
lib/mundo_pepino/es_ES/matchers.rb,
lib/mundo_pepino/visits_history.rb,
lib/mundo_pepino/implementations.rb,
lib/mundo_pepino/resources_history.rb,
lib/mundo_pepino/implementations_api.rb,
lib/mundo_pepino/matchers_delegation.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Base, Implementations, ImplementationsApi, Matchers, ResourcesHistory, VisitsHistory Classes: Config, CrudActionNotMapped, FieldNotMapped, ModelNotMapped, NotFoundInDatabase, NotFoundInHistoryNorDatabase, NotMapped, ResourceNotFound, VERSION, WithoutResources

Constant Summary

Constants included from ImplementationsApi

ImplementationsApi::MAX_NESTED_RESOURCES

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Matchers::Fragments

_como_, _cuyo_, _debo_estar_en_, _dentro_de_, _el_enlace_, _el_listado_de_, _fecha_y_o_hora_, _i_visit_, _la_etiqueta_, _la_pagina_, _leo_o_no_, _localizador_de_atributo_anidado_, _number_, _numero_, _pulso_, _que_existe_, _relleno_, _should_, _should_or_not_, _tenemos_en_bbdd_, _tiene_en_bbdd_, _veo_o_no_, _visito_, _which_

Methods included from VisitsHistory

#do_visit, #last_visited

Methods included from ResourcesHistory

#add_resource, #add_resource_from_database, #detect_first, #last_mentioned, #last_mentioned_called, #last_mentioned_of, #last_mentioned_resources, #last_mentioned_url, #method_missing, #pile_up, #recursive_group_search, #resources_array_field_and_values, #resources_flatten

Methods included from Implementations

#given_or_when_i_do_a_page_request, #given_or_when_i_follow_the_link, #given_resource_has_many_children, #given_resource_has_many_children_from_step_table, #given_resource_have_the_following_values_from_step_table, #given_those_resources_have_value_in_field, #given_we_have_a_number_of_instances_called, #given_we_have_the_following_instances_from_step_table, #then_i_see_or_not_the_text, #then_resource_called_name_should_have_child, #then_resource_called_name_should_have_n_children, #then_resource_called_name_should_have_value_in_field, #then_that_resource_should_have_child, #then_that_resource_should_have_n_children, #then_that_resource_should_have_value_in_field, #then_we_have_a_number_of_instances_in_our_database

Methods included from ImplementationsApi

#base_hash_for, #convert_to_field, #convert_to_model, #do_with_capybara, #do_with_webrat, #field_for, #find_field_and_do, #find_field_and_do_with_capybara, #find_field_and_do_with_webrat, #hasify, #last_mentioned_children, #last_mentioned_should_have_child, #last_mentioned_should_have_n_children, #last_mentioned_should_have_value, #names_for_simple_creation, #nested_field_id, #nested_field_id_prefix, #nested_field_prefix_prefix, #new_nested_field_id, #not_hasify, #not_shouldify, #parent_options, #real_value_for, #resource_index_or_mapped_page, #should_or_not_contain_text, #shouldify, #translated_hashes

Methods included from Base

#conditions_from_attributes, #create, #find_or_create, #parsed_attributes

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MundoPepino::ResourcesHistory

Class Attribute Details

.worldObject

Returns the value of attribute world.



32
33
34
# File 'lib/mundo_pepino.rb', line 32

def world
  @world
end

Class Method Details

.clean_modelsObject



85
86
87
88
89
90
# File 'lib/mundo_pepino.rb', line 85

def clean_models
config.models_to_clean.each do |model|
  model.destroy_all
  model.delete_all if model.count > 0
  end      
end

.common_mappingsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mundo_pepino.rb', line 40

def common_mappings
  String.add_mapper(:number) {|str| str.to_i}
  String.add_mapper(:model) {|str|
    begin
      c = str.singularize.capitalize.constantize
      c.superclass == ActiveRecord::Base ? c : nil
    rescue
      nil
    end
  }
  String.add_mapper :field
  String.add_mapper :crud_action
  String.add_mapper :relation_model
  String.add_mapper(:content_type,
    /\.png$/   => 'image/png',
    /\.jpe?g$/ => 'image/jpg',
    /\.gif$/   => 'image/gif') {|str| 'text/plain'}
  String.add_mapper(:underscored) {|string| string.gsub(/ +/, '_')}
  String.add_mapper(:unquoted) {|str| str =~ /^['"](.*)['"]$/ ? $1 : str}
  String.add_mapper(:regexp) {|str| str =~ /\/.+\/[a-z]*/ ? eval(str) : /#{Regexp.escape(str)}/m }
  String.add_mapper(:translated) do |str|
    if str =~ /^[a-z_]+\.[a-z_]+[a-z_\.]+$/
      I18n.translate(str, :default => str)
    elsif str =~ /^([a-z_]+\.[a-z_]+[a-z_\.]+),(?: )?(\{.+\})$/
      I18n.translate($1, {:default => str}.merge(eval($2)))
    else
      str
    end
  end
  String.add_mapper(:month) {|month| month.capitalize}
  String.add_mapper(:real_value) {|value| value} # true, false...
  String.add_mapper(:automagical_page)
  String.add_mapper(:page) do |str|
    str.to_automagical_page || (str =~ /^\/.*$|^https?:\/\//i ? str : nil)
  end
end

.configObject



77
78
79
# File 'lib/mundo_pepino.rb', line 77

def config
  @config ||= Config.new
end

.configure(&block) ⇒ Object



81
82
83
# File 'lib/mundo_pepino.rb', line 81

def configure(&block)
  config.configure(&block)
end

.extended(current_world) ⇒ Object



33
34
35
36
37
38
# File 'lib/mundo_pepino.rb', line 33

def extended(current_world)
  self.world = current_world
  common_mappings
  language_specific_mappings
  user_specific_mappings
end

.language_specific_mappingsObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mundo_pepino/en_US/mappings.rb', line 3

def language_specific_mappings
  String.real_value_mappings = {
    /^tru(e|th)$/i  => true,
    /^false$/i       => false
  }
  String.number_mappings = { 
    /^an?$/i    => 1,
    /^one$/i    => 1,
    /^first?$/i => 1,
    /^two$/i    => 2,
    /^second$/i => 2,
    /^three$/i  => 3,
    /^third$/i  => 3,
    /^four$/i   => 4,
    /^fourth$/i => 4,
    /^five$/i   => 5,
    /^fifth$/i  => 5,
    /^six$/i    => 6,
    /^seven$/i  => 7,
    /^eight$/i  => 8,
    /^nine$/i   => 9,
    /^ten$/i    => 10 
    }
  String.crud_action_mappings = {
    /^creation$/i           => 'new',
    /^changes?$/i           => 'edit',
    /^modifications?$/i     => 'edit',
    /^editions?$/i          => 'edit'
  }
  String.page_mappings[/^the home\s?page/i] = self.world.root_path
end

.user_specific_mappingsObject



92
93
94
95
96
97
98
99
# File 'lib/mundo_pepino.rb', line 92

def user_specific_mappings
  config.model_mappings.each {|k,v| String.model_mappings[k] = v}
  config.relation_model_mappings.each {|k,v| String.relation_model_mappings[k] = v}
  config.field_mappings.each {|k,v| String.field_mappings[k] = v}
  # url_mappings are deprecated, use page_mappings instead
  config.url_mappings.each {|k,v| String.page_mappings[k] = v}
  config.page_mappings.each {|k,v| String.page_mappings[k] = v}
end