Module: Lazylead::ORM
Overview
ORM-related methods
Defined Under Namespace
Classes: System, Task, Team, VerboseTask
Instance Method Summary collapse
-
#env(opts) ⇒ Object
Tables from database may have configuration in json column.
- #inspect ⇒ Object
-
#to_hash ⇒ Object
Convert json-based database column ‘properties’ to hash.
- #to_s ⇒ Object
Instance Method Details
#env(opts) ⇒ Object
Tables from database may have configuration in json column. Some of those properties might be configured/overridden by environment variable using macros “$…”
{
...
"user" = "${my_user}",
"pass" = "${my_pass}"
"url" = "https://url.com"
...
}
next, we need to configure following environment variables(ENV)
my_user=XXXXX
my_pass=YYYYY
thus, the result of this method is
{
...
"user" = "XXXXXX",
"pass" = "YYYYYY"
"url" = "https://url.com"
...
}
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/lazylead/model.rb', line 67 def env(opts) opts.each_with_object({}) do |e, o| k = e[0] v = e[1] if v.respond_to? :start_with? v = ENV[v.slice(2, v.length - 3)] if v.start_with? "${" end o[k] = v end end |
#inspect ⇒ Object
87 88 89 |
# File 'lib/lazylead/model.rb', line 87 def inspect to_s end |
#to_hash ⇒ Object
Convert json-based database column ‘properties’ to hash.
79 80 81 |
# File 'lib/lazylead/model.rb', line 79 def to_hash JSON.parse(properties).to_h end |
#to_s ⇒ Object
83 84 85 |
# File 'lib/lazylead/model.rb', line 83 def to_s attributes.map { |k, v| "#{k}='#{v}'" }.join(", ") end |