ssm_config 1.2.2 → 1.3.0

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: 4e0458ce594909bd0f384194296abe115310bede9765695232662a1996202842
4
- data.tar.gz: ddde6df256c8f06e2d95f45a254608efd9acf6ef244b6522fb7554c5e95d261d
3
+ metadata.gz: 8d835d981fcf137b46b213786f9e3e2a79a8dc31540ec4e810c3a7f16dfc7ccf
4
+ data.tar.gz: 471c9e8c29bfda709bd5ac812239291ccefa9d365bbb48e8fbbe3c942fd9afbe
5
5
  SHA512:
6
- metadata.gz: 80d9191173e45d77bf045e05e63f0ccf9b8208173757d95dca67d4dbd94c63ebd5e2890d9c46fbcad8ea5fd14c5010b667b9c9d9b82ca9e99382517a110609d2
7
- data.tar.gz: fef6162659dbf16f1d97cfdf7e62554fbd2d1a3e213945218e827433ab18801da89a3d588534ba04e3eb0175b690daf13c0c539bb6e21965e752fb8ec16a6fd4
6
+ metadata.gz: 5ae237e3d775ecc1892f64d39fc95d332cbd0bb15da1bdb6e65247f4bf4aa2d32b522c8ceea3067017eefff756d094ac6c62c1fd74ec83545c640cb259ef857d
7
+ data.tar.gz: 0f3f9b5258f7de1f61df1f50256525ff966e3f2d7fbae1781e8d469715e0ca9750d3bd8f5c4a30c0b0ef5cab6c3aa083520536445b9c6b1b622095d0aa9f76fd
data/README.md CHANGED
@@ -28,10 +28,10 @@ Or install it yourself as:
28
28
 
29
29
  To utilize ActiveRecords, create the following model:
30
30
  ```
31
- rails generate model SsmConfigRecord file:string:index accessor_keys:string value:string datatype:string
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,6 +11,8 @@ 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
15
+ return false
14
16
  end
15
17
 
16
18
  def hash
@@ -40,11 +42,16 @@ module SsmConfig
40
42
  raise SsmConfig::InvalidBoolean, 'Not a valid boolean: must be one of true or false'
41
43
  end
42
44
 
45
+ def convert_erb(value)
46
+ ERB.new(value).result
47
+ end
48
+
43
49
  def transform_class(value, type)
44
50
  type_char = type.to_s.downcase[0]
45
51
  raise SsmConfig::UnsupportedDatatype, 'Not a valid class: must be one of string, integer, boolean, or float' unless VALID_DATATYPES.include? type_char
46
- return value.send("to_#{type_char}") unless type_char == 'b'
47
- 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}")
48
55
  end
49
56
 
50
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.2'.freeze
10
+ VERSION = '1.3.0'.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.2
4
+ version: 1.3.0
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-21 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