Skip to content

Commit

Permalink
Merge 12fd07a into 873ab6f
Browse files Browse the repository at this point in the history
  • Loading branch information
cheerfulstoic committed May 13, 2015
2 parents 873ab6f + 12fd07a commit 701c305
Show file tree
Hide file tree
Showing 31 changed files with 291 additions and 91 deletions.
2 changes: 2 additions & 0 deletions docs/ActiveNode.rst
Expand Up @@ -192,6 +192,8 @@ You can query associations:
.. seealso::
:ref:`#has_many <Neo4j/ActiveNode/HasN/ClassMethods#has_many>`
and
:ref:`#has_one <Neo4j/ActiveNode/HasN/ClassMethods#has_one>`

Eager Loading
~~~~~~~~~~~~~
Expand Down
Binary file modified docs/_exts/hidden_code_block.pyc
Binary file not shown.
2 changes: 0 additions & 2 deletions docs/api/Neo4j/ActiveNode.rst
Expand Up @@ -65,8 +65,6 @@ Constants

* WRAPPED_CLASSES

* WRAPPED_MODELS

* MODELS_FOR_LABELS_CACHE

* USES_CLASSNAME
Expand Down
29 changes: 22 additions & 7 deletions docs/api/Neo4j/ActiveNode/HasN/Association.rst
Expand Up @@ -74,6 +74,10 @@ Association










Expand Down Expand Up @@ -201,6 +205,21 @@ Methods



.. _`Neo4j/ActiveNode/HasN/Association#discovered_model`:

**#discovered_model**


.. hidden-code-block:: ruby

def discovered_model
target_class_names.map(&:constantize).select do |constant|
constant.ancestors.include?(::Neo4j::ActiveNode)
end
end



.. _`Neo4j/ActiveNode/HasN/Association#initialize`:

**#initialize**
Expand Down Expand Up @@ -309,7 +328,7 @@ Methods

def relationship_class_type
@relationship_class = @relationship_class.constantize if @relationship_class.class == String || @relationship_class == Symbol
@relationship_class._type
@relationship_class._type.to_sym
end


Expand Down Expand Up @@ -400,7 +419,7 @@ Methods
case model_class
when nil
if @target_class_name_from_name
"::#{@target_class_name_from_name}"
"#{association_model_namespace}::#{@target_class_name_from_name}"
else
@target_class_name_from_name
end
Expand All @@ -423,11 +442,7 @@ Methods
.. hidden-code-block:: ruby

def target_classes_or_nil
@target_classes_or_nil ||= if target_class_names
target_class_names.map(&:constantize).select do |constant|
constant.ancestors.include?(::Neo4j::ActiveNode)
end
end
@target_classes_or_nil ||= discovered_model if target_class_names
end


Expand Down
21 changes: 19 additions & 2 deletions docs/api/Neo4j/ActiveNode/HasN/ClassMethods.rst
Expand Up @@ -44,6 +44,8 @@ ClassMethods








Expand Down Expand Up @@ -176,10 +178,23 @@ Methods
will assume a `model_class` option of ``'Post'`` unless otherwise specified

**options:** A ``Hash`` of options. Allowed keys are:
*type*: The Neo4j relationship type
*type*: The Neo4j relationship type. This option is required unless either the
`origin` or `rel_class` options are specified

*origin*: The name of the association from another model which the `type` and `model_class`
can be gathered.

Example:
``Person.has_many :out, :posts, origin: :author`` (`model_class` of `Post` is assumed here)

``Post.has_one :in, :author, type: :has_author, model_class: 'Person'``

*model_class*: The model class to which the association is referring. Can be either a
model `Class` object or a string (or an Array of same).
model object ``include`` ing ``ActiveNode`` or a string (or an ``Array`` of same).
**A string is recommended** to avoid load-time issues

*rel_class*: The ``ActiveRel`` class to use for this association. Can be either a
model object ``include`` ing ``ActiveRel`` or a string (or an ``Array`` of same).
**A string is recommended** to avoid load-time issues

