lib/spira/persistence.rb in spira-3.1.0 vs lib/spira/persistence.rb in spira-3.1.1

- old
+ new

@@ -18,11 +18,11 @@ # @param [Symbol, ID] scope # scope can be :all, :first or an ID # @param [Hash] args # args can contain: # :conditions - Hash of properties and values - # :limit - Fixnum, limiting the amount of returned records + # :limit - Integer, limiting the amount of returned records # @return [Spira::Base, Array] def find(scope, *args) case scope when :first find_each(*args).first @@ -71,11 +71,11 @@ # TODO: ideally, all types should be joined in a conjunction # within "conditions_to_query", but since RDF::Query # cannot handle such patterns, we iterate across types "manually" types.each do |tp| break if limit.zero? - q = conditions_to_query(conditions.merge(:type => tp)) + q = conditions_to_query(conditions.merge(type: tp)) repository.query(q) do |solution| break if limit.zero? if offset.zero? yield unserialize(solution[:subject]) limit -= 1 @@ -110,28 +110,28 @@ # +create+ respects mass-assignment security and accepts either +:as+ or +:without_protection+ options # in the +options+ parameter. # # ==== Examples # # Create a single new object - # User.create(:first_name => 'Jamie') + # User.create(first_name: 'Jamie') # # # Create a single new object using the :admin mass-assignment security role - # User.create({ :first_name => 'Jamie', :is_admin => true }, :as => :admin) + # User.create({ first_name: 'Jamie', is_admin: true }, as: :admin) # # # Create a single new object bypassing mass-assignment security - # User.create({ :first_name => 'Jamie', :is_admin => true }, :without_protection => true) + # User.create({ first_name: 'Jamie', is_admin: true }, without_protection: true) # # # Create an Array of new objects - # User.create([{ :first_name => 'Jamie' }, { :first_name => 'Jeremy' }]) + # User.create([{ first_name: 'Jamie' }, { first_name: 'Jeremy' }]) # # # Create a single object and pass it into a block to set other attributes. - # User.create(:first_name => 'Jamie') do |u| + # User.create(first_name: 'Jamie') do |u| # u.is_admin = false # end # # # Creating an Array of new objects using a block, where the block is executed for each object: - # User.create([{ :first_name => 'Jamie' }, { :first_name => 'Jeremy' }]) do |u| + # User.create([{ first_name: 'Jamie' }, { first_name: 'Jeremy' }]) do |u| # u.is_admin = false # end def create(attributes = nil, options = {}, &block) if attributes.is_a?(Array) attributes.collect { |attr| create(attr, options, &block) } @@ -190,11 +190,11 @@ # end # @param [RDF::URI, RDF::Node] subject # @param [Hash{Symbol => Any}] attributes Initial attributes # @return [Spira::Base] the newly created instance def project(subject, attributes = {}, &block) - new(attributes.merge(:_subject => subject), &block) + new(attributes.merge(_subject: subject), &block) end ## # Creates a URI or RDF::Node based on a potential base_uri and string, # URI, or Node, or Addressable::URI. If not a URI or Node, the given @@ -340,11 +340,11 @@ ## # Update multiple attributes of this repository. # # @example Update multiple attributes - # person.update_attributes(:name => 'test', :age => 10) + # person.update_attributes(name: 'test', age: 10) # #=> person # person.name # #=> 'test' # person.age # #=> 10 @@ -364,10 +364,10 @@ # blocks the next time it accesses attributes. # # NB: "props" argument is ignored, it is handled in Base # def reload(props = {}) - sts = self.class.repository.query(:subject => subject) + sts = self.class.repository.query({subject: subject}) self.class.properties.each do |name, options| name = name.to_s if sts objects = sts.select { |s| s.predicate == options[:predicate] } attributes[name] = retrieve_attribute(name, options, objects)