Class: DataSource
- Inherits:
-
Object
- Object
- DataSource
- Defined in:
- lib/DataSource.rb
Overview
<summary>
This helper classes process the request after recieve from the DSRequest.
The CRUD methods(add, remove, update, fetch) were supported.
</summary>
Instance Attribute Summary collapse
-
#data_source ⇒ Object
Returns the value of attribute data_source.
Instance Method Summary collapse
-
#execute(request) ⇒ Object
<summary> process the request </summary>.
-
#get_field(field_name) ⇒ Object
<summary> get the field content by the filed name </summary>.
-
#initialize(path, model) ⇒ DataSource
constructor
A new instance of DataSource.
Constructor Details
#initialize(path, model) ⇒ DataSource
Returns a new instance of DataSource.
12 13 14 15 |
# File 'lib/DataSource.rb', line 12 def initialize(path, model) @model = model @pk = @model.primary_key() end |
Instance Attribute Details
#data_source ⇒ Object
Returns the value of attribute data_source.
8 9 10 |
# File 'lib/DataSource.rb', line 8 def data_source @data_source end |
Instance Method Details
#execute(request) ⇒ Object
<summary> process the request </summary>
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/DataSource.rb', line 32 def execute(request) operation_type = request.operationType case operation_type when 'fetch' @result = fetch(request) when 'add' @result = add(request) when 'remove' @result = remove(request) when 'update' @result = update(request) end return @result end |
#get_field(field_name) ⇒ Object
<summary> get the field content by the filed name </summary>
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/DataSource.rb', line 19 def get_field(field_name) fields = @data_source['fields'] fields.each do | f | if f['name'] == filed_name return f end end return nil end |