*dependent*: Enables deletion cascading.
Expand All @@ -189,6 +204,7 @@ Methods
.. hidden-code-block:: ruby

def has_many(direction, name, options = {}) # rubocop:disable Style/PredicateName
validate_association_options!(name, options)
name = name.to_sym
build_association(:has_many, direction, name, options)

Expand All @@ -213,6 +229,7 @@ Methods
.. hidden-code-block:: ruby

def has_one(direction, name, options = {}) # rubocop:disable Style/PredicateName
validate_association_options!(name, options)
name = name.to_sym
build_association(:has_one, direction, name, options)

Expand Down
9 changes: 2 additions & 7 deletions docs/api/Neo4j/ActiveNode/Labels.rst
Expand Up @@ -15,8 +15,6 @@ Provides a mapping between neo4j labels and Ruby classes





Labels/InvalidQueryError

Labels/RecordNotFound
Expand Down Expand Up @@ -51,8 +49,6 @@ Constants

* WRAPPED_CLASSES

* WRAPPED_MODELS

* MODELS_FOR_LABELS_CACHE


Expand Down Expand Up @@ -108,7 +104,6 @@ Methods

def self.add_wrapped_class(model)
_wrapped_classes << model
WRAPPED_MODELS << model
end


Expand All @@ -134,7 +129,7 @@ Methods
.. hidden-code-block:: ruby

def self.clear_wrapped_models
WRAPPED_MODELS.clear
WRAPPED_CLASSES.clear
end


Expand All @@ -160,7 +155,7 @@ Methods
.. hidden-code-block:: ruby

def self.model_cache(labels)
models = WRAPPED_MODELS.select do |model|
models = WRAPPED_CLASSES.select do |model|
(model.mapped_label_names - labels).size == 0
end

Expand Down
8 changes: 6 additions & 2 deletions docs/api/Neo4j/ActiveNode/Labels/ClassMethods.rst
Expand Up @@ -42,6 +42,10 @@ ClassMethods










Expand All @@ -62,7 +66,7 @@ Files



* `lib/neo4j/active_node/labels.rb:82 <https://github.com/neo4jrb/neo4j/blob/master/lib/neo4j/active_node/labels.rb#L82>`_
* `lib/neo4j/active_node/labels.rb:80 <https://github.com/neo4jrb/neo4j/blob/master/lib/neo4j/active_node/labels.rb#L80>`_



Expand Down Expand Up @@ -396,7 +400,7 @@ Methods
.. hidden-code-block:: ruby

def mapped_label_name
@mapped_label_name || (self.name.nil? ? object_id.to_s.to_sym : self.name.to_sym)
@mapped_label_name || label_for_model
end


Expand Down
2 changes: 1 addition & 1 deletion docs/api/Neo4j/ActiveNode/Labels/InvalidQueryError.rst
Expand Up @@ -26,7 +26,7 @@ Files



* `lib/neo4j/active_node/labels.rb:22 <https://github.com/neo4jrb/neo4j/blob/master/lib/neo4j/active_node/labels.rb#L22>`_
* `lib/neo4j/active_node/labels.rb:21 <https://github.com/neo4jrb/neo4j/blob/master/lib/neo4j/active_node/labels.rb#L21>`_



Expand Down
2 changes: 1 addition & 1 deletion docs/api/Neo4j/ActiveNode/Labels/RecordNotFound.rst
Expand Up @@ -26,7 +26,7 @@ Files



* `lib/neo4j/active_node/labels.rb:23 <https://github.com/neo4jrb/neo4j/blob/master/lib/neo4j/active_node/labels.rb#L23>`_
* `lib/neo4j/active_node/labels.rb:22 <https://github.com/neo4jrb/neo4j/blob/master/lib/neo4j/active_node/labels.rb#L22>`_



Expand Down
10 changes: 6 additions & 4 deletions docs/api/Neo4j/ActiveNode/Persistence/ClassMethods.rst
Expand Up @@ -28,6 +28,8 @@ ClassMethods








Expand Down Expand Up @@ -108,9 +110,9 @@ Methods
.. hidden-code-block:: ruby

