Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make compiled library name and/or output folder of compiled library configurable #43

Open
malept opened this issue Nov 27, 2017 · 2 comments

Comments

@malept
Copy link
Owner

malept commented Nov 27, 2017

Mentioned on The Bikeshed (like #42) and expanded upon via Twitter.

@sgrif
Copy link

sgrif commented Nov 27, 2017

In case Twitter goes away or is inaccessible for some folks :)

Thermite copies the dylib to lib/gem_name.native_extension, which doesn't give me room to execute additional Ruby when require "gem_name" happens. This is my lib/gem_name for reference.

require "helix_runtime"
require "rails_fast_attributes/native"
require "rails_fast_attributes/version"
require "active_model"
require "active_model/attribute"
require "active_model/attribute_set"
require "active_model/attribute/user_provided_default"
require "active_record"
require "active_record/relation"
require "active_record/relation/query_attribute"

module RailsFastAttributes
  ORIGINAL_ATTRIBUTE = ActiveModel::Attribute

  class Attribute
    UNINITIALIZED_ORIGINAL_VALUE = Object.new

    def self.inherited(*)
      raise "ActiveModel::Attribute cannot be subclassed when using rails_fast_attributes"
    end

    def self.null(name)
      ORIGINAL_ATTRIBUTE.null(name)
    end

    module UserProvidedDefault
      def self.new(name, value, ty, original_attr = nil)
        Attribute.user_provided_default(name, value, ty, original_attr)
      end
    end
  end

  class AttributeSet
    Builder = RailsFastAttributes::Builder
    YAMLEncoder = ActiveModel::AttributeSet::YAMLEncoder
  end
end

ActiveModel.send(:remove_const, :Attribute)
ActiveModel::Attribute = RailsFastAttributes::Attribute
ActiveModel.send(:remove_const, :AttributeSet)
ActiveModel::AttributeSet = RailsFastAttributes::AttributeSet

@malept
Copy link
Owner Author

malept commented Mar 10, 2018

I've created a PR for a custom Ruby extension directory in #49. I'm still uncertain whether I want to allow for a custom library name. Currently the name originates from either lib.name or package.name in Cargo.toml (and then is processed as necessary).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants