static_models 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/static_models/version.rb +1 -1
- data/lib/static_models.rb +11 -13
- data/static_models.gemspec +1 -0
- metadata +21 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14b52ac6a5f6d2ea3a9cd809e96dc9a5d3a9bd84
|
4
|
+
data.tar.gz: 0fe26ca5989a19dbdf39805a156e4dd4a16509dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d2a70e05c48350c0a4c48b3924403a511358dab5f09c9fd9bd71a2cfe84835c938b09324ac06cdf4610c11878e4218cb49848bb29311220f3bd8148d982ec27
|
7
|
+
data.tar.gz: 0559dd452091ec6fd0954d10eb81d70a1450a2ce9e2efd4baf0f8b78890dacb90ad6e536ada21cadbcce89db90b6f1c4b5f7aded2ac559e71572158f8141607b
|
data/lib/static_models.rb
CHANGED
@@ -69,14 +69,16 @@ module StaticModels
|
|
69
69
|
def belongs_to(association, opts = {})
|
70
70
|
super(association, opts) if defined?(super)
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
72
|
+
expected_class = unless opts[:polymorphic]
|
73
|
+
module_name = self.class.to_s.split("::")[0..-2].join("::")
|
74
|
+
[ opts[:class_name],
|
75
|
+
"#{module_name}::#{association.to_s.camelize}",
|
76
|
+
association.to_s.camelize,
|
77
|
+
].compact.collect(&:safe_constantize).compact.first
|
78
|
+
end
|
78
79
|
|
79
|
-
|
80
|
+
define_method("#{association}") do
|
81
|
+
klass = expected_class || send("#{association}_type").to_s.safe_constantize
|
80
82
|
|
81
83
|
if klass && klass.include?(Model)
|
82
84
|
klass.find(send("#{association}_id"))
|
@@ -86,12 +88,8 @@ module StaticModels
|
|
86
88
|
end
|
87
89
|
|
88
90
|
define_method("#{association}=") do |value|
|
89
|
-
|
90
|
-
|
91
|
-
got = value.class.name
|
92
|
-
unless expected.include?(got)
|
93
|
-
raise TypeError.new("Expected #{expected.first} got #{got}")
|
94
|
-
end
|
91
|
+
if expected_class && !value.nil? && value.class != expected_class
|
92
|
+
raise TypeError.new("Expected #{expected_class} got #{value.class}")
|
95
93
|
end
|
96
94
|
|
97
95
|
if value.nil? || value.class.include?(Model)
|
data/static_models.gemspec
CHANGED
@@ -31,4 +31,5 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
32
32
|
spec.add_development_dependency "activerecord", '~> 4.2', '>= 4.2.0'
|
33
33
|
spec.add_development_dependency "sqlite3", "~> 1.0", ">= 1.0.0"
|
34
|
+
spec.add_development_dependency "byebug", "~> 1.0", ">= 1.0.0"
|
34
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: static_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nubis
|
@@ -112,6 +112,26 @@ dependencies:
|
|
112
112
|
- - ">="
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: 1.0.0
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: byebug
|
117
|
+
requirement: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - "~>"
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '1.0'
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.0.0
|
125
|
+
type: :development
|
126
|
+
prerelease: false
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.0'
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 1.0.0
|
115
135
|
description: "\n Replace your key/value classes with this.\n Define classes
|
116
136
|
with several 'singleton' instances.\n "
|
117
137
|
email:
|