changelogs.md


wantedly/computed_model

Repository  -  API  -  Source

0.3.0

computed_model 0.3 comes with a great number of improvements, and a bunch of breaking changes.

See Migration-0.3.md for migration.

New feature: dynamic dependencies

Previously, subdeps are only useful for loaded fields and primary fields. Now computed fields can make use of subdeps!


class User
  # Delegate subdeps
  dependency(
    blog_articles: -> (subdeps) { subdeps }
  )
  computed def filtered_blog_articles
    if current_subfields.normalized[:image].any?
      # ...
    end
    # ...
  end
end

See CONCEPTS.md for more usages.

New feature: loader dependency

You can specify dependency from a loaded field.

class User
  dependency :raw_user  # dependency of :raw_books
  define_loader :raw_books, key: -> { id } do |subdeps, **|
    # ...
  end
end

New feature: computed model inheritance

Now you can reuse computed model definitions via inheritance.

module UserLikeConcern
  extends ActiveSupport::Concern
  include ComputedModel::Model

  dependency :preference, :profile
  computed def display_name
    "#{preference.title} #{profile.name}"
  end
end

class User
  include UserLikeConcern

  define_loader :preference, key: -> { id } do ... end
  define_loader :profile, key: -> { id } do ... end
end

class Admin
  include UserLikeConcern

  define_loader :preference, key: -> { id } do ... end
  define_loader :profile, key: -> { id } do ... end
end

0.2.2

  • #7 Accept Hash as a with parameter

0.2.1

  • Fix problem with prefix option in delegate_dependency not working

0.2.0

  • BREAKING CHANGE Make define_loader more concise interface like GraphQL's DataLoader.
  • Introduce primary loader through #define_primary_loader.
  • BREAKING CHANGE Change #bulk_load_and_compute signature to support primary loader.

0.1.1

  • Expand docs.
  • Add ComputedModel#computed_model_error for load cancellation

0.1.0

Initial release.