Class: JsonRigs::FixturedAction
- Inherits:
-
Object
- Object
- JsonRigs::FixturedAction
- Defined in:
- lib/json-rigs/fixture.rb
Instance Attribute Summary collapse
-
#active_fixture_name ⇒ Object
Returns the value of attribute active_fixture_name.
-
#fixtures ⇒ Object
readonly
Returns the value of attribute fixtures.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #active_fixture ⇒ Object
- #active_fixture? ⇒ Boolean
- #dynamic_fixture(fixture_name, proc) ⇒ Object
- #fixture(fixture_name, &block) ⇒ Object
- #has_fixture?(fixture_name) ⇒ Boolean
-
#initialize(url, method) ⇒ FixturedAction
constructor
A new instance of FixturedAction.
- #remove_fixture(fixture_name) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(url, method) ⇒ FixturedAction
Returns a new instance of FixturedAction.
27 28 29 30 31 32 |
# File 'lib/json-rigs/fixture.rb', line 27 def initialize(url, method) @active_fixture_name = nil @url = url @method = method @fixtures = {} end |
Instance Attribute Details
#active_fixture_name ⇒ Object
Returns the value of attribute active_fixture_name.
25 26 27 |
# File 'lib/json-rigs/fixture.rb', line 25 def active_fixture_name @active_fixture_name end |
#fixtures ⇒ Object (readonly)
Returns the value of attribute fixtures.
24 25 26 |
# File 'lib/json-rigs/fixture.rb', line 24 def fixtures @fixtures end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
24 25 26 |
# File 'lib/json-rigs/fixture.rb', line 24 def url @url end |
Instance Method Details
#active_fixture ⇒ Object
46 |
# File 'lib/json-rigs/fixture.rb', line 46 def active_fixture; @fixtures[@active_fixture_name] end |
#active_fixture? ⇒ Boolean
47 |
# File 'lib/json-rigs/fixture.rb', line 47 def active_fixture?; !@active_fixture_name.empty? end |
#dynamic_fixture(fixture_name, proc) ⇒ Object
40 41 42 43 44 |
# File 'lib/json-rigs/fixture.rb', line 40 def dynamic_fixture fixture_name, proc fixture = DynamicFixture.new @fixtures[fixture_name.to_s] = fixture fixture.dynamic_response = proc end |
#fixture(fixture_name, &block) ⇒ Object
34 35 36 37 38 |
# File 'lib/json-rigs/fixture.rb', line 34 def fixture fixture_name, &block fixture = Fixture.new @fixtures[fixture_name.to_s] = fixture fixture.instance_eval &block end |
#has_fixture?(fixture_name) ⇒ Boolean
54 55 56 |
# File 'lib/json-rigs/fixture.rb', line 54 def has_fixture? fixture_name @fixtures[fixture_name.to_s] end |
#remove_fixture(fixture_name) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/json-rigs/fixture.rb', line 58 def remove_fixture fixture_name if @active_fixture_name == fixture_name @active_fixture_name = '' end @fixtures.delete(fixture_name) end |
#to_hash ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/json-rigs/fixture.rb', line 65 def to_hash fixture_hash = @fixtures.keys.each_with_object({}) do |fixture_name, hash| hash[fixture_name] = @active_fixture_name == fixture_name end { method: @method, fixtures: fixture_hash } end |