static_models 0.4.0 → 0.4.1

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
  SHA1:
3
- metadata.gz: 65dff81c399c94a47e52447d832acd3cff5922d7
4
- data.tar.gz: a736899f5666ee1281d50e29a457c1b6faca1547
3
+ metadata.gz: 3ef1da11476c36cfa1b806d8c078837de90a0421
4
+ data.tar.gz: f14b9af0d4b9e25c26e60d5f21710b97c905dbb3
5
5
  SHA512:
6
- metadata.gz: 0af88921adb55e963701874d2990d9bac7779202a40417e44847d3c60170bfd0a168e943e38469a4546e7f29566e7954a01688635d12da843430bb0025363cc1
7
- data.tar.gz: 2123b43bf3c3948948e2531a9434a6a789952aab7e39eb9270a04c9c569eb564d922c7f154b10adcff8dd13e0f23bd5d8c26e5fc7d745b836828036afab6267d
6
+ metadata.gz: d67bfd2ea2c4c35ecfa0755e21d27d629c346d5a938f91346a28b10d39e440888b4875a13f2cb0a06c913e5420f6d53e0849d2738e5d24997beebceb6e8738f6
7
+ data.tar.gz: a615411976c3426ff235d8112a64edd149d3250cee51ab18313935980fb04dc6f2d019a8a8b252abcfc40874f05f0bc936453b3e82536d9a41b5de03af254a88
@@ -7,15 +7,22 @@ module StaticModels
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  included do |i|
10
- cattr_accessor :values, :id_column, :code_column
10
+ cattr_accessor :values, :primary_key, :code_column
11
+ attr_accessor :attributes
11
12
 
12
13
  def initialize(attributes)
14
+ self.attributes = attributes
13
15
  attributes.each{|name,value| send("#{name}=", value) }
14
16
  end
15
17
 
16
18
  def name; send(self.class.code_column); end
17
19
  def to_s; name.to_s; end
18
- def to_i; send(self.class.id_column); end
20
+ def to_i; send(self.class.primary_key); end
21
+
22
+ # Ugly hack to make this compatible with AR validatinos.
23
+ # It's safe to assume a StaticModel is always valid and never destroyed.
24
+ def marked_for_destruction?; false; end
25
+ def valid?; true; end
19
26
  end
20
27
 
21
28
  class_methods do
@@ -58,7 +65,7 @@ module StaticModels
58
65
  end
59
66
 
60
67
  attr_accessor *columns
61
- self.id_column = columns[0]
68
+ self.primary_key = columns[0]
62
69
  self.code_column = columns[1]
63
70
 
64
71
  self.values = {}
@@ -1,3 +1,3 @@
1
1
  module StaticModels
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: static_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nubis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-26 00:00:00.000000000 Z
11
+ date: 2017-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport