Class: Mutx::API::Input
- Inherits:
-
Object
- Object
- Mutx::API::Input
- Defined in:
- lib/mutx/API/input.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#reference ⇒ Object
readonly
Returns the value of attribute reference.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
- .delete(param_id) ⇒ Object
-
.delete_this(data) ⇒ Object
GET.
-
.get_data(id, query_string = nil) ⇒ Object
GET.
- .info(id) ⇒ Object
- .insert!(definition) ⇒ Object
- .update!(definition) ⇒ Object
- .validate_and_create(definition) ⇒ Object
- .validate_json_format(definition) ⇒ Object
Instance Method Summary collapse
-
#initialize(definition) ⇒ Input
constructor
A new instance of Input.
- #structure ⇒ Object
Constructor Details
#initialize(definition) ⇒ Input
Returns a new instance of Input.
7 8 9 10 11 12 13 14 15 |
# File 'lib/mutx/API/input.rb', line 7 def initialize definition Mutx::Support::Log.debug "definition in new => #{definition}" id = definition["_id"] || Mutx::Database::MongoConnector.generate_id @id = id @reference = definition["reference"] @name = definition["name"] @value = definition["value"] @created_at = Time.now.utc end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
5 6 7 |
# File 'lib/mutx/API/input.rb', line 5 def created_at @created_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/mutx/API/input.rb', line 5 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/mutx/API/input.rb', line 5 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/mutx/API/input.rb', line 5 def @options end |
#reference ⇒ Object (readonly)
Returns the value of attribute reference.
5 6 7 |
# File 'lib/mutx/API/input.rb', line 5 def reference @reference end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
5 6 7 |
# File 'lib/mutx/API/input.rb', line 5 def required @required end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/mutx/API/input.rb', line 5 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/mutx/API/input.rb', line 5 def value @value end |
Class Method Details
.delete(param_id) ⇒ Object
75 76 77 |
# File 'lib/mutx/API/input.rb', line 75 def self.delete param_id Mutx::Database::MongoConnector.delete_custom_param param_id end |
.delete_this(data) ⇒ Object
GET
45 46 47 48 49 50 51 |
# File 'lib/mutx/API/input.rb', line 45 def self.delete_this data if self.delete data["_id"] {action:"delete", success:true, message:"Custom Param #{data["name"]} deleted"} else {action:"delete", success:false, message:"Could not delete custom param #{data["name"]}"} end end |
.get_data(id, query_string = nil) ⇒ Object
GET
36 37 38 |
# File 'lib/mutx/API/input.rb', line 36 def self.get_data id, query_string=nil result = self.info id end |
.info(id) ⇒ Object
40 41 42 |
# File 'lib/mutx/API/input.rb', line 40 def self.info id result = Mutx::Database::MongoConnector.input_data_for_id(id) end |
.insert!(definition) ⇒ Object
65 66 67 68 |
# File 'lib/mutx/API/input.rb', line 65 def self.insert! definition #definition.delete("action") Mutx::Database::MongoConnector.insert_input(self.new(definition).structure) end |
.update!(definition) ⇒ Object
70 71 72 73 |
# File 'lib/mutx/API/input.rb', line 70 def self.update! definition definition.delete("action") Mutx::Database::MongoConnector.update_custom_param(self.new(definition).structure) end |
.validate_and_create(definition) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/mutx/API/input.rb', line 27 def self.validate_and_create definition if insert!(definition) {action:"create", success:true, message:"Input #{definition["name"]} created"} else {action:"create", success:false, message:"Input #{definition["name"]} could not be created"} end end |
.validate_json_format(definition) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mutx/API/input.rb', line 54 def self.validate_json_format definition Mutx::Support::Log.debug "Value is a => #{definition['value'].class} => #{definition["value"]}" begin value = JSON.parse(definition["value"]) Mutx::Support::Log.debug "NOW Value is a => #{value.class} => #{value}" nil rescue return "Invalid json format" end end |
Instance Method Details
#structure ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/mutx/API/input.rb', line 17 def structure { "_id" => id, "reference" => reference, "name" => name, "value" => value, "created_at" => created_at } end |