Class: Mutx::API::Repo
- Inherits:
-
Object
- Object
- Mutx::API::Repo
- Defined in:
- lib/mutx/API/repo.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_update ⇒ Object
readonly
Returns the value of attribute last_update.
-
#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.
-
#repo_name ⇒ Object
readonly
Returns the value of attribute repo_name.
-
#repo_token ⇒ Object
readonly
Returns the value of attribute repo_token.
-
#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(name, query_string = nil) ⇒ Object
GET.
- .info(name) ⇒ Object
- .insert!(definition) ⇒ Object
- .update!(definition) ⇒ Object
- .validate_and_create(definition) ⇒ Object
- .validate_json_format(definition) ⇒ Object
Instance Method Summary collapse
-
#initialize(definition) ⇒ Repo
constructor
A new instance of Repo.
- #structure ⇒ Object
Constructor Details
#initialize(definition) ⇒ Repo
Returns a new instance of Repo.
9 10 11 12 13 14 15 16 17 |
# File 'lib/mutx/API/repo.rb', line 9 def initialize definition Mutx::Support::Log.debug "definition in new => #{definition}" id = definition["_id"] || Mutx::Database::MongoConnector.generate_id @id = id @repo_name = definition["name"] @repo_token = definition["token"] || Mutx::Database::MongoConnector.generate_token @value = definition["value"] @last_update = Time.now.utc end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/mutx/API/repo.rb', line 7 def id @id end |
#last_update ⇒ Object (readonly)
Returns the value of attribute last_update.
7 8 9 |
# File 'lib/mutx/API/repo.rb', line 7 def last_update @last_update end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/mutx/API/repo.rb', line 7 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/mutx/API/repo.rb', line 7 def end |
#reference ⇒ Object (readonly)
Returns the value of attribute reference.
7 8 9 |
# File 'lib/mutx/API/repo.rb', line 7 def reference @reference end |
#repo_name ⇒ Object (readonly)
Returns the value of attribute repo_name.
7 8 9 |
# File 'lib/mutx/API/repo.rb', line 7 def repo_name @repo_name end |
#repo_token ⇒ Object (readonly)
Returns the value of attribute repo_token.
7 8 9 |
# File 'lib/mutx/API/repo.rb', line 7 def repo_token @repo_token end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
7 8 9 |
# File 'lib/mutx/API/repo.rb', line 7 def required @required end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/mutx/API/repo.rb', line 7 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/mutx/API/repo.rb', line 7 def value @value end |
Class Method Details
.delete(param_id) ⇒ Object
85 86 87 |
# File 'lib/mutx/API/repo.rb', line 85 def self.delete param_id Mutx::Database::MongoConnector.delete_custom_param param_id end |
.delete_this(data) ⇒ Object
GET
52 53 54 55 56 57 58 |
# File 'lib/mutx/API/repo.rb', line 52 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(name, query_string = nil) ⇒ Object
GET
38 39 40 41 42 43 44 45 |
# File 'lib/mutx/API/repo.rb', line 38 def self.get_data name, query_string=nil result = self.info name if result result else {action:"get", success:false, message:"Repo get was nok"} end end |
.info(name) ⇒ Object
47 48 49 |
# File 'lib/mutx/API/repo.rb', line 47 def self.info name result = Mutx::Database::MongoConnector.repo_data_for_name(name) end |
.insert!(definition) ⇒ Object
72 73 74 75 |
# File 'lib/mutx/API/repo.rb', line 72 def self.insert! definition data = self.new(definition).structure Mutx::Database::MongoConnector.insert_repo(self.new(definition).structure) end |
.update!(definition) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/mutx/API/repo.rb', line 77 def self.update! definition if Mutx::Database::MongoConnector.update_repo_data(self.new(definition).structure) {action:"update", success:true, message:"Repo updated"} else {action:"update", success:false, message:"Repo could not be updated"} end end |
.validate_and_create(definition) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/mutx/API/repo.rb', line 29 def self.validate_and_create definition if insert!(definition) {action:"create", success:true, message:"Repo #{definition["name"]} created"} else {action:"create", success:false, message:"Repo #{definition["name"]} could not be created"} end end |
.validate_json_format(definition) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mutx/API/repo.rb', line 61 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
19 20 21 22 23 24 25 26 27 |
# File 'lib/mutx/API/repo.rb', line 19 def structure { "_id" => id, "repo_name" => repo_name.gsub(" ","_"), "repo_token" => repo_token, "value" => value, "last_update" => last_update } end |