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
- .all ⇒ Object
- .delete_repo(repo_id) ⇒ Object
-
.delete_this(data) ⇒ Object
GET.
-
.get_data(id, query_string = nil) ⇒ Object
GET.
- .insert!(definition) ⇒ Object
- .update!(definition) ⇒ Object
- .update_repo_name(id, name) ⇒ 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
.all ⇒ Object
37 38 39 |
# File 'lib/mutx/API/repo.rb', line 37 def self.all Mutx::Database::MongoConnector.all_repos end |
.delete_repo(repo_id) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/mutx/API/repo.rb', line 89 def self.delete_repo repo_id Mutx::Database::MongoConnector.delete_repo repo_id success = true = "Repo deleted!" {success:success, message:} end |
.delete_this(data) ⇒ Object
GET
49 50 51 52 53 54 55 |
# File 'lib/mutx/API/repo.rb', line 49 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
42 43 44 45 |
# File 'lib/mutx/API/repo.rb', line 42 def self.get_data id, query_string=nil result = Mutx::Database::MongoConnector.repo_data_for_id(id) result || { action: 'get', success: false, message: 'Repo get was nok' } end |
.insert!(definition) ⇒ Object
69 70 71 72 |
# File 'lib/mutx/API/repo.rb', line 69 def self.insert! definition data = self.new(definition).structure Mutx::Database::MongoConnector.insert_repo(self.new(definition).structure) end |
.update!(definition) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/mutx/API/repo.rb', line 74 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 |
.update_repo_name(id, name) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/mutx/API/repo.rb', line 82 def self.update_repo_name id, name Mutx::Database::MongoConnector.update_repo_name(id, name) success = true = "Repo name updated!" {success:success, message:} 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
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mutx/API/repo.rb', line 58 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 |