Sha256: 58dc1e65d6f6029d6d9935977b0d9b392c370e580c3298c677cf7182b414a55d

Contents?: true

Size: 849 Bytes

Versions: 9

Compression:

Stored size: 849 Bytes

Contents

module ActiveData
  module Model
    module Associations
      module Reflections
        module Singular
          extend ActiveSupport::Concern

          module ClassMethods
            def generate_methods(name, target)
              super

              target.class_eval <<-RUBY, __FILE__, __LINE__ + 1
                def build_#{name} attributes = {}
                  association(:#{name}).build(attributes)
                end

                def create_#{name} attributes = {}
                  association(:#{name}).create(attributes)
                end

                def create_#{name}! attributes = {}
                  association(:#{name}).create!(attributes)
                end
              RUBY
            end
          end

          def collection?
            false
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
active_data-1.2.0 lib/active_data/model/associations/reflections/singular.rb
active_data-1.1.7 lib/active_data/model/associations/reflections/singular.rb
active_data-1.1.6 lib/active_data/model/associations/reflections/singular.rb
active_data-1.1.5 lib/active_data/model/associations/reflections/singular.rb
active_data-1.1.4 lib/active_data/model/associations/reflections/singular.rb
active_data-1.1.3 lib/active_data/model/associations/reflections/singular.rb
active_data-1.1.2 lib/active_data/model/associations/reflections/singular.rb
active_data-1.1.1 lib/active_data/model/associations/reflections/singular.rb
active_data-1.1.0 lib/active_data/model/associations/reflections/singular.rb