def find_or_create(find_attributes, set_attributes = {})
on_create_attributes = set_attributes.merge(on_create_props)
on_create_attributes = set_attributes.merge(on_create_props(find_attributes))
on_match_attributes = set_attributes.merge(on_match_props)
neo4j_session.query.merge(n: {self => find_attributes})
neo4j_session.query.merge(n: {self.mapped_label_names => find_attributes})
.on_create_set(n: on_create_attributes).on_match_set(n: on_match_attributes)
.pluck(:n).first
end
Expand Down Expand Up @@ -164,8 +166,8 @@ Methods
.. hidden-code-block:: ruby

def merge(attributes)
neo4j_session.query.merge(n: {self => attributes})
.on_create_set(n: on_create_props)
neo4j_session.query.merge(n: {self.mapped_label_names => attributes})
.on_create_set(n: on_create_props(attributes))
.on_match_set(n: on_match_props)
.pluck(:n).first
end
Expand Down
20 changes: 11 additions & 9 deletions docs/api/Neo4j/ActiveNode/Query/QueryProxy.rst
Expand Up @@ -227,17 +227,23 @@ Methods



.. _`Neo4j/ActiveNode/Query/QueryProxy#_nodeify`:
.. _`Neo4j/ActiveNode/Query/QueryProxy#_nodeify!`:

**#_nodeify**
**#_nodeify!**


.. hidden-code-block:: ruby

def _nodeify(*args)
[args].flatten.map do |arg|
def _nodeify!(*args)
other_nodes = [args].flatten.map do |arg|
(arg.is_a?(Integer) || arg.is_a?(String)) ? @model.find(arg) : arg
end.compact
if @model && other_nodes.any? { |other_node| !other_node.is_a?(@model) }
fail ArgumentError, "Node must be of the association's class when model is specified"
end

other_nodes
end


Expand Down Expand Up @@ -363,14 +369,10 @@ Methods

def create(other_nodes, properties)
fail 'Can only create relationships on associations' if !@association
other_nodes = _nodeify(*other_nodes)
other_nodes = _nodeify!(*other_nodes)
properties = @association.inject_classname(properties)

if @model && other_nodes.any? { |other_node| !other_node.is_a?(@model) }
fail ArgumentError, "Node must be of the association's class when model is specified"
end

Neo4j::Transaction.run do
other_nodes.each do |other_node|
other_node.save unless other_node.neo_id
Expand Down
31 changes: 27 additions & 4 deletions docs/api/Neo4j/ActiveRel/Types/ClassMethods.rst
Expand Up @@ -23,6 +23,8 @@ ClassMethods








Expand Down Expand Up @@ -52,7 +54,8 @@ Methods
.. _`Neo4j/ActiveRel/Types/ClassMethods#_type`:

**#_type**
Should be deprecated
Returns the value of attribute rel_type
attr_reader :rel_type

.. hidden-code-block:: ruby

Expand Down Expand Up @@ -110,15 +113,35 @@ Methods
.. hidden-code-block:: ruby

def inherited(subclass)
subclass.type subclass.name, true
subclass.type subclass.namespaced_model_name, true
end



.. _`Neo4j/ActiveRel/Types/ClassMethods#namespaced_model_name`:

**#namespaced_model_name**


.. hidden-code-block:: ruby

def namespaced_model_name
case Neo4j::Config[:module_handling]
when :demodulize
self.name.demodulize
when Proc
Neo4j::Config[:module_handling].call(self.name)
else
self.name
end
end



.. _`Neo4j/ActiveRel/Types/ClassMethods#rel_type`:

**#rel_type**

Returns the value of attribute rel_type

.. hidden-code-block:: ruby

Expand All @@ -135,7 +158,7 @@ Methods

.. hidden-code-block:: ruby

def type(given_type = self.name, auto = false)
def type(given_type = namespaced_model_name, auto = false)
@rel_type = (auto ? decorated_rel_type(given_type) : given_type).tap do |type|
add_wrapped_class type unless uses_classname?
end
Expand Down

0 comments on commit 701c305

Please sign in to comment.