No commit activity in last 3 years
No release in over 3 years
AccessibleSeedYaml is wrapper of rails seed file. This wrapper provides following function: 1. Easy access interface for seed data. 2. Hold original seed data.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 10.0
 Project Readme

Gem Version Build Status Coverage Status Code Climate

Introduction

AccessibleSeedYaml is wrapper of rails seed file.
This wrapper provides following function:

  1. Easy access interface for seed data.
  2. Hold original seed data.

Install

To install the Gem, run this command from a terminal/shell:

$ gem install accessible_seed_yaml

Example

Sample data

numbers.yaml

data1:
  id: 1
  name: "one"
data2:
  id: 2
  name: "two"
data3:
  id: 3
  name: "three"

Example of AccessibleSeedYaml::Table

require 'accessible_seed_yaml'

original_seed = File.read('numbers.yaml')

@table = AccessibleSeedYaml::Table.new(original_seed)

# Instance is providing data access interface.
@table.records
# => 
# [
#   #<AccessibleSeedYaml::Record:0x007f91552770c0
#    @original_seed="data1:\n  id: 1\n  name: \"one\"\n",
#    @seed_data_by_hash={"data1"=>{"id"=>1, "name"=>"one"}}>,
#   #<AccessibleSeedYaml::Record:0x007f915526c238
#    @original_seed="data2:\n  id: 2\n  name: \"two\"\n",
#    @seed_data_by_hash={"data2"=>{"id"=>2, "name"=>"two"}}>,
#   #<AccessibleSeedYaml::Record:0x007f91552662c0
#    @original_seed="data3:\n  id: 3\n  name: \"three\"",
#    @seed_data_by_hash={"data3"=>{"id"=>3, "name"=>"three"}}>
# ]

@table.records[0]
# => #<AccessibleSeedYaml::Record:0x007f9155725068
# @original_seed="data1:\n  id: 1\n  name: \"one\"\n",
# @seed_data_by_hash={"data1"=>{"id"=>1, "name"=>"one"}}>

# Instance is holding original seed.
@table.original_seed == original_seed
# => true

Example of AccessibleSeedYaml::Record

@record = @table.records[0]

@record
# => #<AccessibleSeedYaml::Record:0x007f9155725068
#     @original_seed="data1:\n  id: 1\n  name: \"one\"\n",
#     @seed_data_by_hash={"data1"=>{"id"=>1, "name"=>"one"}}>

# Instance is providing data access interface.
@record.attributes          # => {"id"=>1, "name"=>"one"}
@record.attributes["id"]    # => 1
@record.attributes["name"]  # => "one"

# Instance is holding original seed.
@record.original_seed # => "data1:\n  id: 1\n  name: \"one\"\n"