Class: HerokuConfigVars::HerokuApp
- Inherits:
-
Object
- Object
- HerokuConfigVars::HerokuApp
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations
- Defined in:
- app/models/heroku_config_vars/heroku_app.rb
Instance Attribute Summary collapse
-
#current_vars ⇒ Object
readonly
Returns the value of attribute current_vars.
-
#loaded ⇒ Object
(also: #loaded?, #persisted?)
readonly
Returns the value of attribute loaded.
-
#vars ⇒ Object
Returns the value of attribute vars.
Class Method Summary collapse
Instance Method Summary collapse
- #added_vars ⇒ Object
- #api_key ⇒ Object
- #api_key=(value) ⇒ Object
- #app_name ⇒ Object
- #app_name=(value) ⇒ Object
- #attributes=(attrs = {}) ⇒ Object
- #changes ⇒ Object
- #id ⇒ Object
-
#initialize(attrs = {}) {|_self| ... } ⇒ HerokuApp
constructor
A new instance of HerokuApp.
- #kept_vars ⇒ Object
- #load_vars ⇒ Object
- #removed_vars ⇒ Object
- #save ⇒ Object
- #updated_and_added_vars ⇒ Object
- #updated_vars ⇒ Object
Constructor Details
#initialize(attrs = {}) {|_self| ... } ⇒ HerokuApp
Returns a new instance of HerokuApp.
29 30 31 32 33 34 35 36 37 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 29 def initialize(attrs={}) @vars = {} @current_vars = {} @loaded = false self.attributes = attrs yield self if block_given? end |
Instance Attribute Details
#current_vars ⇒ Object (readonly)
Returns the value of attribute current_vars.
10 11 12 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 10 def current_vars @current_vars end |
#loaded ⇒ Object (readonly) Also known as: loaded?, persisted?
Returns the value of attribute loaded.
9 10 11 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 9 def loaded @loaded end |
#vars ⇒ Object
Returns the value of attribute vars.
7 8 9 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 7 def vars @vars end |
Class Method Details
.find ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 18 def self.find attrs = { app_name: ENV['HEROKU_APP_NAME'], api_key: ENV['HEROKU_API_KEY'] } new(attrs) do |app| app.load_vars if app.valid? end end |
Instance Method Details
#added_vars ⇒ Object
82 83 84 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 82 def added_vars vars.except *current_vars.keys end |
#api_key ⇒ Object
53 54 55 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 53 def api_key @api_key ||= @vars['HEROKU_API_KEY'].presence end |
#api_key=(value) ⇒ Object
57 58 59 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 57 def api_key=(value) @api_key = @vars['HEROKU_API_KEY'] = value end |
#app_name ⇒ Object
45 46 47 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 45 def app_name @app_name ||= @vars['HEROKU_APP_NAME'].presence end |
#app_name=(value) ⇒ Object
49 50 51 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 49 def app_name=(value) @app_name = @vars['HEROKU_APP_NAME'] = value end |
#attributes=(attrs = {}) ⇒ Object
39 40 41 42 43 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 39 def attributes=(attrs={}) attrs.each do |key, value| self.send "#{key}=", value end end |
#changes ⇒ Object
98 99 100 101 102 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 98 def changes @changes ||= vars.dup. delete_if { |k, v| current_vars[k] == v }. merge!(current_vars.dup.delete_if { |k, v| vars.has_key?(k) }) end |
#id ⇒ Object
61 62 63 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 61 def id app_name end |
#kept_vars ⇒ Object
86 87 88 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 86 def kept_vars current_vars.slice *vars.keys end |
#load_vars ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 65 def load_vars catch_heroku_errors do Rails.logger.debug 'Loading config' @vars = connection.get_config_vars(app_name).body @current_vars = @vars.dup.freeze @loaded = true end end |
#removed_vars ⇒ Object
78 79 80 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 78 def removed_vars current_vars ? current_vars.except(*vars.keys) : {} end |
#save ⇒ Object
74 75 76 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 74 def save save_to_heroku and save_to_env if valid? end |
#updated_and_added_vars ⇒ Object
94 95 96 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 94 def updated_and_added_vars changes.slice(*vars.keys) end |
#updated_vars ⇒ Object
90 91 92 |
# File 'app/models/heroku_config_vars/heroku_app.rb', line 90 def updated_vars changes.slice(*kept_vars.keys) end |