ssm_config 1.2.3 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 831eb6c691b037b55c991d51b7db74d2f65ce6aeb25ce1f72e4b8a58c09e86a7
4
- data.tar.gz: eb0016f6b7983d7c52e111e163077b12874f763f2afffb43509611b860b1aab8
3
+ metadata.gz: 04a9990dd3a7eff2abf7099c62aaaa900f51685ab7bba36c7aee7c0f0dc40df0
4
+ data.tar.gz: a3acb67638b4ace54e223b3dd47e83cc0784b62f1edb9974f7d081fd58933ea7
5
5
  SHA512:
6
- metadata.gz: 689e51652b4cafe794bedda63be2697220f63f495ec879c46b5a6f95f8b489d3763648c83e9037e05044814efeaf0d1e1abdfa30fdad68e9ff633cc641c27202
7
- data.tar.gz: 3a17b84d245ca4f18017ec1709db431ec7c9cfacef94de4c14cd4ced15007fccf225849d368ed3ac613a9c7d236d7bb7333727dcc564f2dcc7409b258c7a599e
6
+ metadata.gz: ebc49c73d573091da6a40bda97828e744e4784c080fe8385f40409e45cf6d71a1f5f8e43dc1fe366002bc3ea4d49e9da296a214bde84c5d9ff169e4de2b5ff25
7
+ data.tar.gz: d5237f97d84ed07108090f371de965030c44ced97a87da9d644e48908cc9ff8bedb8c97673bacd8ed22de46da4f69956c109c5d34cf9f9242605495ebd06dd02
data/Gemfile CHANGED
@@ -3,6 +3,8 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in ssm_config.gemspec
4
4
  gemspec
5
5
 
6
+ gem 'mysql2'
7
+
6
8
  group :development, :test do
7
9
  gem 'pry-byebug'
8
10
  gem 'rubocop', '~> 0.92', :require => false
data/README.md CHANGED
@@ -31,7 +31,7 @@ To utilize ActiveRecords, create the following model:
31
31
  rails generate model SsmConfigRecord file:string:index accessor_keys:string value:text datatype:string
32
32
  ```
33
33
 
34
- The supported datatypes are `[string, integer, boolean, float]`. The first character entered in the field `datatype` should be the character that corresponds to the first character of the datatype (so one of `[s, i, b, f]`). This field is not case-sensitive.
34
+ The supported datatypes are `[string, integer, boolean, float, erb]`. The first character entered in the field `datatype` should be the character that corresponds to the first character of the datatype (so one of `[s, i, b, f, e]`). This field is not case-sensitive. The type `erb` will store the `erb` expression in the database, and evaluate it on queries.
35
35
 
36
36
  Booleans should also be one of `[t, f]`, corresponding to `true` and `false`. Similarly, this is not case-sensitive and only the first character of the value entered (given the datatype is a boolean) will be checked.
37
37
 
@@ -51,11 +51,17 @@ module SsmConfig
51
51
 
52
52
  def determine_class(value)
53
53
  return 'boolean' if (value == false) || (value == true)
54
- return value.class
54
+ return 'erb' if (value[0..2] == '<%=') && (value[-2..-1] == '%>')
55
+ value.class
56
+ end
57
+
58
+ def file_path
59
+ Rails.root.join(SsmConfig::SsmStorage::Yml::CONFIG_PATH, "#{@file_name}.yml")
55
60
  end
56
61
 
57
62
  def hash
58
- SsmConfig::SsmStorage::Yml.new(@file_name).hash
63
+ yaml_loaded = YAML.load(File.read((file_path).to_s))
64
+ (yaml_loaded[Rails.env] || yaml_loaded['any']).try(:with_indifferent_access)
59
65
  end
60
66
  end
61
67
  end
@@ -3,7 +3,7 @@ module SsmConfig
3
3
  class Db
4
4
  TABLE_NAME = 'ssm_config_records'.freeze
5
5
  ACTIVE_RECORD_MODEL = 'SsmConfigRecord'.freeze
6
- VALID_DATATYPES = ['s', 'i', 'b', 'f'].freeze
6
+ VALID_DATATYPES = ['s', 'i', 'b', 'f', 'e'].freeze
7
7
  def initialize(file_name)
8
8
  @file_name = file_name
9
9
  end
@@ -11,7 +11,7 @@ module SsmConfig
11
11
  def table_exists?
12
12
  return active_record_model_exists? if active_record_exists? && constant_exists?
13
13
  false
14
- rescue ActiveRecord::NoDatabaseError
14
+ rescue ActiveRecord::NoDatabaseError, Mysql2::Error::ConnectionError
15
15
  return false
16
16
  end
17
17
 
@@ -42,11 +42,16 @@ module SsmConfig
42
42
  raise SsmConfig::InvalidBoolean, 'Not a valid boolean: must be one of true or false'
43
43
  end
44
44
 
45
+ def convert_erb(value)
46
+ ERB.new(value).result
47
+ end
48
+
45
49
  def transform_class(value, type)
46
50
  type_char = type.to_s.downcase[0]
47
51
  raise SsmConfig::UnsupportedDatatype, 'Not a valid class: must be one of string, integer, boolean, or float' unless VALID_DATATYPES.include? type_char
48
- return value.send("to_#{type_char}") unless type_char == 'b'
49
- convert_boolean(value)
52
+ return convert_boolean(value) if type_char == 'b'
53
+ return convert_erb(value) if type_char == 'e'
54
+ value.send("to_#{type_char}")
50
55
  end
51
56
 
52
57
  def add_flag_for_array_index(key)
data/lib/ssm_config.rb CHANGED
@@ -7,7 +7,7 @@ require 'active_support/core_ext/hash/indifferent_access'
7
7
  require 'active_support/time'
8
8
 
9
9
  module SsmConfig
10
- VERSION = '1.2.3'.freeze
10
+ VERSION = '1.3.1'.freeze
11
11
  REFRESH_TIME = (30.minutes).freeze
12
12
 
13
13
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssm_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Santiago Herrera
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-19 00:00:00.000000000 Z
11
+ date: 2023-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0'
148
148
  requirements: []
149
- rubygems_version: 3.0.9
149
+ rubygems_version: 3.2.3
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: YML file loader and parser for Rails