Skip to content

Commit

Permalink
Constantize using Consty gem
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Naiman committed Sep 16, 2016
1 parent 2304639 commit e3e5384
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/rasti/db.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'sequel'
require 'consty'

require_relative 'db/version'
require_relative 'db/collection'
Expand Down
2 changes: 1 addition & 1 deletion lib/rasti/db/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def primary_key
end

def model
@model ||= constantize(singularize(name))
@model ||= Consty.get(demodulize(singularize(name)), self)
end

def relations
Expand Down
4 changes: 4 additions & 0 deletions lib/rasti/db/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class << self
def [](*attributes)
Class.new(self) do
attributes.each { |name| attribute name }

def self.inherited(subclass)
subclass.instance_variable_set :@attributes, attributes
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rasti/db/relations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def initialize(name, source_collection_class, options={})
end

def target_collection_class
@target_collection_class ||= @options[:collection].is_a?(Class) ? @options[:collection] : constantize(@options[:collection] || camelize(pluralize(name)))
@target_collection_class ||= @options[:collection].is_a?(Class) ? @options[:collection] : Consty.get(@options[:collection] || camelize(pluralize(name)), self.class)
end

private
Expand Down
1 change: 1 addition & 0 deletions rasti-db.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_runtime_dependency 'sequel', '~> 4.38'
spec.add_runtime_dependency 'consty', '~> 1.0'

spec.add_development_dependency 'bundler', '~> 1.12'
spec.add_development_dependency 'rake', '~> 11.0'
Expand Down

0 comments on commit e3e5384

Please sign in to comment.