Skip to content

Commit

Permalink
[INTERNAL] Extract Core::Attributes to the 'attributes_dsl' gem
Browse files Browse the repository at this point in the history
== Deleted

* QueryBuilder::Core::Attributes
* QueryBuilder::Core::AttributeError
  • Loading branch information
nepalez committed Sep 11, 2015
1 parent 55e6ee8 commit d69ebb3
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 342 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## v0.0.4 to be released

### Internal

* Extracted `Core::Attributes` to the external gem 'attributes_dsl' (nepalez)

### Deleted

* `Core::Attributes` (nepalez)
* `Core::AttributesDSL` (nepalez)

[Compare v0.0.3...HEAD](https://github.com/nepalez/query_builder/compare/v0.0.3...HEAD)

## v0.0.3 2015-08-21

### Added
Expand Down
1 change: 1 addition & 0 deletions lib/query_builder.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# encoding: utf-8

require "attributes_dsl"
require "equalizer"
require "ice_nine"
require "transproc"
Expand Down
2 changes: 0 additions & 2 deletions lib/query_builder/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module QueryBuilder
#
module Core

require_relative "core/attribute_error"
require_relative "core/attribute"
require_relative "core/base"
require_relative "core/clause"
require_relative "core/statement"
Expand Down
54 changes: 0 additions & 54 deletions lib/query_builder/core/attribute.rb

This file was deleted.

25 changes: 0 additions & 25 deletions lib/query_builder/core/attribute_error.rb

This file was deleted.

70 changes: 3 additions & 67 deletions lib/query_builder/core/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,15 @@ module QueryBuilder::Core
#
class Base

# @!method attributes
# The hash of default attributes of class' instances
#
# @return [Hash]
#
def self.attributes
@attributes ||= Set.new
end

# @!method attribute(name, options)
# Declares the attribute with optional default value
#
# @param [Symbol] name The name of the attribute
# @param [Hash] options
# @option options [Object] :default
#
# @return [undefined]
#
def self.attribute(name, options = {})
attributes << Attribute.new(name, options)
define_method(name) { attributes.fetch(name) }
end

# Makes default attributes inheritable
#
# @private
#
def self.inherited(subclass)
attributes.each do |item|
subclass.public_send(:attribute, *item.arguments)
end
end

# @!attribute [r] attributes
#
# @return [Hash] The hash of the initialized attributes
#
attr_reader :attributes
extend AttributesDSL

# @!method initialize(attributes = {})
# Initializes the instance
#
# @param [Hash] attributes The custom attributes of the instance
#
def initialize(attributes = {})
validate_unknown attributes
validate_missing attributes

@attributes = default_attributes.merge(attributes)
def initialize(_attributes = {})
super
IceNine.deep_freeze(self)
end

Expand All @@ -73,30 +33,6 @@ def to_s
""
end

private

def known_attributes
self.class.attributes
end

def required_attributes
known_attributes.select(&:required)
end

def default_attributes
known_attributes.each_with_object({}) { |e, a| a[e.name] = e.default }
end

def validate_unknown(hash)
unknown = hash.keys - known_attributes.map(&:name)
fail AttributeError.new(:unknown, unknown) if unknown.any?
end

def validate_missing(hash)
missed = required_attributes.map(&:name) - hash.keys
fail AttributeError.new(:missed, missed) if missed.any?
end

end # class Base

end # module CQLBuiler::Core
3 changes: 2 additions & 1 deletion query_builder.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ Gem::Specification.new do |gem|

gem.required_ruby_version = ">= 1.9.3"

gem.add_runtime_dependency "transproc", "~> 0.3"
gem.add_runtime_dependency "attributes_dsl", "~> 0.0"
gem.add_runtime_dependency "equalizer", "~> 0.0.11"
gem.add_runtime_dependency "ice_nine", "~> 0.11"
gem.add_runtime_dependency "transproc", "~> 0.3"

gem.add_development_dependency "hexx-rspec", "~> 0.5"

Expand Down
38 changes: 0 additions & 38 deletions spec/unit/core/attribute_error_spec.rb

This file was deleted.

70 changes: 0 additions & 70 deletions spec/unit/core/attribute_spec.rb

This file was deleted.

0 comments on commit d69ebb3

Please sign in to comment.