Giter Site home page Giter Site logo

casting's People

Contributors

cbandy avatar dependabot-preview[bot] avatar harlow avatar icortex avatar kachick avatar parndt avatar sanemat avatar saturnflyer 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

casting's Issues

Possibly incompatible with New Relic agent (or the other way around.)

We recently integrated New Relic into our application to test out some metrics and it initially connects but starts throwing errors to which Casting is a big part of the stack trace.

I wanted to get some thoughts on this to find out if anyone else is using New Relic and whether or not this has been an issue.

RuntimeError: can't modify frozen NewRelic::Agent::Configuration::ServerSource

/var/bundle/ruby/2.2.0/gems/casting-0.7.1/lib/casting/missing_method_client.rb:50:in `__delegates__'
/var/bundle/ruby/2.2.0/gems/casting-0.7.1/lib/casting/missing_method_client.rb:67:in `method_delegate'
/var/bundle/ruby/2.2.0/gems/casting-0.7.1/lib/casting/missing_method_client.rb:63:in `respond_to_missing?'
/var/bundle/ruby/2.2.0/gems/newrelic_rpm-3.16.0.318/lib/new_relic/agent/configuration/manager.rb:99:in `respond_to?'
/var/bundle/ruby/2.2.0/gems/newrelic_rpm-3.16.0.318/lib/new_relic/agent/configuration/manager.rb:99:in `block in source'
/var/bundle/ruby/2.2.0/gems/newrelic_rpm-3.16.0.318/lib/new_relic/agent/configuration/manager.rb:98:in `each'
/var/bundle/ruby/2.2.0/gems/newrelic_rpm-3.16.0.318/lib/new_relic/agent/configuration/manager.rb:98:in `source'
/var/bundle/ruby/2.2.0/gems/newrelic_rpm-3.16.0.318/lib/new_relic/agent/transaction_sample_builder.rb:120:in `transaction_trace_threshold'
/var/bundle/ruby/2.2.0/gems/newrelic_rpm-3.16.0.318/lib/new_relic/agent/transaction_sample_builder.rb:111:in `finish_trace'
/var/bundle/ruby/2.2.0/gems/newrelic_rpm-3.16.0.318/lib/new_relic/agent/transaction_sampler.rb:104:in `on_finishing_transaction'
/var/bundle/ruby/2.2.0/gems/newrelic_rpm-3.16.0.318/lib/new_relic/agent/transaction.rb:519:in `commit!'
/var/bundle/ruby/2.2.0/gems/newrelic_rpm-3.16.0.318/lib/new_relic/agent/transaction.rb:503:in `stop'
/var/bundle/ruby/2.2.0/gems/newrelic_rpm-3.16.0.318/lib/new_relic/agent/transaction.rb:148:in `stop'
/var/bundle/ruby/2.2.0/gems/newrelic_rpm-3.16.0.318/lib/new_relic/agent/instrumentation/middleware_tracing.rb:108:in `call'
/var/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/configuration.rb:79:in `call'
/var/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/server.rb:541:in `handle_request'
/var/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/server.rb:388:in `process_client'
/var/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/server.rb:270:in `block in run'
/var/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/thread_pool.rb:106:in `call'
/var/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/thread_pool.rb:106:in `block in spawn_thread'

The lines in new_relic come down to this

def source(key)
  config_stack.each do |config|
    if config.respond_to?(key.to_sym) || config.has_key?(key.to_sym)
      return config
    end
  end
end

and on the config.respond_to? method which seems to get into the fact that it's trying to initialize @delegates on a frozen object.

Report methods from delegates when querying a client

Currently, an object will respond to messages from its delegates, but if you ask for a collection of methods it will not include those from the delegate.

Casting::MissingMethodClient should report these methods.

methods added by module not accessible from within module

# data object
class Request
  def scheduled_time_from
    'time from'
  end

  def scheduled_time_to
    'time to'
  end
end

# presenter
module RequestPresenter
  def scheduled_time_from
    'formatted' + super
  end

  def scheduled_time_to
    'formatted' + super
  end

  def scheduled_time_formatted
    "#{scheduled_time_from} - #{scheduled_time_to}"
  end
end

request = Request.find(1).cast_as(RequestPresenter)
request.scheduled_time_formatted # => 'time to - time from' 

scheduled_time_formatted should return 'formatted time to - formatted time from'.

I hope the issue is clear from the above, I have no idea how to describe it in words.

Is this expected behaviour?

My work around for now is as such:

# presenter
module RequestPresenter
  def scheduled_time_from_formatted
    'formatted ' + scheduled_time_from
  end

  def scheduled_time_to_formatted
    'formatted ' + scheduled_time_to
  end

  def scheduled_time_formatted
    "#{scheduled_time_from_formatted} - #{scheduled_time_to_formatted}"
  end
end

request = Request.find(1).cast_as(RequestPresenter)
request.scheduled_time_formatted # => 'formatted time to - formatted time from' 

Consider alternate method names

Currently the standard lib Forwardable and ActiveSupport provide delegate methods.

Perhaps a fallback to cast would make sense to prevent confusion.

NoMethodError undefined method `cast_as`

There is a high chance I'm just using the library wrong, but here goes:

class User < ActiveRecord::Base
  include Casting::Client
end

module Customer; end

user = User.last
user.cast_as(Customer) # => NoMethodError

This is on Ruby 1.9.3.

how to cast_as rspec doubles?

You might not consider this a casting issue, if so, please close.

If I use a double and somewhere along the way it gets cast_as it fails because of course the double does not have the Casting::Client. Do you know of a work around?

# role
class Cancellable
  def cancel
  end
end

def cancel(order)
  order.cast_as(Cancellable)
  order.cancel
end

order = double('order')

order.should_receive(:cancel)

cancel(order)
# => Double 'order' received unexpected messgae :cast_as

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.