class FixtureOverlord::Mock
Public Class Methods
new(hash)
click to toggle source
Calls superclass method
# File lib/fixture_overlord/mock.rb, line 13 def initialize(hash) super(hash.merge(generate_id)) end
setup(hash)
click to toggle source
# File lib/fixture_overlord/mock.rb, line 9 def self.setup(hash) new(hash) end
Public Instance Methods
change(options = {})
click to toggle source
child(options)
click to toggle source
add a child association
Examples¶ ↑
e.g. (has_many
)
blog.child(posts: post) blog.posts.first.title
There are 4 methods aliased to this one to provide the developer ActiveRecord & a Sequel (ORM) like interface.
# File lib/fixture_overlord/mock.rb, line 44 def child(options) associations(options) do |k,v| writer(k,[v]) end end
Also aliased as: has_many, one_to_many
parent(options)
click to toggle source
add a parent association
Examples¶ ↑
e.g. (belongs_to
)
post.parent(blog: blog) post.blog.name
There are 4 methods aliased to this one to provide the developer ActiveRecord & a Sequel (ORM) like interface.
# File lib/fixture_overlord/mock.rb, line 66 def parent(options) associations(options) do |k,v| writer(k,v) end end
remove(key)
click to toggle source
remove an attribute from the class
Examples¶ ↑
e.g.
blog.remove(:name) blog.name == nil
# File lib/fixture_overlord/mock.rb, line 101 def remove(key) writer(key) end
Also aliased as: delete
to_attributes()
click to toggle source
Private Instance Methods
associations(options) { |k, v| ... }
click to toggle source
# File lib/fixture_overlord/mock.rb, line 125 def associations(options, &block) options.each do |k,v| v = Mock.setup(v) if v.is_a?(Hash) || v.is_a?(Hashish) yield k, v end end
build_model_base()
click to toggle source
# File lib/fixture_overlord/mock.rb, line 121 def build_model_base @build_model_base ||= Helpers.to_model(yaml_filename) end
generate_id()
click to toggle source
generate a unique id and return the hash
# File lib/fixture_overlord/mock.rb, line 111 def generate_id { id: ::SecureRandom.random_number(99999) } end
writer(key, value = nil)
click to toggle source
assign a value to a hash key
# File lib/fixture_overlord/mock.rb, line 117 def writer(key, value = nil) self.send("#{key}=", value) end