Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uninitialized constant Airtable::Record::HashWithIndifferentAccess #5

Open
dmerand opened this issue Apr 2, 2016 · 6 comments
Open

Comments

@dmerand
Copy link

dmerand commented Apr 2, 2016

Hi,

I've been working on getting this gem to work for some time, and I'm stuck. I'm wondering if the issue is my setup or the gem.

Here's my setup code:

#!/usr/bin/env ruby

require 'airtable'

at_key = 'KEY_REDACTED'
at_base = 'BASE_REDACTED'

@client = Airtable::Client.new(at_key)
@table = @client.table(at_base, "Videos")
@records = @table.records
p @records.inspect

...pretty much straight from the README. When I run that code, I get this error:

/Users/donald/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/airtable-0.0.8/lib/airtable/record.rb:33:in override_attributes!': uninitialized constant Airtable::Record::HashWithIndifferentAccess (NameError) from /Users/donald/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/airtable-0.0.8/lib/airtable/record.rb:5:ininitialize'
from /Users/donald/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/airtable-0.0.8/lib/airtable/record_set.rb:13:in new' from /Users/donald/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/airtable-0.0.8/lib/airtable/record_set.rb:13:inblock in initialize'
from /Users/donald/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/airtable-0.0.8/lib/airtable/record_set.rb:13:in map' from /Users/donald/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/airtable-0.0.8/lib/airtable/record_set.rb:13:ininitialize'
from /Users/donald/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/airtable-0.0.8/lib/airtable/table.rb:27:in new' from /Users/donald/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/airtable-0.0.8/lib/airtable/table.rb:27:inrecords'
from ./gem_test.rb:10:in `<

As you can see, I'm using rbenv. I've run this same code on Ruby 1.9.1, 2.2.4, and 2.3.0 and I can't get it to do anything but give me the error you see above. Am I missing something? Or this this a bug?

I downloaded the gem source to my machine and ran the tests, which ran just fine.

@nesquena
Copy link
Collaborator

nesquena commented Apr 2, 2016

There's an unstated dependency on http://apidock.com/rails/ActiveSupport/HashWithIndifferentAccess which is causing this issue. If you add in the activesupport library to your project or otherwise define HashWithIndifferentAccess, this error will go away

@nesquena nesquena closed this as completed Apr 2, 2016
@dmerand
Copy link
Author

dmerand commented Apr 2, 2016

Thanks, that fixes it indeed! For anybody else with this problem, the require line is:

require 'active_support/all'

@yuuki1224
Copy link

yuuki1224 commented Jun 7, 2016

I've got same trouble and wondering why don't this add require 'active_support/all' into here?
Any reason?

@syrnick syrnick reopened this Jun 8, 2016
@syrnick
Copy link
Contributor

syrnick commented Jun 8, 2016

I'll address that. Is there any reason to not depend on active_support explicitly?

@nesquena
Copy link
Collaborator

nesquena commented Jun 8, 2016

active_support is a pretty expensive dependency to bring in to a project that doesn't already have it loaded. I wonder if we'd be better off finding an alternate way to make it so we can do @record[:foo] and @record['foo'] produce the same response. That said, easiest solution is to depend explicitly on active_support

@syrnick
Copy link
Contributor

syrnick commented Jun 8, 2016

Handling @record[:foo] and @record['foo'] is pretty easy. I'd just store data keyed by the string k, a map from to_key(k) to k and lookup the key if the argument to @record[] is a symbol. I think it'll actually be better, because you'd only be exposed to naming collisions created by to_key when you use an ambiguous symbol.

@record.fields[:foo] and @record.fields['foo'] is a bit more complicated as we'd need an equivalent replacement for HashWithIndifferentAccess. I'm leaning towards checking if it exists and returning one if it does. If you don't have active_support, it'd just work until you try to use @record.fields with a symbol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants