static_models 0.2.1 → 0.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
  SHA1:
3
- metadata.gz: 4d77b33fce2c3bb1b2547381dbc8a0fe08ec2dec
4
- data.tar.gz: 25049e39993a9ab70f4891b9bbe7ef338a4a4039
3
+ metadata.gz: 36852f849aa037a3e75ddd732e77a2f9eef48b74
4
+ data.tar.gz: d064389a9fe474c8237f3809ca08403784fb3f95
5
5
  SHA512:
6
- metadata.gz: f110800d4495af904267a5998496b3faa8eade6b086a709e6bdc4dde4ebc46dc2a3b8c89a7a429135decdb3c5e81cf599575e4df156a52e5f5179b79a6d54fb9
7
- data.tar.gz: 71378d6f04fe8c2c3be6b80b9f883906f6e1c0c3cc866cdaf9f4f68ceef677a8972984cf5740cbd5a02cf9e2823272e2c5c4cae32a8e1de555a423abad49be13
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
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
131
-
132
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/[USERNAME]/static_models.
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
+ [![Build Status](https://circleci.com/gh/bitex-la/static_models.png)](https://circleci.com/gh/bitex-la/static_models)
138
142
 
139
143
  ## License
140
144
 
data/circle.yml ADDED
@@ -0,0 +1,3 @@
1
+ database:
2
+ override:
3
+ - echo "no database"
@@ -1,3 +1,3 @@
1
1
  module StaticModels
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
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
- return nil unless Object.const_defined?(klass_name)
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
- else
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.2.1
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