Method: JSONBuilder::Member#initialize
- Defined in:
- lib/json_builder/member.rb
#initialize(key, scope, *args, &block) ⇒ Member
Public: Returns a key value pair for the stored value which could be an instance of JSONBuilder::Elements or JSONBuilder::Value.
key - Used to generate the JSON member’s key. Can be a String or Symbol. scope - The view scope context for any variables. args - Can be an Array or other standard Ruby value. block - Yielding any block passed to the element.
Raises JSONBuilder::MissingKeyError if the key passed is nil. Returns instance of JSONBuilder::Member.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/json_builder/member.rb', line 18 def initialize(key, scope, *args, &block) raise MissingKeyError if key.nil? @key = key argument = args.shift if argument.is_a?(Array) || defined?(ActiveRecord::Relation) && argument.is_a?(ActiveRecord::Relation) @value = Elements.new(scope, argument, &block) else @value = Value.new(scope, argument, &block) end end |