how to initialize cequel in my gem (without rails)

253 views
Skip to first unread message

Oleh Novosad

unread,
Apr 24, 2014, 6:18:20 AM4/24/14
to ceq...@googlegroups.com
Hello guys, 

How to initialise cequel in my gem (without rails)?
Seems I will have to fix a bit cequel rake tasks as they use Rails.root for example. But that's ok.
Just wondering how to initialise cequel in right way, so I can use 

Cequel::Record.connection.schema.create!

without problems. At this moment this code returns nil exception (NoMethodError: undefined method `schema' for nil:NilClass)
Of course I can connect Cequel::Record.connect(my_config_yaml) somewhere. But still wondering what is right way to initialise gem. 

Thanks.

Oleh Novosad

unread,
Apr 24, 2014, 9:02:15 AM4/24/14
to ceq...@googlegroups.com
Ok I found it in gem's lib/cequel/record/railtie.rb

initializer "cequel.configure_rails" do
        config_path = Rails.root.join('config/cequel.yml').to_s

        if File.exist?(config_path)
          config = YAML.load(ERB.new(IO.read(config_path)).result)[Rails.env]
            .deep_symbolize_keys
        else
          config = {host: '127.0.0.1:9042'}
        end
        config.reverse_merge!(keyspace: "#{Railtie.app_name}_#{Rails.env}")
        connection = Cequel.connect(config)

        connection.logger = Rails.logger
        Record.connection = connection
      end
=)

Четвер, 24 квітня 2014 р. 13:18:20 UTC+3 користувач Oleh Novosad написав:

Matthew A. Brown

unread,
Apr 24, 2014, 9:09:35 AM4/24/14
to Oleh Novosad, ceq...@googlegroups.com
Hey Oleh,

Good to hear! I would've pointed you in the direction of the Railtie as well : )

Feel free to hit up the list if you come up with any other questions, or to file an issue if there's anything you'd like to see in the library that's not there now!

Mat


--
You received this message because you are subscribed to the Google Groups "Cequel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cequel+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oleh Novosad

unread,
Apr 24, 2014, 10:51:11 AM4/24/14
to ceq...@googlegroups.com, Oleh Novosad
Hey Mat, 

Thank you for wonderful gem! If any more questions/issues/proposals I will definitely use groups. Thanks.

Четвер, 24 квітня 2014 р. 16:09:35 UTC+3 користувач Mat Brown написав:
Reply all
Reply to author
Forward
0 new messages