Class: MockWS::CRUDManager

Inherits:
Object
  • Object
show all
Extended by:
Carioca::Injector
Defined in:
lib/mockws/crud_manager.rb

Constant Summary collapse

DEFAULT_STATUS =
200

Class Method Summary collapse

Class Method Details

.configure(service) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/mockws/crud_manager.rb', line 131

def self.configure(service)
    @@service = service
    unless configuration.settings.services.select {|key,value|  value[:type] == :crud }.empty? then
        @@store = MockWS::Store::new
        output.info "Mock CRUD initialisation : "
        configuration.settings.services.select {|key,value|  value[:type] == :crud }.each do |_key, definition|
            @@store.add_model definition: definition
            output.item "Create JSON CRUD for #{definition[:object]}"
            output.arrow "GET /crud/#{definition[:object]}/list"
            output.arrow "GET /crud/#{definition[:object]}/<KEY>"
            output.arrow "POST /crud/#{definition[:object]} [JSON BODY]"
            output.arrow "PUT /crud/#{definition[:object]} [JSON BODY]"
            output.arrow "DELETE /crud/#{definition[:object]}/<KEY> "
            
        end
        create_crud_service
    end
end

.get_response_time(value) ⇒ Object



124
125
126
127
128
# File 'lib/mockws/crud_manager.rb', line 124

def self.get_response_time(value)
    return {value: value[:response_time], type: :static} if value.include? :response_time
    return {value: rand(1..value[:random_time]), type: :random} if value.include? :random_time
    return {value: 0, type: :instant} 
end