DataMapper plugin providing many extra types for use in data models.
datamapper / dm-types Goto Github PK
View Code? Open in Web Editor NEWDataMapper plugin providing extra data types
Home Page: http://datamapper.org/
License: MIT License
DataMapper plugin providing extra data types
Home Page: http://datamapper.org/
License: MIT License
DataMapper::Types::Flag caches values assigned/appended with the left shift <<
operator, but fails to persist them on save().
I've created a gist to illustrate the problem.
I might also add that finders like Model.all(:flagprop => [:one, :two])
do not behave as (I) expected, but I really have no idea how they are supposed to work.
See also:
#1128
Created by Austin Bales (at 417east) - 2009-12-21 05:26:02 UTC
Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1161
Update the 'bcrypt-ruby' gem requirement to just 'bcrypt', as the gems name has been changed and requiring the former results in an informational messages being displayed.
class Car
include DataMapper::Resource
has n, :wheels
property :id, Serial
property :deleted, ParanoidBoolean, :default => false, :lazy => false
end
If :lazy is set to true, Wheel.car will return nil even if a record exists (it even queries the DB successfully).
See https://gist.github.com/1511964 for a fuller use-case
Appreciate any insight into what is causing this: the stdlib Pathname seems to be loaded and the stdlib docs makes no mention of a /
method:
undefined method `/' for #<Pathname:0x0000000263f6f8> (NoMethodError)
/home/hedge/.rvm/gems/ruby-1.9.2-p136@bbb_vm_monitor/gems/dm-types-0.10.0/lib/dm-types.rb:5:in `<module:Types>'
/home/hedge/.rvm/gems/ruby-1.9.2-p136@bbb_vm_monitor/gems/dm-types-0.10.0/lib/dm-types.rb:4:in `<module:DataMapper>'
/home/hedge/.rvm/gems/ruby-1.9.2-p136@bbb_vm_monitor/gems/dm-types-0.10.0/lib/dm-types.rb:3:in `<top (required)>'
/home/hedge/.rvm/gems/ruby-1.9.2-p136@bbb_vm_monitor/gems/data_mapper-0.9.2/lib/data_mapper.rb:7:in `require'
/home/hedge/.rvm/gems/ruby-1.9.2-p136@bbb_vm_monitor/gems/data_mapper-0.9.2/lib/data_mapper.rb:7:in `block in <top (required)>'
/home/hedge/.rvm/gems/ruby-1.9.2-p136@bbb_vm_monitor/gems/data_mapper-0.9.2/lib/data_mapper.rb:5:in `each'
/home/hedge/.rvm/gems/ruby-1.9.2-p136@bbb_vm_monitor/gems/data_mapper-0.9.2/lib/data_mapper.rb:5:in `<top (required)>'
/home/hedge/.rvm/gems/ruby-1.9.2-p136@global/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `require'
/home/hedge/.rvm/gems/ruby-1.9.2-p136@global/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/home/hedge/.rvm/gems/ruby-1.9.2-p136@global/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `each'
/home/hedge/.rvm/gems/ruby-1.9.2-p136@global/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `block in require'
/home/hedge/.rvm/gems/ruby-1.9.2-p136@global/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `each'
/home/hedge/.rvm/gems/ruby-1.9.2-p136@global/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `require'
/home/hedge/.rvm/gems/ruby-1.9.2-p136@global/gems/bundler-1.0.10/lib/bundler.rb:120:in `require'
/usr/src/bigbluebutton/labs/vm/development/features/monitor/config/boot.rb:10:in `<top (required)>'
/home/hedge/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/home/hedge/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/usr/src/bigbluebutton/labs/vm/development/features/monitor/features/support/env.rb:2:in `<top (required)>'
I have 6 month experience in rails but first experience with datamapper rails.there is incompatibilities of datamapper with rails.Please point out which latest version of datamapper is compatible with latest rails version.
Thank you.
This may be a problem for some, but I guess we shouldn't be using UUID type anyway. But, if you get an error from dm-do-adapter or dm-postgres-adapter dm-do-adapter.rb:201:in
property_schema_hash': undefined method merge' for nil:NilClass
it's because of a custom type in dm-types.
For me it happened for a UUID property, but was fine for Enum
. :shrugs:
Hi,
Could you please update the dependencies to allow dm-types and dm-serializer to work with the 1.6.x version of the JSON gem?
Thanks,
Steve
When using an enum as part of a CPK, you cannot destroy the record. Observe:
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
require 'dm-types'
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'postgres://localhost/test') # createdb test
class User
include DataMapper::Resource
property :id, Serial
has n, :posts
end
class Post
include DataMapper::Resource
property :id, Serial, :key => true
property :type, Enum[:a, :b], :key => true
property :title, String
belongs_to :user
end
DataMapper.finalize
DataMapper.auto_migrate!
user = User.create(:posts => [{:type => :a, :title => "Post A"}, {:type => :b, :title => "Post B"}])
user.reload
post = user.posts.first
puts post.destroy # => true
puts Post.all.map(&:title) # ...but record is not destroyed!
There is a dodgy work around, but it doesn't run any callbacks:
Post.all(:user_id => post.user_id, :type => post.type).destroy!
Created by Xavier Shay - 2011-01-18 04:43:40 UTC
Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1478
When one is using a flag field, they should be able to search for records that have a specific flag set. This can be done with a bitwise "and" query, using the ampersand operator.
I don't know what the correct way to do this is, but a method that works for me is defining a new Comparison, as such: http://pastebin.com/xWU62iT2
That way one can do a search like this:
User.all('role.hasflag' => :moderator)
and it will match users with that AND other roles, not just the specific combination
A new release of datamapper is probably needed. dm-types depends on bcrypt-ruby ~> 2.1.4, whereas activemodel on which both actionpack and activerecord (and thus rails) depend, has a dependency on bcrypt-ruby ~> 3.0.0. This prevents dm from even bundling on Rails 3.1.
I would submit a pull request for fixing this dependency, but I can't get the datamapper tests to run, so it doesn't really feel worthwhile.
When I am using YAML data type in data_mapper some operations on Arrays and Hashes are not seen by data mapper and not saved into database.
Workaround is to use only assign function on Arrays and Hashes saved to database as YAML.
Script showing problem:
require 'rubygems'
require 'dm-core'
require 'dm-types'
An in-memory Sqlite3 connection:
DataMapper.setup(:default, 'sqlite3::memory:')
class Category
include DataMapper::Resource
property :id, Serial
property :name, String
property :links, DataMapper::Types::Yaml
end
DataMapper.auto_migrate!
DataMapper::Logger.new(STDOUT, :debug)
print "Creating new category..."
c = Category.new
puts "[OK]"
c.name = 'Empty'
c.links = []
c.save
puts "New category links look like #{c.links.to_yaml}"
empty_id = c.id
c.links << {:a=>12}
c.save
puts "Changed category links set to look like #{c.links.to_yaml}"
puts "After rereading category links look like #{Category.get(empty_id).links.to_yaml}"
if Category.get(empty_id).links.size == 0 then
puts "There is problem"
else
puts "Everything is fine"
end
Problem appeared both in trunk and in current gem from repository.
Created by gondar - 2009-09-25 13:13:45 UTC
Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1061
Hi @dkubb! Via twitter, @solnic suggested I write to you about whether you'd accept a PR to the 1.2 release branch of dm-types to upgrade the version of safe_yaml
in use. Would you?
It looks like in the master branch of dm_types, safe_yaml is no longer explicitly specified in the gemfile. Not sure why offhand.
I'm really only concerned with the 1.2 release branch, however, and am trying to see if we can resolve the dependency problems between DM and RailsAdmin, which includes a dependency which itself includes the latest safe_yaml
I discovered that the IPAddress property will attempt to typecast the values used in .like
queries, which results in an ArgumentError
being raised by IPAddr.new
.
User.all(:sign_in_ip.like => '%192.168.%')
/home/hal/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/ipaddr.rb:496:in `rescue in initialize': invalid address (ArgumentError)
from /home/hal/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/ipaddr.rb:493:in `initialize'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-types-08966f30a9e1/lib/dm-types/ip_address.rb:16:in `new'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-types-08966f30a9e1/lib/dm-types/ip_address.rb:16:in `load'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-types-08966f30a9e1/lib/dm-types/ip_address.rb:30:in `typecast'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query/conditions/comparison.rb:320:in `typecast_property'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query/conditions/comparison.rb:315:in `typecast'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query/conditions/comparison.rb:291:in `initialize'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query/conditions/comparison.rb:60:in `new'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query/conditions/comparison.rb:60:in `new'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1182:in `append_property_condition'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1148:in `append_condition'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1213:in `append_string_condition'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1150:in `append_condition'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1193:in `append_symbol_condition'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1149:in `append_condition'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1219:in `append_operator_conditions'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1151:in `append_condition'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1020:in `block (2 levels) in merge_conditions'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1020:in `each'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1020:in `block in merge_conditions'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1014:in `each'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1014:in `merge_conditions'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:370:in `update'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:386:in `merge'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/model.rb:767:in `scoped_query'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/model.rb:342:in `all'
Reproduction: https://github.com/postmodern/dm-bug-report/tree/ip_address_typecast
Reproduced on 1.1.0, 1.2.0 and Edge.
The bug here is that with an empty string, URI type always returns an instance of Addressable::URI. So when doing a validation checking for #blank? it returns false. This is a problem when the property is being set from form params.
If you create a Resolv::DNS
object to query a specific nameserver, it will return Resolv::IPv4
/ Resolv::IPv6
objects instead of Strings. The IPAddress Property does not typecast these objects.
Setting a property with type String
forces a limit on the length. It defaults to 50, and there is no way to un-set it.
property :name, String, :length => nil
# +options[:length]+ should be Range or Integer, but was NilClass (ArgumentError)
property :name, String, :length => n
# options[:length]+ should be Range or Integer, but was Float (ArgumentError)
Yes, I could used Text, :lazy => false
, but thats convoluted. Postgres has no limit on the length of VARCHAR columns, and MySQL has a 64K limit, but requires that a limit be specified. SQLite3 has no limit, even if one is specified. Several other adapters have no limit on a string-ish attribute.
My suggestion would be to remove the default 50-char limit from String properties, and have no default limit. The MySQL adapter can then pick a special default, since it is the only one that needs it.
Created by Paul Sadauskas (Rando) - 2009-05-14 21:51:04 UTC
Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/850
It would be nice to have a more precise EpochTime type. I'm a Ruby newbie, but this seems to work for me;
class EpochFloatTime < Float
def load(value)
case value
when ::Float, ::Integer
::Time.at(value)
else value
end
end
def dump(value)
case value
when ::Float, ::Integer, ::Time then value.to_f
when ::DateTime then value.to_time.to_f
end
end
end
I accidentally closed this, so I resubmitted at
https://github.com/datamapper/dm-types/issues#issue/15
I have the class below
class User
include DataMapper::Resource
property :id, Serial
property :display, Enum[ :first, :last, :first_last, :last_first ]
end
When I try and run rake db:autoupgrade I get the following error message: uninitialized constant User::Enum
Below is the trace from rake:
** Invoke db:autoupgrade (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
uninitialized constant User::Enum
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/dm-core-1.2.0/lib/dm-core/model.rb:728:in const_missing' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/dm-core-1.2.0/lib/dm-core/property/lookup.rb:25:in
const_missing'
/Users/Jon/addtoit/app/models/user.rb:7:in <class:User>' /Users/Jon/addtoit/app/models/user.rb:1:in
<top (required)>'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/dm-rails-1.2.1/lib/dm-rails/setup.rb:60:in block (2 levels) in preload_models' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/dm-rails-1.2.1/lib/dm-rails/setup.rb:60:in
each'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/dm-rails-1.2.1/lib/dm-rails/setup.rb:60:in block in preload_models' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/dm-rails-1.2.1/lib/dm-rails/setup.rb:59:in
each'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/dm-rails-1.2.1/lib/dm-rails/setup.rb:59:in preload_models' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/dm-rails-1.2.1/lib/dm-rails/railtie.rb:80:in
block (2 levels) in class:Railtie'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:418:in _run__2565405975579041820__prepare__1633098324659922499__callbacks' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:405:in
__run_callback'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:385:in _run_prepare_callbacks' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:81:in
run_callbacks'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/actionpack-3.2.3/lib/action_dispatch/middleware/reloader.rb:74:in prepare!' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/actionpack-3.2.3/lib/action_dispatch/middleware/reloader.rb:48:in
prepare!'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/railties-3.2.3/lib/rails/application/finisher.rb:47:in block in <module:Finisher>' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/railties-3.2.3/lib/rails/initializable.rb:30:in
instance_exec'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/railties-3.2.3/lib/rails/initializable.rb:30:in run' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/railties-3.2.3/lib/rails/initializable.rb:55:in
block in run_initializers'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/railties-3.2.3/lib/rails/initializable.rb:54:in each' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/railties-3.2.3/lib/rails/initializable.rb:54:in
run_initializers'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/railties-3.2.3/lib/rails/application.rb:136:in initialize!' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in
method_missing'
/Users/Jon/addtoit/config/environment.rb:5:in <top (required)>' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/railties-3.2.3/lib/rails/application.rb:103:in
require'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/railties-3.2.3/lib/rails/application.rb:103:in require_environment!' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/railties-3.2.3/lib/rails/application.rb:292:in
block (2 levels) in initialize_tasks'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/task.rb:205:in call' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/task.rb:205:in
block in execute'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/task.rb:200:in each' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/task.rb:200:in
execute'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/task.rb:158:in block in invoke_with_call_chain' /Users/Jon/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in
mon_synchronize'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/task.rb:151:in invoke_with_call_chain' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/task.rb:176:in
block in invoke_prerequisites'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/task.rb:174:in each' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/task.rb:174:in
invoke_prerequisites'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/task.rb:157:in block in invoke_with_call_chain' /Users/Jon/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in
mon_synchronize'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/task.rb:151:in invoke_with_call_chain' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/task.rb:144:in
invoke'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/application.rb:116:in invoke_task' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/application.rb:94:in
block (2 levels) in top_level'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/application.rb:94:in each' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/application.rb:94:in
block in top_level'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/application.rb:133:in standard_exception_handling' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/application.rb:88:in
top_level'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/application.rb:66:in block in run' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/application.rb:133:in
standard_exception_handling'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/lib/rake/application.rb:63:in run' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/gems/rake-0.9.2.2/bin/rake:33:in
<top (required)>'
/Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/bin/rake:19:in load' /Users/Jon/.rvm/gems/ruby-1.9.3-p125@rails32/bin/rake:19:in
I'm using rails 3.2.3, if any more information is needed let me know.
length refers to the encrypted string and not the input string. so setting a property to :lenght => 3..200 will not work because the brcypt string, whatever the input string was, will succeed.
What are the steps to get this working? I ran bundle install and all seemed well when the dm-core version was bumped to >= 1.2.1. However I keep getting the following error on running specs.
Users/nem/.rvm/gems/jruby-1.7.4@dm-types/gems/rspec-1.3.2/lib/spec/runner/options.rb:188: Use RbConfig instead of obsolete and deprecated Config.
NameError: uninitialized constant DataMapper::Property::BCryptHash::PassThroughLoadDump
const_missing at org/jruby/RubyModule.java:2631
BCryptHash at /Users/nem/Development/MyStuff/git/ruby/dm-types/lib/dm-types/bcrypt_hash.rb:7
Property at /Users/nem/Development/MyStuff/git/ruby/dm-types/lib/dm-types/bcrypt_hash.rb:6
DataMapper at /Users/nem/Development/MyStuff/git/ruby/dm-types/lib/dm-types/bcrypt_hash.rb:5
(root) at /Users/nem/Development/MyStuff/git/ruby/dm-types/lib/dm-types/bcrypt_hash.rb:4
const_get at org/jruby/RubyModule.java:2546
(root) at /Users/nem/.rvm/gems/jruby-1.7.4@dm-types/bundler/gems/dm-core-efa363cd9bf1/lib/dm-core/property.rb:1
find_class at /Users/nem/.rvm/gems/jruby-1.7.4@dm-types/bundler/gems/dm-core-efa363cd9bf1/lib/dm-core/property.rb:365
const_missing at /Users/nem/.rvm/gems/jruby-1.7.4@dm-types/bundler/gems/dm-core-efa363cd9bf1/lib/dm-core/property/lookup.rb:22
Person at /Users/nem/Development/MyStuff/git/ruby/dm-types/spec/fixtures/person.rb:22
TypesFixtures at /Users/nem/Development/MyStuff/git/ruby/dm-types/spec/fixtures/person.rb:3
DataMapper at /Users/nem/Development/MyStuff/git/ruby/dm-types/spec/fixtures/person.rb:2
require at org/jruby/RubyKernel.java:1054
require_with_backports at /Users/nem/.rvm/gems/jruby-1.7.4@dm-types/gems/backports-3.3.3/lib/backports/tools.rb:328
(root) at /Users/nem/Development/MyStuff/git/ruby/dm-types/spec/fixtures/person.rb:1
(root) at /Users/nem/Development/MyStuff/git/ruby/dm-types/spec/integration/bcrypt_hash_spec.rb:1
(root) at /Users/nem/Development/MyStuff/git/ruby/dm-types/spec/integration/bcrypt_hash_spec.rb:5
load at org/jruby/RubyKernel.java:1073
try_spec at /Users/nem/Development/MyStuff/git/ruby/dm-types/spec/spec_helper.rb:22
each at org/jruby/RubyArray.java:1617
(root) at /Users/nem/Development/MyStuff/git/ruby/dm-types/spec/integration/bcrypt_hash_spec.rb:3
(root) at /Users/nem/.rvm/gems/jruby-1.7.4@dm-types/gems/rspec-1.3.2/lib/spec/runner/example_group_runner.rb:1
load_files at /Users/nem/.rvm/gems/jruby-1.7.4@dm-types/gems/rspec-1.3.2/lib/spec/runner/example_group_runner.rb:15
load_files at /Users/nem/.rvm/gems/jruby-1.7.4@dm-types/gems/rspec-1.3.2/lib/spec/runner/example_group_runner.rb:14
load at org/jruby/RubyKernel.java:1073
run_examples at /Users/nem/.rvm/gems/jruby-1.7.4@dm-types/gems/rspec-1.3.2/lib/spec/runner/options.rb:134
eval at org/jruby/RubyKernel.java:1093
(root) at /Users/nem/.rvm/gems/jruby-1.7.4@dm-types/bin/ruby_noexec_wrapper:14
For example:
in Class A
belongs_to :b
in class B
property :c, Enum[:one, :two]
In irb if I do:
a = A.new(:b => B.new(:c => :one))
a.b.c
=> nil
dm-timestamps sets :created_at
to DateTime.now
(logical). EpochTime
then converts that DateTime
to UTC offset zero, thus completely breaking DST. Here's a failing spec to give you an example ;) I haven't looked into a fix yet.
We all know Discriminator type, but what I wish it to support is some kind of demodulize functionality, let's say:
property :type, Discriminator, :demodulize => true
Normally Discriminator type generate this insert for the code presented in the footer:
INSERT INTO "very_long_module1_very_long_module2_as" ("type") VALUES ('VeryLongModule1::VeryLongModule2::A::A1')
with :demodulize => true options it would be:
INSERT INTO "very_long_module1_very_long_module2_as" ("type") VALUES ('A1')
When you use inheritance in the way I presented below (ie. nested classes), the module A will see and recognize A1 and A2 class, even if you don't prefixe them by "VeryLongModule1::VeryLongModule2::A". I know it could be a problem if you inherit from A class in different Object spaces, in this cases Discriminator needs full path to find them, but it depends on programmer to use it right.
require 'rubygems'
require 'dm-core'
require 'dm-types'
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, 'sqlite3::memory:')
module VeryLongModule1
module VeryLongModule2
class A
include DataMapper::Resource
property :id, Serial
property :type, Discriminator # :demodulize => true
class A1 < self
end
class A2 < self
end
end
DataMapper.auto_migrate!
A::A1.new.save
end
end
Here is a pull request for a path that will open possibility to create custom discriminator types
http://github.com/dmgr/dm-core/commit/58017d02987e9fdbae23750c3ab1079f47b3e5c5
Created by Dawid Marcin Grzesiak - 2010-03-27 09:00:06 UTC
Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1226
v1.2.2...master says it should include the code from PR #50. Unfortunately, the released gem on rubygems does not appear to have this code included in the dirty_minder.rb
. Can a v1.2.3 be release to fix the rubygem?
Hi!
Got this error when using dm on jruby with UUID field type:
ERROR: column "c$uuid" is of type uuid but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
Position: 88 (code: 0, sql state: 42804, query: INSERT INTO "t$gp_events" ("c$uuid", "c$number", "c$s", "c$tx", "c$ac", "c$d") VALUES ('48cfcb78-5883-4d58-b81c-b4d2e6dd304b', '100487', '1.0', '1000000041342594267', '68473', '2012-04-23 16:03:14.000000 +04:00:00'), uri: )
my model:
class Events
include DataMapper::Resource
storage_names[:default] = 't$gp_events'
property :uuid, UUID, :field => 'c$uuid', :key => true
property :number, Integer, :field => 'c$number'
property :s, Float, :field => 'c$s'
property :tx, Integer, :field => 'c$tx'
property :ac, Integer, :field => 'c$ac'
property :d, DateTime, :field => 'c$d'
end
everything fine on MRI
dm-types/csv.rb
redefines the global CSV
constant to be an alias to FasterCSV
when running under Ruby 1.8. While I understand the desire to keep the remainder of the code the same under 1.8 and 1.9, this causes a problem: if the built-in CSV library is required after dm-types/csv.rb
(e.g., by another library) you get a superclass mismatch for class Row
error.
An alternative: define a method on that returns the appropriate module to use (CSV or FasterCSV) depending on the ruby version.
dm-serializer has a similar bug (datamapper/dm-serializer#25). The bug in dm-types is less serious since dm-types/csv.rb
is only required if you actually use the Csv
type, but it is still a potential issue.
currently I am using version 1.2.0 which brings multi_json ~>1.0.3 to the dependency hull. now when I want to use something more recent (which includes Oj ) I need to monkey patch and copy+paste and still not sure if i missed some tiny details. somehow I just miss to "overrule" dependency constraints (because I know that 1.6.x is backward compatible to 1.0.x). bundler does not offer such feature. BUT with a more relax semantic version constraint like multi_json ~>1.0 I do have the chance to "overrule" things in case they are not backward compatible - something like multi_json >1.5
even if I know that dm-1.3.0 will not become true but being more relax with version constraints is maybe something considering for dm-2 ;)
I'm using dm-types in conjunction with cucumber for testing.
Actually, I have to use a old cucumber version, because they switched to json (aslak said "Nobody should use json_pure anymore." -
https://github.com/aslakhellesoy/cucumber/commit/60a1d2a55d56b645287cc39316722abe32df31ad )
I tried to change the Gemfile myself in a fork, but I didn't get the testsetup running :(
Thanks,
keep up the good work!
Or is previous version needed for any reason?
stringex 2.0 add an adapter for datamapper for the act_as_url library, so it is very important to be compatible.
Could you please also adjust gemspec and Rakefile to use json instead of json_pure?
Thanks a lot!
The latest release of this gem depends on the 1.x series of the json
gem. That means that dm-types
cannot be used on ruby 2.4, because support for ruby 2.4 was added in the 2.0 release of json
. Please update the dependency so that it would be possible to use this gem on ruby 2.4.
In http://rubygems.org/gems/dm-types
Runtime Dependencies
We're upgrading the FreeBSD ports tree, but it seems dm-types(datamapper) need exact dependency versions, can't it relax to => ?
Calling empty?
on an has n
association. Ruby 2.2.0, worked previous versions of ruby.
from bundle/ruby/2.2.0/gems/dm-types-1.2.2/lib/dm-types/support/dirty_minder.rb:144:in `track'
from bundle/ruby/2.2.0/gems/dm-types-1.2.2/lib/dm-types/support/dirty_minder.rb:161:in `hook_value'
from bundle/ruby/2.2.0/gems/dm-types-1.2.2/lib/dm-types/support/dirty_minder.rb:151:in `set!'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/model.rb:607:in `block (2 levels) in load'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/model.rb:598:in `each'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/model.rb:598:in `block in load'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/model.rb:577:in `map'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/model.rb:577:in `load'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/repository.rb:162:in `read'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/collection.rb:1118:in `lazy_load'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/support/lazy_array.rb:87:in `empty?'
from (irb):2
from bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'
from bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'
from bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'
from bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'irb(main):003:0> r.extract_logs.empty?
Hi,
Could you loosen the version requirements to work with bcrypt-ruby 3.0.0 or greater? Since bcrypt-ruby3.0.1 is out this would make packaging dm-types 1.2.0 for FreeBSD possible.
Steve
rails 3.1.0 has a dependency on bcrypt as ~>3.0.0 while dm-types has a hardcoded dependency on 2.1.4, this causes a conflict. kthxbye
A pattern I frequently use in an internal application is a Json field tweaked so that it stores/retrieves Mash
es (mainly when storing complex configuration that we don't want to codify into a table)
Is this something that would fit into dm-types? (I'm willing to write a patch, or an extra gem if it doesn't fit)
I'm going to suggest that assigning an arbitrary string to a Json field should result in a validation error rather than an exception.
I have a class defined as follows:
class Mymodel
include DataMapper::Resource
property :id, Serial
property :jsonfield, Json
end
Assigning a hash or an array to jsonfield works as expected. The hash or array is properly json-ized in the data store, and when I read the field back, I get a hash/array that's identical to the original.
2.0.0p247 :001 > a = Mymodel.new
=> #<Mymodel @id=nil @jsonfield=nil>
2.0.0p247 :002 > a.jsonfield = ["Nancy", "Mary", "Phil"]
=> ["Nancy", "Mary", "Phil"]
2.0.0p247 :003 > a.jsonfield
=> ["Nancy", "Mary", "Phil"]
2.0.0p247 :004 >
Assigning a string to jsonfield causes the parser to interpret the string as a json-encoded hash or array. When I read the field back, I get the hash or array instead of the string representation.
2.0.0p247 :004 > a.jsonfield = '["Nancy", "Mary", "Phil"]'
=> "[\"Nancy\", \"Mary\", \"Phil\"]"
2.0.0p247 :005 > a.jsonfield
=> ["Nancy", "Mary", "Phil"]
2.0.0p247 :006 >
Assigning a string that is not a valid json representation of a hash or array raises an exception.
2.0.0p247 :006 > a.jsonfield = "Nancy"
MultiJson::LoadError: 795: unexpected token at 'Nancy'
...
I would expect this last case to result in a validation error, not an exception.
For comparison, no exception is raised when I assign "Nancy" to id. It simply won't validate.
2.0.0p247 :007 > a.id = "Nancy"
=> "Nancy"
2.0.0p247 :008 > a.valid?
=> false
2.0.0p247 :009 > a.errors[:id]
=> ["Id must be an integer"]
2.0.0p247 :010 >
It looks like something about the new properties broke paranoid properties with inheritance
irb(main):008:0> class A
irb(main):009:1> include DataMapper::Resource
irb(main):010:1> property :deleted, ParanoidBoolean
irb(main):011:1> end
=> #<DataMapper::Property::ParanoidBoolean @model=A @name=:deleted>
irb(main):012:0> class B < A
irb(main):013:1> end
=> nil
irb(main):014:0> A.paranoid_properties
=> {:deleted=>#<Proc:0x653cca0e@/.../dm-types/paranoid_boolean.rb:22>}
irb(main):015:0> B.paranoid_properties
=> nil
Tried this in both MRI 1.8.7 and jRuby 1.6.0
Note: Sorry for the dupe. I accidentally closed the previous issue.
Greetings
I'm having some issues with the use of Enum as a type. I declare it in the model like this:
class Bong
property :label, Enum[:a, :b, :c]
end
After that I create an instance:
a = Bong.create(:label => :a)
a.label #=> :a
a.label = :b
a.label #=> :b
a.id #=> 1
But later, as I fetch it, I get the strangest behaviour:
a = Bong.get(1)
a.label #=> nil
can you tell me why this happens?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.