Skip to content

Commit

Permalink
Use Element#expose in preference to method_missing
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Aug 2, 2013
1 parent 0a57035 commit 5e14389
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ source "https://rubygems.org"
gemspec

gem 'rake'
gem 'opal'
gem 'opal', :github => 'opal/opal'
gem 'opal-spec'
gem 'opal-sprockets'
14 changes: 1 addition & 13 deletions opal/opal-jquery/element.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Element
%x{
var root = __opal.global, dom_class;
var root = $opal.global, dom_class;
if (root.jQuery) {
dom_class = jQuery
Expand Down Expand Up @@ -89,18 +89,6 @@ def self.expose(*methods)
alias_native :slide_toggle, :slideToggle
alias_native :fade_toggle, :fadeToggle

# Missing methods are assumed to be jquery plugins. These are called by
# the given symbol name.
def method_missing(symbol, *args, &block)
%x{
if (#{self}[#{symbol}]) {
return #{self}[#{symbol}].apply(#{self}, args);
}
}

super
end

def to_n
self
end
Expand Down
8 changes: 6 additions & 2 deletions spec/element/method_missing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
};
}

describe "Element#method_missing" do
it "calls jquery plugins by given name" do
class Element
expose :opal_specs_extension, :opal_specs_args
end

describe "Element#exposes" do
it "exposes jquery plugins by given name" do
Element.new.opal_specs_extension.should eq("foo_bar_baz")
end

Expand Down

0 comments on commit 5e14389

Please sign in to comment.