maccman / supermodel Goto Github PK
View Code? Open in Web Editor NEWRuby in-memory models
License: MIT License
Ruby in-memory models
License: MIT License
Simple in-memory database using ActiveModel. Primarily developed for Bowline applications. http://github.com/maccman/bowline Supports: * Serialisation * Validations * Callbacks * Observers * Dirty (Changes) * Ruby Marshalling to disk * Redis Examples: require "supermodel" class Test < SuperModel::Base end t = Test.new t.name = "foo" t.save #=> true Test.all Test.first Test.last Test.find_by_name('foo) You can use a random ID rather than the object ID: class Test < SuperModel::Base include SuperModel::RandomID end t = Test.create(:name => "test") t.id #=> "7ee935377bb4aecc54ad4f9126" You can marshal objects to disk on startup/shutdown class Test < SuperModel::Base include SuperModel::Marshal::Model end SuperModel::Marshal.path = "dump.db" SuperModel::Marshal.load at_exit { SuperModel::Marshal.dump } You can use Redis, you need the Redis gem installed: require "redis" class Test < SuperModel::Base include SuperModel::Redis::Model attributes :name indexes :name end Test.find_or_create_by_name("foo")
Hi
Not sure if SuperModel supoort relationships, like belong_to or has_many.
class Person
has_many:addresses
end
.....
person.addresses = [ address ]
person.addresses.target #=> returns [ address ]
person.addresses.base #=> returns person
person.addresses.metadata #=> returns the metadata
.....
Hello
I tried use SuperModel to connect Redis with AR , but I found it always return "nil" when use 'find_by_xxx' like below, any idea or it's my fault to use in such way ?
require "redis"
require 'supermodel'
class Hello < SuperModel::Base
include SuperModel::Redis::Model
attributes:yyy
end
h=Hello.new
h.yyy='test'
h.save
p Hello.find_by_yyy('test') #=>nil
p Hello.all #=><Hello:0x2e4b680 @new_record=false, @attributes={"yyy"=>"test", "id"=>1}, @changed_attributes={"yyy"=>nil}>
Howdy maccman,
I just tried to get the helloworld app working (in the last 4 hours) on Ubuntu 10.04 (just after upgrading SuperModel to 0.1.4). I'm running Ruby 1.9.1.
bowline-gen app helloworld: worked fine (thanks for fixing supermodel!)
cd helloworld
bowline-bundle: this worked OK and put the gems in the vendor/gems directory
./script/run produces the following error:
Setting up Bowline. This could take a while... /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/bowline-0.9.3/lib/bowline/initializer.rb:113:in `set_autoload_paths': undefined method `load_paths=' for ActiveSupport::Dependencies:Module (NoMethodError) from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/bowline-0.9.3/lib/bowline/initializer.rb:335:in `process' from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/bowline-0.9.3/lib/bowline/initializer.rb:71:in `run' from /home/cadmium/ruby/bowline/helloworld/config/environment.rb:4:in `' from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/activesupport-3.0.0.rc/lib/active_support/dependencies.rb:219:in `require' from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/activesupport-3.0.0.rc/lib/active_support/dependencies.rb:219:in `block in require' from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/activesupport-3.0.0.rc/lib/active_support/dependencies.rb:205:in `block in load_dependency' from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/activesupport-3.0.0.rc/lib/active_support/dependencies.rb:570:in `new_constants_in' from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/activesupport-3.0.0.rc/lib/active_support/dependencies.rb:205:in `load_dependency' from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/activesupport-3.0.0.rc/lib/active_support/dependencies.rb:219:in `require' from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/bowline-0.9.3/lib/bowline/tasks/misc.rake:2:in `block in ' from /var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `call' from /var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute' from /var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `each' from /var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `execute' from /var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain' from /usr/lib/ruby/1.9.1/monitor.rb:190:in `mon_synchronize' from /var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' from /var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:607:in `block in invoke_prerequisites' from /var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:604:in `each' from /var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites' from /var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:596:in `block in invoke_with_call_chain' from /usr/lib/ruby/1.9.1/monitor.rb:190:in `mon_synchronize' from /var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' from /var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/bowline-0.9.3/lib/bowline/commands/run.rb:4:in `' from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/activesupport-3.0.0.rc/lib/active_support/dependencies.rb:219:in `require' from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/activesupport-3.0.0.rc/lib/active_support/dependencies.rb:219:in `block in require' from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/activesupport-3.0.0.rc/lib/active_support/dependencies.rb:205:in `block in load_dependency' from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/activesupport-3.0.0.rc/lib/active_support/dependencies.rb:570:in `new_constants_in' from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/activesupport-3.0.0.rc/lib/active_support/dependencies.rb:205:in `load_dependency' from /home/cadmium/ruby/bowline/helloworld/vendor/gems/ruby/1.9.1/gems/activesupport-3.0.0.rc/lib/active_support/dependencies.rb:219:in `require' from ./script/run:3:in `'
By the way, here is my gem list:
*** LOCAL GEMS *** actionmailer (2.3.8) actionpack (2.3.8) activemodel (3.0.0.rc) activerecord (2.3.8) activeresource (2.3.8) activesupport (3.0.0.rc, 2.3.8) bowline (0.9.3) bowline-bundler (0.0.4) builder (2.1.2) diff-lcs (1.1.2) extlib (0.9.15) highline (1.6.1) i18n (0.4.1) mechanize (1.0.0) nokogiri (1.4.3.1) rack (1.2.1, 1.1.0) rails (2.3.8) rake (0.8.7) redcar (0.3.8.4) rubyzip (0.9.4) rubyzip2 (2.0.1) supermodel (0.1.4) templater (1.0.0)
I can't wait to try this out so hopefully these bugs can be sorted out quickly (if it isn't something wrong that I did).
Thanks,
cadmium
In Readme on first page, should be require 'super_model' and not 'supermodel'.
you require inheritable_attributes and attr_accessor_with_default from active support's core extensions but those are no longer available in 3.2.3 (at least as far as i can tell)
Get a no route matches for the model.
Any ideas?
Looking at the keys in redis, it appears that SuperModels that index :id have 2 id keys entered. For instance, a model Test with :id => "12345" will have the following key entries:
Is there a reason for "test:12345", or is this a bug?
I don't know where the issue with this would be, but my tests are red no matter what I do. Here is the code:
describe "nil and blank values" do
class People < SuperModel::Base
validates_formatting_of :last_name, :using => :alpha, :allow_blank => false
end
it "are allowed" do
p = People.new(:last_name => "something")
p.should be_valid
p.save!
p.last_name = ""
p.should_not be_valid
end
end
validates_formatting_of
is a gem I am currently working on. It simply uses validates_format_of. The Person should not be valid after last_name
is set to blank, but the tests say it is.
I know it is not a problem with my gem because I have tested it in an external Rails application with perfect results. Any ideas? Thanks!
Active_support-3.0.0.rc no longer includes "active_support/core_ext/object/misc"
This breaks supermodel which explicitly depends on it:
~/gems/supermodel-0.1.3/lib/supermodel.rb:12
Hi,
Just wondering if there are any tests or specs for this? If not, do you want some created (rspec or testunit or ...?)
Thanks
These are making the gem hard to install (I have a gem that depends on SuperModel). I think it should work if we upgrade, but it seems there are a lot of tests that need to be written to confirm this, eh?
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<activemodel>, [">= 3.0.0"])
else
s.add_dependency(%q<activemodel>, ["~> 3.0.0"])
end
else
s.add_dependency(%q, ["~> 3.0.0"])
end
main » require 'supermodel'
LoadError: cannot load such file -- active_support/core_ext/class/inheritable_attributes
from /Users/Alex/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:121:in `require'
Hi,
exists? method doesn't seem to work :
>> MyModel.last
=> #<MyModel:0x7fe0202352f0 @changed_attributes={}, @attributes={"number"=>"3", "id"=>70300294400640}, @new_record=false>
>> MyModel.exists?(:number => 3)
=> false
>> MyModel.exists?(:number => "3")
=> false
>> MyModel.exists?("number" => "3")
=> false
>> MyModel.exists?("number = 3")
=> false
Does this method require ActiveRecord module ?
Thanks for this plugin, I was about to write one like this !
Trying to use Rails 3.1 (depends on activemodel 3.1.0) whereas you declared dependency on activemodel 3.0.0. Wondering if there is a reason.
Hi, Supermodel currently depends on ActiveModel 3.0. I'm using Supermodel as a "generic activemodel implementation" in http://github.com/karmi/tire and it's making it a bit painful, since the version is long outdated... Could Supermodel be upgraded to ActiveModel 3.2.x?
Thanks!,
Karel
Attempting to create the follwing results in:
class Test < SuperModel::Redis
attributes :name
indexes :name
end
Test.find_or_create_by_name("foo")
TypeError: wrong argument type Module (expected Class)
Unless I'm missing something, this should be:
class Test < SuperModel::Base
include SuperModel::Redis::Model
attributes :name
indexes :name
end
Test.find_or_create_by_name("foo")
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.