egov_utils 0.1.23 → 0.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4a1277bc53acada48031d6bca281ce875e4f937b8e86ad3e05588ad7c2e3201
4
- data.tar.gz: 69e8697534f1b8398739b9578f337a294b4c07455c94e0c89505f9f511a804f6
3
+ metadata.gz: 18a523079b611c16cb2d396f77d105946a0f82359afc2bdf264c8eca9ead5b54
4
+ data.tar.gz: 83d00e43acb7ac7d1a1996214ebf417601085642629575c13bc5ce8a650fd183
5
5
  SHA512:
6
- metadata.gz: d34e4b723a3c007cf2eb5c4bbd494af079f5e520c72d8fd80ddd09b5431d78b088fbcea6ee6c73a87cfee0179a4ff8d7d945a3da31eeed3a63da96c0f01377bf
7
- data.tar.gz: 9aef7643e96b238fcee2a0d1ead31b43889c9f0e9ff261bcd69a26cf657e3ac3c6891a11b86df8fd252229e9ddec75ebe9fdf44a3a1271a65de38638bfc35e0b
6
+ metadata.gz: de2382de5425cb8f9399b933057b3bace3e2ded8cbf66c4f4a65b29ebdaf8c1582afbd72e6bc3feccb8a69abc512af21f68d2c7b2ba010a624b1e8a7e00a8bef
7
+ data.tar.gz: 69e22c0e7132b03f8fa34ceb14619bdbdd6419f8b13e7fb7a878a8d2dc95a7c947022db81b377b0f53079869e228b8965bffdc4f33210075a47cd14625c03558
@@ -116,12 +116,12 @@ module EgovUtils
116
116
 
117
117
  def ldap_groups
118
118
  if provider.present?
119
- group_ids = Rails.cache.read("#{cache_key}/ldap_group_ids", expires_in: 30.minutes)
119
+ group_ids = persisted? && Rails.cache.read("#{cache_key}/ldap_group_ids", expires_in: 30.minutes)
120
120
  if group_ids
121
121
  groups = EgovUtils::Group.where(id: group_ids).to_a
122
122
  else
123
123
  groups = EgovUtils::Group.where(provider: provider).to_a.select{|g| auth_source.member?(ldap_dn, g.external_uid) }
124
- Rails.cache.write("#{cache_key}/ldap_group_ids", groups.collect(&:id), expires_in: 30.minutes)
124
+ Rails.cache.write("#{cache_key}/ldap_group_ids", groups.collect(&:id), expires_in: 30.minutes) if persisted?
125
125
  end
126
126
  groups
127
127
  end
@@ -6,7 +6,6 @@ module BootstrapForm
6
6
  def fileuid_field(method, options={})
7
7
  form_group_builder(method, options) do
8
8
  prepend_and_append_input(options) do
9
- binding.pry
10
9
  @template.fileuid_field(@object_name, method, objectify_options(options))
11
10
  end
12
11
  end
@@ -89,13 +89,21 @@ module EgovUtils
89
89
  }
90
90
 
91
91
  # Used for `serialize` method in ActiveRecord
92
- class << self
93
- def dump(fileuid)
94
- unless obj.is_a?(self)
92
+ class Coder
93
+
94
+ def initialize(attr_name, type)
95
+ @attr_name = attr_name
96
+ @type = type
97
+ end
98
+
99
+ def dump(obj)
100
+ return if obj.nil?
101
+ obj = Fileuid.new(obj, type: @type) if obj.is_a?(String)
102
+ unless obj.is_a?(Fileuid)
95
103
  raise ::ActiveRecord::SerializationTypeMismatch,
96
104
  "Attribute was supposed to be a #{self}, but was a #{obj.class}. -- #{obj.inspect}"
97
105
  end
98
- fileuid.invalid? ? nil : to_s
106
+ obj.invalid? ? nil : obj.to_s
99
107
  end
100
108
 
101
109
  def load(source)
@@ -103,8 +111,13 @@ module EgovUtils
103
111
  end
104
112
  end
105
113
 
106
- attr_accessor :bc, :agenda, :senat, :year, :document_number
114
+ AVAILABLE_ATTRIBUTES = [:bc, :agenda, :senat, :year, :document_number]
107
115
 
116
+ attr_accessor *AVAILABLE_ATTRIBUTES
117
+
118
+ def ==(other)
119
+ other.is_a?(Fileuid) && AVAILABLE_ATTRIBUTES.all?{|a| self.public_send(a) == other.public_send(a) }
120
+ end
108
121
 
109
122
  def type
110
123
  @type ||= @options['type']
@@ -115,18 +128,18 @@ module EgovUtils
115
128
  end
116
129
 
117
130
  def invalid?
118
- @invalid
131
+ !type || @invalid
119
132
  end
120
133
 
121
134
  def initialize(str_val, **options)
122
135
  @options = options.stringify_keys
136
+ @str_val = str_val
123
137
  parse_str!(str_val) if str_val.is_a?(String)
124
138
  end
125
139
 
126
140
  def parse_str!(str_val, type=self.type)
127
141
  type ||= determine_type(str_val)
128
142
  @type = type
129
- @invalid = true unless type
130
143
  return if invalid?
131
144
  match_data = str_val.match(type_definition.to_regex)
132
145
  if match_data
@@ -140,7 +153,7 @@ module EgovUtils
140
153
  TYPES.each do |k, type|
141
154
  return k if str_val =~ type.to_regex
142
155
  end
143
- @invalid = true
156
+ nil
144
157
  end
145
158
 
146
159
  def as_json(**options)
@@ -1,3 +1,3 @@
1
1
  module EgovUtils
2
- VERSION = '0.1.23'
2
+ VERSION = '0.1.26'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egov_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.23
4
+ version: 0.1.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondřej Ezr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-07 00:00:00.000000000 Z
11
+ date: 2017-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails