Skip to content

Commit

Permalink
Drops model extension feature
Browse files Browse the repository at this point in the history
  • Loading branch information
eudoxa committed Apr 26, 2024
1 parent d963310 commit ad1b020
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 127 deletions.
26 changes: 0 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ With Chanko, you can release many features concurrently and manage target users
When any errors are raised from chanko's features,
it will be automatically hidden and fallback to its normal behavior.


## Requirements
* Ruby >= 2.6.0
* Rails >= 5.0.0


## Usage
Add to your Gemfile.

Expand Down Expand Up @@ -117,29 +115,6 @@ end
### render
In version 2 and earlier, Chanko extended Rails' search path to include the views path of the unit. This functionality has been discontinued. To maintain the views path under the unit, you will need to manually create a symbolic link in app/views/units to access it.

### models
In models block, you can expand model features by `expand` method.
The expanded methods are available via unit proxy like `User.unit.active`,
`User.find(params[:id]).unit.active?` or `User.unit.gc_all_soft_deleted_users`.

```ruby
models do
expand(:User) do
scope :active, lambda { where(:deleted_at => nil) }

def active?
deleted_at.nil?
end

class_methods do
def gc_all_soft_deleted_users
where.not(deleted_at: nil).delete_all
end
end
end
end
```

### shared
You can call methods defined by `shared` in invoking.

Expand All @@ -160,7 +135,6 @@ helpers do
end
```


## Example
https://github.com/cookpad/chanko/tree/master/spec/dummy
Chanko provides an example rails application in spec/dummy directory.
Expand Down
4 changes: 0 additions & 4 deletions lib/chanko/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ def helpers(&block)
Helper.define(unit_name, &block)
end

def models(&block)
extender.instance_eval(&block)
end

def active_if(*conditions, &block)
@active_if = ActiveIf.new(*conditions, &block)
end
Expand Down
1 change: 0 additions & 1 deletion lib/chanko/unit/scope_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def class?
def label
label_scope_map = {
:controller => ActionController::Base,
:model => ActiveRecord::Base,
:view => ActionView::Base
}

Expand Down
23 changes: 0 additions & 23 deletions lib/generators/chanko/unit/templates/unit.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,6 @@ module <%= class_name %>
# end
# ```

# ## models
# In models block, you can expand model features by `expand` method.
# The expanded methods are available via unit proxy like `User.unit.active`,
# `User.find(params[:id]).unit.active?` or `User.unit.gc_all_soft_deleted_users`.
#
# ```
# models do
# expand(:User) do
# scope :active, lambda { where(:deleted_at => nil) }
#
# def active?
# deleted_at.nil?
# end
#
# class_methods do
# def gc_all_soft_deleted_users
# where.not(deleted_at: nil).delete_all
# end
# end
# end
# end
# ```

# ## shared
# You can call methods defined by `shared` in invoking.
#
Expand Down
57 changes: 0 additions & 57 deletions spec/chanko/unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,62 +188,5 @@ def test
expect(view.__example_unit_test).to eq("test")
end
end

describe ".models" do
before do
stub_const("ExampleModel", model_class)
unit.models do
expand(:ExampleModel) do
scope :active, lambda { where(:deleted_at => nil) }

has_one :user

def test
"test"
end

class_methods do
def test
"test"
end
end
end
end
end

let(:model_class) do
Class.new do
include UnitProxyProvider

def self.scope(name, *args)
singleton_class.class_eval do
define_method(name) { "scoped" }
end
end

def self.has_one(name, *args)
singleton_class.class_eval do
define_method(name) { args }
end
end
end
end

it "defines instance methods with prefix" do
expect(ExampleModel.new.__example_unit_test).to eq("test")
end

it "defines class methods with prefix" do
expect(ExampleModel.__example_unit_test).to eq("test")
end

it "defines scope method with prefix" do
expect(ExampleModel.__example_unit_active).to eq("scoped")
end

it "defines has_one association method with prefix" do
expect(ExampleModel.__example_unit_user).to eq([:class_name => "User"])
end
end
end
end
16 changes: 0 additions & 16 deletions spec/dummy/app/units/entry_deletion/entry_deletion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@ module EntryDeletion
end
end

models do
expand(:Entry) do
scope :active, lambda { where(:deleted_at => nil) }

def soft_delete
update_attributes(:deleted_at => Time.now)
end

class_methods do
def gc_all_soft_deleted_users
where.not(deleted_at: nil).delete_all
end
end
end
end

helpers do
def link_to_deletion(entry)
link_to "Delete", entry, :method => :delete
Expand Down

0 comments on commit ad1b020

Please sign in to comment.