Closed bkjohnson closed 12 months ago
Hey Brooks, thanks for suggestions, but I want to keep the scope of this project limited. Integrations with other projects is probably better put in external gems.
Also integration with rails is so trivial I don't think it needs specific treatment. All you need is a mapping from rails to shale types. Here's an example:
RAILS_TO_SHALE_TYPE_MAPPING = {
integer: Shale::Type::Integer,
string: Shale::Type::String,
datetime: Shale::Type::Time,
}
class PersonMapper < Shale::Mapper
model Person
Person.attribute_types.each do |name, att|
attribute name.to_sym, RAILS_TO_SHALE_TYPE_MAPPING[att.type]
end
end
That makes sense, thank you for the feedback! I'll work on a solution like your example.
I've been trying to see if shale would be a good choice for a rails app I'm working on. I saw in https://github.com/kgiszczak/shale/issues/16 that you pointed to the Custom Model documentation which seems helpful, but the downside is that in order to use that developers have to redefine the attributes that are already defined in
schema.rb
.If I set up a very basic rails app with a schema that looks like this:
(Created a migration with
rails generate migration CreatePerson first_name:string last_name:string address:string
)Then I'm able to call
Person.attribute_types
and get something that has the type for each attribute key along with other schema-adjacent data:So I'm wondering if it would be feasible for shale to use that data so that instead of having to redefine attributes in our mapper like this:
we could do something like this and let shale create the attributes based on what's already defined on the model: