static_models 0.2.1 → 0.3.0
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 +4 -4
- data/README.md +8 -4
- data/circle.yml +3 -0
- data/lib/static_models/version.rb +1 -1
- data/lib/static_models.rb +6 -8
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36852f849aa037a3e75ddd732e77a2f9eef48b74
|
4
|
+
data.tar.gz: d064389a9fe474c8237f3809ca08403784fb3f95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f92c0dcdcba6cd964a29e6bbf98de5cf7f196f9309e882a79871ff5aff2031af662302daba15629d66a35c727a3335cc94b33309a6b7c6771eb6b1fd3869b19
|
7
|
+
data.tar.gz: e384551d6fee147c63c2602627ad47027a07f31e99587a078f947c78ed4d5b80ea5a10dfc1a92e5d1731c997e911791b05f8a9eb6f4154048ece1126045a7e7c
|
data/README.md
CHANGED
@@ -127,14 +127,18 @@ Or install it yourself as:
|
|
127
127
|
|
128
128
|
## Development
|
129
129
|
|
130
|
-
|
131
|
-
|
132
|
-
|
130
|
+
```sh
|
131
|
+
$ bundle install
|
132
|
+
$ bundle exec rspec spec
|
133
|
+
```
|
133
134
|
|
134
135
|
## Contributing
|
135
136
|
|
136
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
137
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bitex-la/static_models.
|
138
|
+
|
139
|
+
## Code Status
|
137
140
|
|
141
|
+
[](https://circleci.com/gh/bitex-la/static_models)
|
138
142
|
|
139
143
|
## License
|
140
144
|
|
data/circle.yml
ADDED
data/lib/static_models.rb
CHANGED
@@ -76,19 +76,17 @@ module StaticModels
|
|
76
76
|
(opts[:class_name] || association.to_s.camelize)
|
77
77
|
end
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
klass = klass_name.constantize
|
79
|
+
klass = klass_name && klass_name.safe_constantize
|
82
80
|
|
83
|
-
if klass.include?(Model)
|
81
|
+
if klass && klass.include?(Model)
|
84
82
|
klass.find(send("#{association}_id"))
|
85
|
-
|
83
|
+
elsif defined?(super)
|
86
84
|
super()
|
87
85
|
end
|
88
86
|
end
|
89
87
|
|
90
88
|
define_method("#{association}=") do |value|
|
91
|
-
unless opts[:polymorphic]
|
89
|
+
unless opts[:polymorphic] || value.nil?
|
92
90
|
expected = [opts[:class_name], association.to_s.camelize].compact
|
93
91
|
got = value.class.name
|
94
92
|
unless expected.include?(got)
|
@@ -96,14 +94,14 @@ module StaticModels
|
|
96
94
|
end
|
97
95
|
end
|
98
96
|
|
99
|
-
if value.class.include?(Model)
|
97
|
+
if value.nil? || value.class.include?(Model)
|
100
98
|
if opts[:polymorphic]
|
101
99
|
# This next line resets the old polymorphic association
|
102
100
|
# if it was set to an ActiveRecord::Model. Otherwise
|
103
101
|
# ActiveRecord will get confused and ask for our StaticModel's
|
104
102
|
# table and a bunch of other things that don't apply.
|
105
103
|
super(nil) if defined?(super)
|
106
|
-
send("#{association}_type=", value.class.name )
|
104
|
+
send("#{association}_type=", value && value.class.name )
|
107
105
|
end
|
108
106
|
send("#{association}_id=", value && value.id)
|
109
107
|
else
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nubis
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- Rakefile
|
129
129
|
- bin/console
|
130
130
|
- bin/setup
|
131
|
+
- circle.yml
|
131
132
|
- lib/static_models.rb
|
132
133
|
- lib/static_models/version.rb
|
133
134
|
- static_models.gemspec
|