Giter Club home page Giter Club logo

supermodel's Introduction

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")

supermodel's People

Contributors

dhruvasagar avatar maccman avatar ncavig avatar quarklemotion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

supermodel's Issues

If SuperModel support relationships? like belong_to or has_many.

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
.....

return nil when use 'find_by_xxx'

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}>

undefined method `load_paths=' for ActiveSupport::Dependencies:Module

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

activesupport 3.2.3 not supported

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)

Redis Model ID Key Without Attribute Name

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:

  1. "test:12345"
  2. "test:id:12345"

Is there a reason for "test:12345", or is this a bug?

Allow_nil and allow_blank not being applied

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!

tests or specs?

Hi,

Just wondering if there are any tests or specs for this? If not, do you want some created (rspec or testunit or ...?)

Thanks

gem version pins are preventing use in Rails 3.2

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

supermodel doesnt support current active_support?

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'

Model.exists?(:attr => value) not working ?

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 !

Activemodel dependency

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.

Outdated ActiveModel dependency

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

TypeError

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")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.