ssm_config 1.2.3 → 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: 831eb6c691b037b55c991d51b7db74d2f65ce6aeb25ce1f72e4b8a58c09e86a7
4
- data.tar.gz: eb0016f6b7983d7c52e111e163077b12874f763f2afffb43509611b860b1aab8
3
+ metadata.gz: 8d835d981fcf137b46b213786f9e3e2a79a8dc31540ec4e810c3a7f16dfc7ccf
4
+ data.tar.gz: 471c9e8c29bfda709bd5ac812239291ccefa9d365bbb48e8fbbe3c942fd9afbe
5
5
  SHA512:
6
- metadata.gz: 689e51652b4cafe794bedda63be2697220f63f495ec879c46b5a6f95f8b489d3763648c83e9037e05044814efeaf0d1e1abdfa30fdad68e9ff633cc641c27202
7
- data.tar.gz: 3a17b84d245ca4f18017ec1709db431ec7c9cfacef94de4c14cd4ced15007fccf225849d368ed3ac613a9c7d236d7bb7333727dcc564f2dcc7409b258c7a599e
6
+ metadata.gz: 5ae237e3d775ecc1892f64d39fc95d332cbd0bb15da1bdb6e65247f4bf4aa2d32b522c8ceea3067017eefff756d094ac6c62c1fd74ec83545c640cb259ef857d
7
+ data.tar.gz: 0f3f9b5258f7de1f61df1f50256525ff966e3f2d7fbae1781e8d469715e0ca9750d3bd8f5c4a30c0b0ef5cab6c3aa083520536445b9c6b1b622095d0aa9f76fd
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
@@ -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.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.3
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