Coder Social home page Coder Social logo

activeentity's People

Contributors

dependabot[bot] avatar jasl avatar leastbad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

activeentity's Issues

Some confusion over enum

I don't know if this is an issue, or possibly just an opportunity to create more documentation for the enum module.

While I think I have come to understand the Active Entity enum implementation, my experiments suggest that its behaviour is different enough from ActiveRecord::Enum that it's almost harmful to use the AR documentation for this feature.

Unlike AR enum, AE enum only accepts one parameter, and that parameter must be a Hash. This makes most of the examples at the top of https://github.com/jasl/activeentity/blob/master/lib/active_entity/enum.rb incorrect; for example, there are no scopes created and there is no concept of where querying with AE. It supports suffixes and prefixes, but no other options.

AR enum is described as "an enum attribute where the values map to integers in the database, but can be queried by name" but that is just not how the AE implementation works.

class Example < ActiveEntity::Base
  attribute :status, :integer, default: 0
  enum status: [:active, :inactive]
end

example = Example.new
example.attributes # => {"status"=>"active"}

Really, what we have is not an Integer, but a String that can be set with an Integer. I don't know if AE tracks the type cast but the important thing is that if I go to work with the attributes it shows up as a String... meaning that logically, I should define status as a String attribute when using Active Entity. However, that doesn't end well:

class Example < ActiveEntity::Base
  attribute :status, :string, default: 10
  enum status: {active: 10, inactive: 20}
end

example = Example.new
example.attributes # => {"status"=>"active"}
example.inactive! # => {"status"=>nil} <- I'm cheating a bit because AllFutures supports update!/save!
example.status = 20 # => {"status"=>"inactive"}
example.status = :active # => {"status"=>"active"}

So, to recap: AE enum looks like and behaves as a String, but must be declared with Integer type or else the dynamic methods are not created properly.

I actually think that this is fine now that I have mapped it out, but that we have a responsibility to document these quirks. In the StimulusReflex project, our first step in solving any problem is to try and ask if it is something that should just be fully explained in the docs.

I am writing docs for AllFutures and would be happy to share anything useful from that work upstream to Active Entity.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.